Timing about serial ports, best practices in binary mode

2 thoughts on “Timing about serial ports, best practices in binary mode

  1. Hi all!

    My name is Frank, I use this modules from long time ago for several applications.


    Now I want to migrate a code wroted in C that is today inside a MCU to a GM862-quad-py module.

    The issue about this is that the read string do not have any EOF character. It’s finish the stream and that is all. So the software must have the functionality to get the complete stream until the silence appears or when a time-out runs.

    It’s binary stream, is not text so the NULL are valid. 

    This is about the Rx, to stablish and mantain the comunication flowing, the response will be sent in less than 300 mSec.


    This stream apears at 2 seconds, so to sincronize it the first read must wait for it, or waits always for it. 


    I write this to try to start:


    def GetResponse(Timeout):

        RxByte =0



        while(RxByte != -1):

            RxByte = SER2.receivebyte(1)


            if (RxByte != -1):

                StrBuffer = StrBuffer + chr(ord(RxByte))


        if (RxByte == -1):

            print ‘Rx: ‘ + printHex(StrBuffer)

            return StrBuffer 





    a = GetResponse()

    if (a!=-1): print a