
Programming the Board
Initialization
(c) Spectrum Instrumentation GmbH
63
Complete C/C++ Example
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_v
-
Close 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.
#include “../c_header/dlltyp.h”
#include “../c_header/regs.h”
#include “../c_header/spcm_drv.h”
#include <stdio.h>
int main()
{
drv_handle hDrv; // the handle of the device
int32 lCardType; // a place to store card information
hDrv = spcm_hOpen ("/dev/spcm0"); // Opens the board and gets a handle
if (!hDrv) // check whether we can access the card
return -1;
spcm_dwGetParam_i32 (hDrv, SPC_PCITYP, &lCardType); // simple command, read out of card type
printf (“Found card M2i/M3i/M4i/M4x/M2p.%04x in the system\n”, lCardType & TYP_VERSIONMASK);
spcm_vClose (hDrv);
return 0;
}
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
Содержание M2p.59 Series
Страница 190: ......