V
V
Vitaly2017-11-17 20:36:18
Python
Vitaly, 2017-11-17 20:36:18

How to correctly convert a string to bytes?

All the best!
I want to use Python (2.7) to send commands to a device connected via COM port (serialport, linux) using the serial library .
The description for the device says that you need to send commands in the form of bytes, but I don’t quite understand how to do this, that is, how can I convert the data to bytes?
Here is what I am trying to do :

reset = [ 0x02, 0x03, 0x06, 0x30, 0x41, 0xB3 ]  # байты которые нужно отправить вместе
connection = serial.Serial(port='/dev/ttyS0',baudrate=9600)
connection.write(reset)
connection.close()

Can you please tell me how to reset to the correct form?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Movchan, 2017-11-17
@Scorpiored88

Here are some options:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question