I am trying to write data to the first serial port, COM1, using PySerial.
import serial
ser = serial.Serial(0)
print (ser.name)
ser.baudrate = 56700
ser.write("abcdefg")
ser.close()
ought to work. However, I need to send 28 bytes of integers constantly; in the form
255 255 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
on loop, with each integer using one byte of data.
Trying:
import serial
ser = serial.Serial(0)
print (ser.name)
ser.baudrate = 56700
while True:ser.write(255 255 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000)
ser.close()
raises a Syntax Error
.
How can you write integers to a serial port if write
only sends strings? How can I ensure that each number is sent as 8-bits?
There is very little in the documentation for the class serial
, so any help will be appreciated.