Reputation: 151
I'm using the KISS Python module to collect data from the serial communications port. This module has a function that returns the value of the values obtained from the serial port. The lines of code, obtained the source code of the module are the following:
for frame in frames:
if len(frame) and ord(frame[0]) == 0:
self.logger.debug('frame=%s', frame)
self.logger.debug('hola soy el logger debug')
if callback:
callback(frame)
I'm trying to store the value of frame in a variable. I need to do in a thread that I created through inheritance an object of class QThread
. I am making an application using PyQt4.
The class is as follows:
class OperativeKISSThread(KISSThread):
def __init__(self, parent = None):
KISSThread.__init__(self, parent)
def doWork(self):
prueba.read(callback=self.catchValue(frame))
return True
def catchValue(self, frame):
print frame
When I run the above code I get the following screen output:
Traceback (most recent call last):
File "_client_amp.py", line 432, in run
success = self.doWork(self.kissTNC)
File "_client_amp.py", line 452, in doWork
prueba.read(callback=self.catchValue(frame))
NameError: global name 'frame' is not defined
What changes would be made in my code to get the value of frame?
Upvotes: 1
Views: 42
Reputation: 6826
The callback should be specified using just the function name, like:
def doWork(self, prueba):
prueba.read(callback=self.catchValue)
return True
Upvotes: 2