A default request factory.
Applications need to derive from this class and must re-implement the function mvIMPACT.acquire.RequestFactory.createRequest to work with custom objects derived from mvIMPACT.acquire.Request.
Deriving from mvIMPACT.acquire.Request can be useful when a certain device driver or device offers a custom feature that is returned as part of the request object that can not be accessed using the mvIMPACT.acquire.Request class offered by this interface.
This shows how a request factory could be used to create custom request objects from within a mvIMPACT::acquire::FunctionInterface instance.
class MyRequest(acquire.Request):
def __init__(self, *args):
acquire.Request.__init__(self, *args)
self.myRequestResult = acquire.PropertyIRequestResult()
locator = acquire.DeviceComponentLocator(self.getComponentLocator().hObj())
locator.bindComponent(self.myRequestResult, "Result")
class MyRequestFactory(acquire.RequestFactory):
def __init__(self):
acquire.RequestFactory.__init__(self)
self.__instances = []
def createRequest(self, pDev, requestNr):
try:
instance = MyRequest(pDev, requestNr)
self.__instances.append(instance)
return instance
except Exception as e:
print("An exception has been raised by code that is not supposed to raise one: '" + str(e) + "'! If this is NOT handled here the application will crash as this Python exception instance will be returned back into the native code that fired this function callS!")
return None
Now the request factory must be passed to the constructor of the function interface
def fn(pDev):
mrf = MyRequestFactory()
fi = acquire.FunctionInterface(pDev, mrf)
pRequest = fi.getRequest(getRequestNrFromSomewhere())
if pRequest.isOK:
if type(pRequest) is MyRequest:
print(pMyRequest.myRequestResult.name() + ": " + pMyRequest.myRequestResult.readS())
else:
print("ERROR! We should have an instance of our derived 'MyRequest' class here!")
sys.exit(-1)
}
- Since
- 1.12.56