Driver Initialization

As you can see from these calls, you need to supply the board handle nHandle every time you call the driver procedures. Instead, you can define a driver variable m_nHandle that will have the driver handle. Every time you need to access the driver, you can use that variable. The variable can be initialized in the driver OnInit event that is called only once when the application starts. This relieves the user from calling any initialization code before calling the driver commands.

Looking over the Gx6138 driver OnInit event will show you just that: OnInit has the following code:

if nSlot=0 then nSlot=Driver.Parameters("Slot")
if nSlot=0 then

error -1, "Driver Parameter 'Slot' not set to the board PCI slot number.\nPlease set the parameter value from the driver shortcut property page."

endif

The Gx6138 PXI slot number, if not supplied as a parameter to the Initialize is retrieved from the driver shortcut using the Parameters ADriver property. When you insert a driver into your system, you should set the base address of the board.

Looking over at the driver procedure to see the code for the Initialize procedure, you will see the following code:

Gx6138Initialize(nSlot, m_nHandle, nStatus)
CheckError(nStatus)

As you can see, the Gx6138Initialize accepts the nSlot and returns the handle to m_nHandle and the status to nStatus. nStatus is passed to a driver procedure called CheckError, which provides error handling for the driver as explained in Handling Errors in a Driver.