我是pyserial的新手,我正试图让两个Blue Dongle RS232互相交谈
我有一个连接到/ dev / ttyUSB0,另一个连接到/ dev / ttyUSB1
当使用AT命令连接时,它们都被配置为彼此连接。我发送"你好"通过蓝牙链接从USB0加密狗到USB1加密狗的消息。
这是我的代码
import serial
ser0 = serial.Serial()`
ser0.port = '/dev/ttyUSB0'
ser0.baudrate = 57600
ser0.bytesize = 8
ser0.parity = serial.PARITY_NONE
ser0.stopbits = serial.STOPBITS_ONE
ser1 = serial.Serial()
ser1.port = '/dev/ttyUSB0'
ser1.baudrate = 57600
ser1.bytesize = 8
ser1.parity = serial.PARITY_NONE
ser1.stopbits = serial.STOPBITS_ONE
try:
ser0.open()
print "Connected usb0"
except serial.serialutil.SerialException:
print "Cannot Connect to usb0"
ser0.close()
try:
ser1.open()
print "Connected usb1"
except serial.serialutil.SerialException:
print "Cannot Connect to usb0"
ser1.close()
cmd = "hello!!!\r"
ser0.write(cmd.encode())
print "sent hello"
response = ser1.readline()
# tried ser1.read(64) as well
print response
ser0.close()
ser1.close()
这是输出: 连接usb0 连接usb1 发出问候
它打印到这一行 - >打印"发送你好" 在此之后代码被卡住并且没有生成响应
我在这里做错了什么?
提前致谢! --Aneesh