I’ve just started on Nameko and I think maybe the problem I’m having is unfamiliar vocabulary. I hope you’ll bear with me or point me in the right direction.
I have two issues that I’m trying to understand.
- I have a serial device attached to a small computer (Raspberry Pi), and I want to keep the connection from the device to the Pi open, once it’s opened through eg ttyUSB0. It will return a “Serial” object that I wish to be persistent on the Pi. The Raspberry Pi’s sole function is to run the device handler service. I wanted to have a global variable holding it on the Pi Service, but the Methods didn’t seem to be able to see it. Like this:
class Arduino(object): name = "Arduino_service" test=0 # Initialise Arduino @rpc def connect(self): # Set serial port to 0 self.ser = 0 test=test+1 print (test)
File "./ArduinoService.py", line 19, in connect test=test+1 UnboundLocalError: local variable 'test' referenced before assignment
- The second problem is how to access the code from my main application:
I thought I could do this:
Arduino = json.loads(n.rpc.Arduino_service.connect())
But apparently not. No error, nothing. Do I need to use a framework like Flask to do it for me?
PS Is there a way of formatting code on this board?