(self, param)
return speed, parity, bytesize, stop, rs, cs, ds, cd, lf, pe
Parse serial port connection parameters
Parse serial port connection parameters
Parse serial port connection parameters
def _parse_params(self, param):
        """Parse serial port connection parameters """
        max_param = 10
        param_list = param.upper().split(b',')
        if len(param_list) > max_param:
            raise error.BASICError(error.BAD_FILE_NAME)
        param_list += [b''] * (max_param-len(param_list))
        speed, parity, data, stop = param_list[:4]
        # set speed
        if speed not in (
                b'75', b'110', b'150', b'300', b'600', b'1200',
                b'1800', b'2400', b'4800', b'9600', b''
            ):
            # Bad file name
            raise error.BASICError(error.BAD_FILE_NAME)
        speed = int(speed) if speed else 300
        # set parity
        if parity not in (b'S', b'M', b'O', b'E', b'N', b''):
            raise error.BASICError(error.BAD_FILE_NAME)
        parity = parity or b'E'
        # set data bits
        if data not in (b'4', b'5', b'6', b'7', b'8', b''):
            raise error.BASICError(error.BAD_FILE_NAME)
        data = int(data) if data else 7
        bytesize = data + (parity != b'N')
        if bytesize not in range(5, 9):
            raise error.BASICError(error.BAD_FILE_NAME)
        # set stopbits
        if stop not in (b'1', b'2', b''):
            raise error.BASICError(error.BAD_FILE_NAME)
        if not stop:
            stop = 2 if (speed in (75, 110)) else 1
        else:
            stop = int(stop)
        lf, rs, cs, ds, cd, pe = False, False, None, 1000, 0, False
        for named_param in param_list[4:]:
            if not named_param:
                continue
            try:
                if named_param == b'RS':
                    # suppress request to send
                    rs = True
                elif named_param[:2] == b'CS':
                    # set CTS timeout - clear to send
                    # 0 for empty string; BAD FILE NAME if not numeric
                    cs = int(named_param[2:]) if named_param[2:] else 0
                elif named_param[:2] == b'DS':
                    # set DSR timeout - data set ready
                    ds = int(named_param[2:]) if named_param[2:] else 0
                elif named_param[:2] == b'CD':
                    # set CD timeout - carrier detect
                    cd = int(named_param[2:]) if named_param[2:] else 0
                elif named_param == b'LF':
                    # send a line feed at each return
                    lf = True
                elif named_param == b'PE':
                    # enable parity checking
                    # not implemented
                    pe = True
                else:
                    raise error.BASICError(error.BAD_FILE_NAME)
            except ValueError:
                raise error.BASICError(error.BAD_FILE_NAME)
        # CS default depends on RS
        if cs is None:
            cs = 1000 if not rs else 0
        return speed, parity, bytesize, stop, rs, cs, ds, cd, lf, pe
def _parse_params ( self , param ) : max_param = 10 param_list = param . upper ( ) . split ( b',' ) if len ( param_list ) > max_param : raise error . BASICError ( error . BAD_FILE_NAME ) param_list += [ b'' ] * ( max_param - len ( param_list ) ) speed , parity , data , stop = param_list [ : 4 ] # set speed if speed not in ( b'75' , b'110' , b'150' , b'300' , b'600' , b'1200' , b'1800' , b'2400' , b'4800' , b'9600' , b'' ) : # Bad file name raise error . BASICError ( error . BAD_FILE_NAME ) speed = int ( speed ) if speed else 300 # set parity if parity not in ( b'S' , b'M' , b'O' , b'E' , b'N' , b'' ) : raise error . BASICError ( error . BAD_FILE_NAME ) parity = parity or b'E' # set data bits if data not in ( b'4' , b'5' , b'6' , b'7' , b'8' , b'' ) : raise error . BASICError ( error . BAD_FILE_NAME ) data = int ( data ) if data else 7 bytesize = data + ( parity != b'N' ) if bytesize not in range ( 5 , 9 ) : raise error . BASICError ( error . BAD_FILE_NAME ) # set stopbits if stop not in ( b'1' , b'2' , b'' ) : raise error . BASICError ( error . BAD_FILE_NAME ) if not stop : stop = 2 if ( speed in ( 75 , 110 ) ) else 1 else : stop = int ( stop ) lf , rs , cs , ds , cd , pe = False , False , None , 1000 , 0 , False for named_param in param_list [ 4 : ] : if not named_param : continue try : if named_param == b'RS' : # suppress request to send rs = True elif named_param [ : 2 ] == b'CS' : # set CTS timeout - clear to send # 0 for empty string; BAD FILE NAME if not numeric cs = int ( named_param [ 2 : ] ) if named_param [ 2 : ] else 0 elif named_param [ : 2 ] == b'DS' : # set DSR timeout - data set ready ds = int ( named_param [ 2 : ] ) if named_param [ 2 : ] else 0 elif named_param [ : 2 ] == b'CD' : # set CD timeout - carrier detect cd = int ( named_param [ 2 : ] ) if named_param [ 2 : ] else 0 elif named_param == b'LF' : # send a line feed at each return lf = True elif named_param == b'PE' : # enable parity checking # not implemented pe = True else : raise error . BASICError ( error . BAD_FILE_NAME ) except ValueError : raise error . BASICError ( error . BAD_FILE_NAME ) # CS default depends on RS if cs is None : cs = 1000 if not rs else 0 return speed , parity , bytesize , stop , rs , cs , ds , cd , lf , pe