src/comm2checker.py
def sendMsg(self, msg: str, waittime: float) -> str:
        """
        send message and receive return message

        Parameters
        ----------
            port: object
                Serial
            msg: str
                message for checker (only from bit assign)
            waittime: float
                time out second
        Returns
        ----------
            rx: str
                return message from checker
        """
        # check input
        if msg[0:2].isdecimal() and int(msg[0:2])<100:
            # only decimal, 0~99
            tx = msg
        else:
            print('Error : Serial Message header is only decimal in 0~99.')
            return None
        # comm
        # send msg as string
        self.port.write(tx.encode('utf-8'))
        # waiting rx
        start = time.time()
        elapsedTime = 0
        while elapsedTime<10:
            # read rx
            rxRaw = self.port.readline()
            # convert rx from bytes to string
            rx = ''.join(rxRaw.decode('utf-8').splitlines())
            if rx !='':
                return rx
            time.sleep(waittime)
            elapsedTime = time.time()-start
        if elapsedTime >= 10:
            return 'timeout'

        send message and receive return message

        Parameters
        ----------
            port: object
                Serial
            msg: str
                message for checker (only from bit assign)
            waittime: float
                time out second
        Returns
        ----------
            rx: str
                return message from checker
        
send message and receive return message
Parameters

object
Serial
msg: str
message for checker (only from bit assign)
waittime: float
time out second
Returns

str
return message from checker
send message and receive return message Parameters object Serial msg : str message for checker ( only from bit assign ) waittime : float time out second Returns str return message from checker
def sendMsg(self, msg: str, waittime: float) -> str:
        if msg[0:2].isdecimal() and int(msg[0:2])<100:
            tx = msg
        else:
            print('Error : Serial Message header is only decimal in 0~99.')
            return None
        self.port.write(tx.encode('utf-8'))
        start = time.time()
        elapsedTime = 0
        while elapsedTime<10:
            rxRaw = self.port.readline()
            rx = ''.join(rxRaw.decode('utf-8').splitlines())
            if rx !='':
                return rx
            time.sleep(waittime)
            elapsedTime = time.time()-start
        if elapsedTime >= 10:
            return 'timeout'
def sendMsg ( self , msg : str , waittime : float ) -> str : if msg [ 0 : 2 ] . isdecimal ( ) and int ( msg [ 0 : 2 ] ) < 100 : tx = msg else : print ( 'Error : Serial Message header is only decimal in 0~99.' ) return None self . port . write ( tx . encode ( 'utf-8' ) ) start = time . time ( ) elapsedTime = 0 while elapsedTime < 10 : rxRaw = self . port . readline ( ) rx = '' . join ( rxRaw . decode ( 'utf-8' ) . splitlines ( ) ) if rx != '' : return rx time . sleep ( waittime ) elapsedTime = time . time ( ) - start if elapsedTime >= 10 : return 'timeout'
send message and receive return message
Parameters
send message and receive return message Parameters
"""
        send message and receive return message

        Parameters
        ----------
            port: object
                Serial
            msg: str
                message for checker (only from bit assign)
            waittime: float
                time out second
        Returns
        ----------
            rx: str
                return message from checker
        """ # check input # only decimal, 0~99 # comm # send msg as string # waiting rx # read rx # convert rx from bytes to string
self
msg
str
waittime
float