I have a question about sending and receiving multiple data using the pySerial Python library. According to what I understand, serial port communication works with byte variables.
How do I send four different variables with method write
and then with method read
receive two different variables?
As an example:
import serial
import time
sendSerial = serial.Serial ("COM4", 9600)
readoutSerial = serial.Serial ("COM4", 9600)
time.sleep (2)
sendSerial.write ("data1" + "data2" + "data3" + "data4")
while True:
readoutSerial.read ("data5" + "data6")
What should I do to send the four variables with write
differentiated by some character and then separate them for the respective use of each variable? (applying the same for the two variables received with read
) Also, what can I do to send the variables asfloat
and not generate conflict with the reading in byte
?