Python Forum
Reading data from serial port as byte array - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Reading data from serial port as byte array (/thread-15212.html)



Reading data from serial port as byte array - vlad93 - Jan-08-2019

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,


RE: Reading data from serial port as byte array - heiner55 - May-18-2019

See here:
https://python-forum.io/Thread-help-with-converting-C-function-to-Python