0

I send a data from the serial port as

1H|\^&|||c111^Roche^c111^2.0.0.0710^1^3334
44|||||host|TSREQ^REAL|

To serial port and at receiving end string got split as

1H|\^

and

&|||c111^Roche^c111^2.0.0.0710^1^3334
    44|||||host|TSREQ^REAL|

why it happened, i want to send it as a single string.

This is my code

 import serial
    import requests

    ser = serial.Serial(port='COM1',baudrate=9600,parity=serial.PARITY_NONE,stopbits=serial.STOPBITS_ONE,bytesize=serial.EIGHTBITS,timeout=0.5)
    concat = str()
    concat01=str()
    header = "b'\x021H|\^&||||||||||P||'\r\n"
    sample = "b'\x023Q|1|^0101645900^10^0^4^^SAMPLE^NORMAL||ALL||||||||O'\r\n"
    eol="b'\x024L|1|I'\r\n"
    patient_info = "b'\x022P|1'\r\n"

    while 1:
        z=ser.readline()
        print(z)
        print("Str Result",str(z))
        if str(z)!="b''":
            if str(z) == str(b'\x06'):
                print("verfied 06")
                concat = header + patient_info + sample + eol
                ser.write(concat.encode())
Sunil Jose
  • 221
  • 1
  • 15
  • 2
    How do you send it? At the lowest level, your serial interface is transmitting bytes, then it is up to you (or your library) to concatenate and parse the results. – JohanL Aug 01 '17 at 06:56
  • If you know how many bytes are in a packet, you should explicitly read that many bytes. If the packet size is variable, then you could prepend the packet with its size. Eg, if all packets contain <256 byes the packet size can be given by a single byte, so you read 1 byte, decode it, and then you know how many bytes to read to get the rest of the packet. – PM 2Ring Aug 01 '17 at 07:03
  • Modified my question with code – Sunil Jose Aug 01 '17 at 07:32
  • Your strings look strange "b'\x024L'" is a string with the characters b single-quote \x02 2 4 L single-quote in it. – Eliot Blennerhassett Aug 01 '17 at 10:01
  • To debug, I advise splitting into a sender and a receiver script, each using a distinct physical serial port (2 ports connected with null modem cable) – Eliot Blennerhassett Aug 01 '17 at 10:14

0 Answers0