Python Forum
Reading data from serial port as byte array
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading data from serial port as byte array
#1
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,
Reply
#2
See here:
https://python-forum.io/Thread-help-with...-to-Python
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Waiting for input from serial port, then move on KenHorse 3 991 Yesterday, 07:21 AM
Last Post: DeaD_EyE
  MCU reboots after opening Serial port when ran from Raspberry PI zazas321 3 424 Mar-19-2024, 09:02 AM
Last Post: zazas321
  pyserial/serial "has no attribute 'Serial' " gowb0w 9 3,877 Aug-24-2023, 07:56 AM
Last Post: gowb0w
  Serial Port As Global Prasanjith 2 1,480 Mar-23-2023, 08:54 PM
Last Post: deanhystad
Star Pyserial not reading serial.readline fast enough while using AccelStepper on Arduino MartyTinker 4 4,044 Mar-13-2023, 04:02 PM
Last Post: deanhystad
  Reading All The RAW Data Inside a PDF NBAComputerMan 4 1,340 Nov-30-2022, 10:54 PM
Last Post: Larz60+
  extract only text strip byte array Pir8Radio 7 2,921 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
  Reading Data from JSON tpolim008 2 1,076 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Seeing al the data in a dataframe or numpy.array Led_Zeppelin 1 1,139 Jul-11-2022, 08:54 PM
Last Post: Larz60+
Question Change elements of array based on position of input data Cola_Reb 6 2,110 May-13-2022, 12:57 PM
Last Post: Cola_Reb

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020