Python Forum
Reading mixed ASCII/binary serial input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Reading mixed ASCII/binary serial input
#2
I think I figured it out. This seems to work with a timeout of 1 second:

    self.serial.timeout = 1
    delimiter = b'$PASHR'
    if self.serial.in_waiting:
        message = self.serial.read_until(delimiter)
        if len(message) > 6: # ignore carryover b'$PASHR'
            ***process message***
When I looked carefully at the variable length returns, I discovered that the message sequence after the first incomplete cycle was:

b'$PASHR' (6 bytes)
b',MPC,<data><checksum>\r\n$PASHR' (108 bytes)
...
b',MPC,<data><checksum>\r\n' (102 bytes)
(delay)
b'$PASHR' (6 bytes)

The delimiter from the last message in the sequence is chopped off and output at the beginning of the next sequence. I can deal with that.
Reply


Messages In This Thread
Reading mixed ASCII/binary serial input - by N8UR - Jun-10-2019, 09:22 PM
RE: Reading mixed ASCII/binary serial input - by N8UR - Jun-11-2019, 02:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PC why serial code = converting to ascii ? trix 11 2,304 Oct-12-2024, 11:10 PM
Last Post: deanhystad
  pyserial/serial "has no attribute 'Serial' " gowb0w 11 21,886 Sep-27-2024, 12:18 PM
Last Post: NigelHalse
  Reading an ASCII text file and parsing data... oradba4u 2 1,403 Jun-08-2024, 12:41 AM
Last Post: oradba4u
  Waiting for input from serial port, then move on KenHorse 3 4,130 Apr-17-2024, 07:21 AM
Last Post: DeaD_EyE
Star Pyserial not reading serial.readline fast enough while using AccelStepper on Arduino MartyTinker 4 8,421 Mar-13-2023, 04:02 PM
Last Post: deanhystad
  Reading an Input File DaveG 1 1,837 Mar-27-2022, 02:08 AM
Last Post: deanhystad
  serial input/output barryjo 3 4,981 Dec-27-2021, 11:57 PM
Last Post: barryjo
  Help reading data from serial RS485 korenron 8 19,192 Nov-14-2021, 06:49 AM
Last Post: korenron
  Group List Elements according to the Input with the order of binary combination quest_ 19 9,174 Jan-28-2021, 03:36 AM
Last Post: bowlofred
  Reading Serial data Moris526 6 7,292 Dec-26-2020, 04:04 PM
Last Post: Moris526

Forum Jump:

User Panel Messages

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