56
M3i.48xx / M3i.48xx-exp Manual
Initialization
Programming the Board
Initialization
Before using the card it is necessary to open the kernel device to access the hardware. It is only possible to use every device exclusively using
the handle that is obtained when opening the device. Opening the same device twice will only generate an error code. After ending the
driver use the device has to be closed again to allow later re-opening. Open and close of driver is done using the spcm_hOpen and
spcm_vClose function as described in the “Driver Functions” chapter before.
Open/Close Example
Initialization of Remote Products
The only step that is different when accessing remotely controlled cards or digitizerNETBOXes is the initialization of the driver. Instead of the
local handle one has to open the VISA string that is returned by the discovery function. Alternatively it is also possible to access the card
directly without discovery function if the IP address of the device is known.
Multiple cards are opened by indexing the remote card number:
Error handling
If one action caused an error in the driver this error and the register and value where it occurs will be saved.
The driver is then locked until the error is read out using the error function spcm_dwGetErrorInfo_i32. Any
calls to other functions will just return the error code ERR_LASTERR showing that there is an error to be read
out.
This error locking functionality will prevent the generation of unseen false commands and settings that may lead to totally unexpected behav-
ior. For sure there are only errors locked that result on false commands or settings. Any error code that is generated to report a condition to
the user won’t lock the driver. As example the error code ERR_TIMEOUT showing that the a timeout in a wait function has occurred won’t
lock the driver and the user can simply react to this error code without reading the complete error function.
As a benefit from this error locking it is not necessary to check the error return of each function call but just checking the error function once
at the end of all calls to see where an error occurred. The enhanced error function returns a complete error description that will lead to the
call that produces the error.
drv_handle hDrv; // the handle of the device
hDrv = spcm_hOpen ("/dev/spcm0"); // Opens the board and gets a handle
if (!hDrv) // check whether we can access the card
{
printf “Open failed\n”);
return -1;
}
... do any work with the driver
spcm_vClose (hDrv);
return 0;
drv_handle hDrv; // the handle of the device
hDrv = spcm_hOpen ("TCPIP::192.168.169.14::INSTR"); // Opens the remote board and gets a handle
if (!hDrv) // check whether we can access the card
{
printf “Open of remote card failed\n”);
return -1;
}
...
hDrv = spcm_hOpen ("TCPIP::192.168.169.14::INSTR"); // Opens the remote board #0
// or alternatively
hDrv = spcm_hOpen ("TCPIP::192.168.169.14::INST0::INSTR"); // Opens the remote board #0
// all other boards require an index:
hDrv = spcm_hOpen ("TCPIP::192.168.169.14::INST1::INSTR"); // Opens the remote board #1
hDrv = spcm_hOpen ("TCPIP::192.168.169.14::INST2::INSTR"); // Opens the remote board #2