Hi Mark,
Every event handler in Phidget22 for Python has a self parameter that references the instance of the object that called the event.
To pass data to the event handlers, you can add attributes to the object instance, and it will be available using the self parameter of the event, which is the first parameter in the list for the event handler.
In our examples, the self parameter is labeled 'e', though you can label it 'self' in your application.
For example, with a digital input object, you could use the following to pass a file name to its events.
Code: Select all
ch = DigitalInput()
#add a 'filename' attribute
ch.filename = "fileName.txt"
ch.setOnStateChangeHandler(StateChangeHandler)
Which can then be referenced in the event handler as follows:
Code: Select all
def StateChangeHandler(self, state):
print("State: %f" % state)
if(getattr(self, "filename", None) is not None):
print(self.filename)
#code for dealing with your file here