最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论