读写通信pySerial

时间:2018-01-23 11:41:10

标签: python serial-port pyserial

您好我在设备上读取/写入时遇到问题。我想通过rs 485(半双工)进行串行连接。当我调用读写函数时,他们没有收到数据。谁知道我做错了什么?

def Transmission(ser,data):
    if ser.isOpen():
        try:
            print(data)
            ser.flushInput()
            ser.flushOutput()
            ser.rtscts = True
            ser.write(data)
            time.sleep(0.1)
            numOfLines = 0
            print("write: " + data)
            while True:
                response = ser.readline()
                print("read data: " + response)
                ser.rtscts = False 
                numOfLines = numOfLines + 1
            if(numOfLines >= 5):
                ser.close()
        except Exception, e1:
            print "error communicating...: " + str(e1)
    else:
        print "cannot open serial port "
    return response

终端没有显示接收数据:

powah
write: powah
read data:
read data:
read data:
read data:
read data:

我尝试在循环中使用read进行编写(更改ser.rtscts)。如何解决这个问题?谢谢

0 个答案:

没有答案