Impact Acquire SDK Python
RequestFactory Class Reference

A default request factory. More...

Inheritance diagram for RequestFactory:
[legend]

Public Member Functions

 __disown__ (self)
 
 __init__ (self)
 
 createRequest (self, arg0, arg1)
 

Properties

 thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
 

Detailed Description

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.

# Example for a derived request object. It doesn't introduce new functionality
# but rebinds an existing property. Custom properties could bound in a similar
# way.
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)
# We MUST keep a reference to this request object here as otherwise the instance gets cleaned up
# by the garbage collector when leaving this function. We therefore add an artificial reference
# by adding this MyRequest instance to the array which is kind of silly but in Java we have a
# very similar effect (see corresponding snippet in the Java manual).
#
# Maybe there is a better way to do this! Suggestions welcome!
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):
# ... some code ...
mrf = MyRequestFactory()
fi = acquire.FunctionInterface(pDev, mrf)
# ... more additional code
# assuming we got back a request from the driver at this point:
pRequest = fi.getRequest(getRequestNrFromSomewhere())
if pRequest.isOK:
# The paranoid could do this additional check, but it is not necessary:
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)
# do what you want to do with your derived request instance here!
# ... probably even more additional code
}
Since
1.12.56

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self)

Member Function Documentation

◆ __disown__()

__disown__ ( self)

◆ createRequest()

createRequest ( self,
arg0,
arg1 )

Property Documentation

◆ thisown

thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
static