Hi i am working with python serial project i want to change the serial port parity value at runtime it is not working properly especially in odd parity mode it is not sending correct data
import serial
import time
ser = serial.Serial(
port='COM3',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0
)
time.sleep(2)
while True:
ser.parity = serial.PARITY_ODD
ser.write(serial.to_bytes([0x01]))
ser.write(serial.to_bytes([0x02]))
ser.write(serial.to_bytes([0x03]))
ser.write(serial.to_bytes([0x01]))
ser.write(serial.to_bytes([0x02]))
ser.write(serial.to_bytes([0x03]))
time.sleep(2)
In above code i am sending three bytes of data with Odd and Even parity while sending i am able receive the Even parity data with correct value but in odd parity mode it is not transmitting correct values
for even parity at the receiver end i am getting 01 02 03
for odd parity at receiver end i am getting some time 01 12 03 some time 01 08 03 some time 81 02 03
guide me to change the parity of the serial port at run time
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742354902a4428236.html
评论列表(0条)