0

I am link modem to pi3 via serial port and configure this port . When i receive data in my python software from serial port and save bytes in file, i note i receive too mutch data , I am receiving byte by byte , For example if transmited data from modem to pi3 was 1.5 kbyte , my softwre receive 5.5 k byte.

I note there is many line duplicated .

I use port. Read() Shul i use read until or read inwait? Can any one help me or explain this matter?

2
  • 1
    Not a Pi specific question. Wherever you ask this question you will need to show the code you used and an example of the output against the expected output.
    – joan
    Apr 4, 2021 at 12:25
  • are you certain that baud rates, bit settings are correct? One can usually expect some noise too that should be rejected by checking parity or some additional embedded check.
    – Abel
    Dec 31, 2021 at 3:15

1 Answer 1

0
    import serial
                b = open("/home/pi/20", "wb")
                byte=port.read()
                num_byte+=1
                while True:
                       if byte== b'\x10':
                            x = port.read(1)
                            if x== b'\x03':
                                #b.write(b'\x10x\03')
                                print('end of file')
                                num_byte+=2
                                b.close()
                                break
                            
                            if x == b'\x10':
                                b.write(b'\x10')
                                byte = port.read(1)
                                num_byte+=1
                                continue
                            if x== b'\x1a':
                                b.write(b'\x10\x10')
                                num_byte+=2
                                byte = port.read(1)
                                continue
                            else:
                                
                               
                                byte = port.read(1)
                                num_byte+=2
                                continue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.