Closed ned closed 6 years ago
when I run this, I get an error:
UnboundLocalError: local variable 'r' referenced before assignment
But I think that was already a problem before the commit (?)
The code should be pretty much the same, except that I moved the serial and socket stuff into functions to make it easy to call from main.py. I do the
if __name__ == '__main__':
so that both the original files should behave exactly the same as before if run directly, instead of through main.py (like if you just want to have the rpi be a speaker or just be a scanner). I renamed run.py --> speaker.py to make it more clear.
Fixed the UnboundLocalError (can't use undeclared variables outside try block)
New error is this:
serial.serialutil.SerialException: [Errno 2] could not open port /dev/ttyUSB0: [Errno 2] No such file or directory: '/dev/ttyUSB0'
Just because I don't have a usb input device to test it with yet I think. But we should get the usb scanners in the next couple of days.
This uses the selectors Python library, which allows us to wait on multiple file-like objects (e.g. sockets, serial ports) and handle incoming data concurrently.
Note: this doesn't do threading or parallel stuff, it's only ever handling one thing at a time, but that's not a bad thing, as long as the handlers don't run forever.