Article From:

Part of the code:

#Open the serial portSer=serial.Serial ('COM3', 9600)Opening a threadTh=threading.Thread (target=thread_read, args= (SER, msg_)Parsed))Th.start ()Def thread_read (SER, callback=None):Buf=b''While running.is_set ():Buf=read_data (SER, buf, callback=None)Def read_data (SER, buf, callback=None):IfCallback is None:Callback=printBUF + = (ser.inwaiting ())

Why call inwait () in read_data (), report an error, tell me that there is no attribute’inwait ()’, write ser. inwait () outside the method is normal, I am not alreadyIs the reference to the serial object passed in? Book God answers!

Answer 0:

If you don’t pass the object, try using the global variable.

Answer 1:

print(dir(ser))Print all methods of SER, findinWaitingandin_waiting,There was no inwaiting, so it was wrong.
Are you sure that inwaiting is called outside?

ractmethods__', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__'
, '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__'
, '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__next__', '__reduce__', '__re
duce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_abc_cache', '_
abc_negative_cache', '_abc_negative_cache_version', '_abc_registry', '_baudrate', '_break_state', '_
bytesize', '_cancel_overlapped_io', '_checkClosed', '_checkReadable', '_checkSeekable', '_checkWrita
ble', '_close', '_dsrdtr', '_dtr_state', '_inter_byte_timeout', '_orgTimeouts', '_overlapped_read',
'_overlapped_write', '_parity', '_port', '_port_handle', '_reconfigure_port', '_rs485_mode', '_rts_s
tate', '_rtscts', '_stopbits', '_timeout', '_update_break_state', '_update_dtr_state', '_update_rts_
state', '_write_timeout', '_xonxoff', 'applySettingsDict', 'apply_settings', 'baudrate', 'break_cond
ition', 'bytesize', 'cancel_read', 'cancel_write', 'cd', 'close', 'closed', 'cts', 'dsr', 'dsrdtr',
'dtr', 'fileno', 'flush', 'flushInput', 'flushOutput', 'getCD', 'getCTS', 'getDSR', 'getRI', 'getSet
tingsDict', 'get_settings', 'inWaiting', 'in_waiting', 'interCharTimeout', 'inter_byte_timeout', 'ir
ead_until', 'isOpen', 'is_open', 'isatty', 'name', 'open', 'out_waiting', 'parity', 'port', 'portstr
', 'read', 'read_all', 'read_until', 'readable', 'readall', 'readinto', 'readline', 'readlines', 're
set_input_buffer', 'reset_output_buffer', 'ri', 'rs485_mode', 'rts', 'rtscts', 'seek', 'seekable', '
sendBreak', 'send_break', 'setDTR', 'setPort', 'setRTS', 'set_buffer_size', 'set_output_flow_control
', 'stopbits', 'tell', 'timeout', 'truncate', 'writable', 'write', 'writeTimeout', 'write_timeout',
'writelines', 'xonxoff']

Similar Posts:

Link of this Article: Python method invocation

Leave a Reply

Your email address will not be published. Required fields are marked *