Changing Serial Port Parity at Run time Python Serial - Stack Overflow

Hi i am working with python serial project i want to change the serial port parity value at runtime it

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

相关推荐

  • Changing Serial Port Parity at Run time Python Serial - Stack Overflow

    Hi i am working with python serial project i want to change the serial port parity value at runtime it

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信