Multiple serial USBs

Hi all,

i have two USB serial devices to read encoder values from my wheels. When I connect them seperately they works fine. But when I run them together to calculate odometry CORE2-ROS freezes. What is causing that?

Any help would be apriciated.

Here the part of my code in python.

 ser = serial.Serial(
 port='/dev/ttyACM0',
 baudrate=115200,
 parity=serial.PARITY_NONE,
 stopbits=serial.STOPBITS_ONE,
 bytesize=serial.EIGHTBITS,
 xonxoff=False,
 rtscts=False,
 dsrdtr=False,
)
ser1 = serial.Serial(
 port='/dev/ttyACM1',
 baudrate=115200,
 parity=serial.PARITY_NONE,
 stopbits=serial.STOPBITS_ONE,
 bytesize=serial.EIGHTBITS,
 xonxoff=False,
 rtscts=False,
 dsrdtr=False,
)

ser.isOpen()
ser1.isOpen()

last_received = ''

def receiving(ser):
    global last_received
    buffer = ''

    while True:
        # last_received = ser.readline()
        buffer += ser.read(ser.inWaiting())
        if '\n' in buffer:
            last_received, buffer = buffer.split('\n')[-2:]
            try:
                return int(last_received)
            except ValueError:
                pass  
                return 0
def Encoder():

    time.sleep(0.1)
    count=receiving(ser)
    count1=receiving(ser1)
    return count, count1

Thanks

Mert

Hi Mert, could you also share a C++ code on CORE2-ROS real-time board side?

Hi Dominik,

Thanks for the rapid response. There is nothing running on CORE2-ROS yet. I only run my python module to calculate odometry on SBC and publish it in ROS.

To correct my question, SBC is freezing not the CORE2-ROS.

Thanks

Maybe im misreading it (I’m in mobile right now), but it looks like you’re only calling out a single serial connection right now. When you connect two, the SBC is not sure which one to go with, and this might explain the hang when you use two, but normal operation when you use one.

Try explicitly coding two serial connections, to independently address each encoder.

Hi Bownem,

Thanks for your response. If you look at the code, it is calling two separate serial USBs on (/dev/ttyACM0 and /dev/ttyACM1). Just reading them from same function but it should not be problem.

Thanks

Yup, missed that. I saw the ACM0 function, but mobile version of this page made it tricky to keep track of where I was in the code.

I’m not seeing anything that immediately jumps out at me as to why only one serial device is working at any one time. Best I can come up with is that the count1 function isn’t a fan of you don’t doing anything with ser1 - but I can’t really justify why it wouldn’t like that. Maybe try giving ser1 a simple job to do as well?

Hi Brownem,

Unfortunately it didnt work. For some reasons if I use both serial USB serials it hangs and I lost the connection through Wifi.

Any further suggestion would be appreciated.

Thanks