I'm new here and I'm a beginner in python programming. I need to convert C# code to python but I stuck when I wanted to read serial data as byte array. I used extend()
and bytearray()
functions but nothing is working.
Bellow is the C# code which I want to convert to Python 3.x
do
{
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
try
{
for (int j = 0; j < inBuffer.Length; j++)
{
if (inBuffer[j] == MatchStart)
I don't know how to convert the first 3 lines.
I tried:
bytedata=ser.read(10000) # I need to
b=bytearray()
b.extend(map(ord, bytedata))
or:
bytedata+=ser.read(ser.inWaiting())
z=bytearray(bytedata)
Thanks.