Hi,
I want to use 2 UART to communicate with my 2 devices at the same time but the UART2 always doesn’t work. I’ve tried to send commands through /dev/ttyS0 and /dev/ttyTHS2 to test my UART2, but both got no response. I’ve also swapped the order of my devices and whether device A or B worked pretty well with UART1. I am wondering if there’s something wrong with my testing code or other settings?
import serial
import timeser1 = serial.Serial(“/dev/ttyTHS1”, 57600, timeout=0.1)
ser2 = serial.Serial(“/dev/ttyTHS2”, 57600, timeout=0.1) # Have tried ttyTHS2 and ttyS0.
#ser2 = serial.Serial(“/dev/ttyS0”, 57600, timeout=0.1) # Have tried ttyTHS2 and ttyS0.
time.sleep(1)while True:
ser1.write(b"1,PING\r\n")
response = ser1.readline()
print("Uart1: ", response, end=‘\t’)ser2.write(b"1,PING\r\n")
response = ser2.readline()
print("Uart2: ", response)
time.sleep(0.25)
responses:
Uart1: b’BDC\r\n’ Uart2: b’’
Uart1: b’BDC\r\n’ Uart2: b’’
Uart1: b’BDC\r\n’ Uart2: b’’
After swapped:
import serial
import timeser1 = serial.Serial(“/dev/ttyTHS1”, 57600, timeout=0.1)
ser2 = serial.Serial(“/dev/ttyTHS2”, 57600, timeout=0.1) # Have tried ttyTHS2 and ttyS0.
#ser2 = serial.Serial(“/dev/ttyS0”, 57600, timeout=0.1) # Have tried ttyTHS2 and ttyS0.
time.sleep(1)while True:
ser1.write(b"1,PING\r\n")
response = ser1.readline()
print("Uart1: ", response, end=‘\t’)ser2.write(b"1,PING\r\n")
response = ser2.readline()
print("Uart2: ", response)
time.sleep(0.25)
responses: (Both got nothing)
Uart1: b’’ Uart2: b’’
Uart1: b’’ Uart2: b’’
Uart1: b’’ Uart2: b’’