简体   繁体   中英

Porting Serial.write(Byte, int, int) from C# to Python using Pyserial

I have code written in C# that I want to port to Python.

I want to port Serial.write(Byte, int, int) from C# to Python and I am using Pyserial. I tried Serial.Write in Pyserial but wasn't able to get the work done.

Can anyone guide me through how to create a similar function in Python?

According to the docs , you need to write bytes , not numbers.

So you need to convert your numbers, which are one byte and two int , to bytes.

You can do that with the struct module. See the struct.pack method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM