Dynamically Creating Channel Class Instance
Posted: Wed Jan 16, 2019 2:19 am
Per the API docs, channels returned by Manager OnAttach handlers are read-only objects, and the developer should create new instances of the correct type.
My question is, is there a way to dynamically create the correct type?
Cannot use ch.__class__ as it is always an instance of class Phidget.
Is it possible to use ch.getChannelClassName() to somehow create the proper class instance?
Otherwise we get code like this:
My question is, is there a way to dynamically create the correct type?
Cannot use ch.__class__ as it is always an instance of class Phidget.
Is it possible to use ch.getChannelClassName() to somehow create the proper class instance?
Otherwise we get code like this:
Code: Select all
def on_manager_attach_handler(self, ch):
if ch.getChannelClass() == ChannelClass.PHIDCHCLASS_DIGITALINPUT:
ch_new = DigitalInput()
elif ch.getChannelClass() == ChannelClass.PHIDCHCLASS_DIGITALOUTPUT:
ch_new = DigitalOutput()
...