Following my previous question. I was advised to make a separate python library and then import it.
After reading a bit more on Stackoverflow
, I realized that the best way is to write methods and I've taken up that path.
def USB(port):
activateme = serial.Serial(port,115200)
#print "starting to monitor"
for line in activateme:
#print line
return line
def USBprocess(line):
if line.startswith( '#d'):
fields = line.split(',')
if len(fields) > 5:
W = fields[1]
V = fields[2]
A = fields[3]
print "monitoring"
return W,V,A
op = USB(port)
w,v,a = USBprocess(op)
and I get the error:
UnboundLocalError: local variable 'W' referenced before assignment
what is it that I am doing wrong?