ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can make your own node in ROS 2 either in python or CPP,

I have worked with Python, below is the code for that, you can use library serial in python, and you need to convert it to ros2 code based on your requirements.

import serial

ser = serial.Serial("/dev/ttyUSB0", baudrate=9600, parity=serial.PARITY_NONE, bytesize=serial.EIGHTBITS,
                            stopbits=serial.STOPBITS_ONE, timeout=10000)
if ser.is_open == True:
            return True
        else:
            return False

while (ser.is_open == True):
            line = ser.read_until(b'#')

You can make your own node in ROS 2 either in python or CPP,

I have worked with Python, below is the code for that, you can use library serial in python, and you need to convert it to ros2 code based on your requirements.

import serial

ser = serial.Serial("/dev/ttyUSB0", baudrate=9600, parity=serial.PARITY_NONE, bytesize=serial.EIGHTBITS,
                            stopbits=serial.STOPBITS_ONE, timeout=10000)
if ser.is_open == True:
            return True
        else:
            return False

while (ser.is_open == True):
            line = ser.read_until(b'#')

In case of any ques, feel free to drop commet.