Python Forum

Full Version: Reading data from serial port as byte array
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'm new here and i'm begginer in python programming. I need to convert c# code to python but i stuck when i wanted to read serial data as byte array.

Here is the code:
int _byteToRead = P._serialPort.BytesToRead;
byte[] inBuffer = new byte[_byteToRead];
P._serialPort.Read(inBuffer, 0, _byteToRead); //Reads a number of characters from the System.IO.Ports.SerialPort input buffer and writes them into an array of characters at a given offset.
........................
byte MatchStart = 242; // HEX: F2
byte MatchEnd = 248; // HEX: F8

I don't know how to convert the first 3 lines.

Thanks,