Examples of receiving and sending 16 bit packets using Python3 serial port

  • 2021-06-28 13:08:14
  • OfStack

As follows:


import serial
import string
import binascii
s=serial.Serial('com4',9600)
s.open()
# Receive 
n=s.inwaiting()
if n: 
  data= str(binascii.b2a_hex(s.read(n)))[2:-1]
  print(data)
# Send out  
d=bytes.fromhex('10 11 12 34 3f') 
s.write(d)
s.close()

Related articles: