python and serial. how to send a message and receive an answer

前端 未结 4 1852
清歌不尽
清歌不尽 2021-01-22 13:05

I have to send ZANE:1:00004:XX_X.X_XXXX_000XX:\\r\\nvia serial communication with python.

here is my code:

import serial
ser = serial.Seria         


        
4条回答
  •  礼貌的吻别
    2021-01-22 13:40

    Here two thinks are important.first one is timeout and second one is EOL charector.. if you are going to use time out in the receiver side then no need EOL from transmitter side. if you are going to use EOL charector in transmitter side(/n,/r) then no need to put time out in the receiver side. Ex: serialport=serial.serial(port,baud,timeout) if you are going to use time out incoming signal over serial port(Ex: hello how are you? nice to meet you man!!) Here new line cherector does not respond well.so you can leave it.

    Ex: serialport=Serial.serial(port,baud) if you are not going to put time out in serial port then you should use end of line charector(/n,/r) in the transmitter Note : Second way is more efficient than first way

提交回复
热议问题