Measurement Computing Data Acquisition Systems rev.10.4 User Manual
Page 20

Accessing and Changing a Device Name Using the Control Panel
To change a device name by going through the Control Panel you:
(1) Go to the Control Panel and select “Daq* Configuration.
(2) Double-Click on the applicable device.
(3) Highlight the existing name and type in the new one. Then click the “OK” button, not shown.
The
daqOpen
call, if successful, will return a handle to the opened device. This handle may then be used
by other functions to configure or perform other operations on the device. When operations with the
device are complete, the device may then be closed using the
daqClose
function. If the device could not
be found or opened,
daqOpen
will return -1.
The DAQX library has a default error handler defined upon loading. However; if it is desirable to change
the error handler or to disable error handling, then the
daqSetErrorHandler
function may be used to
setup an error handler for the driver. In the following example the error handler is set to
0
(no handler
defined), which disables error handling.
ret& = VBdaqSetErrorHandler&(0&)
If there is a Daq device error, the program will continue. The function’s return value (an error number or
0
if no error) can help you debug a program.
If (VBdaqOpen&(“DaqBook0”) < 0) Then
“Cannot open DaqBook0”
Daq device functions return
daqErrno&
.
Print “daqErrno& : ”; HEX$(daqErrno&)
End If
The next statement defines an error handling routine that frees us from checking the return value of every
Daq device function call. Although not necessary, this sample program transfers program control to a user-
defined routine when an error is detected. Without a Daq device error handler, Visual Basic will receive
and handle the error, post it on the screen and terminate the program. Visual Basic provides an integer
variable (ERR) that contains the most recent error code. This variable can be used to detect the error
source and take the appropriate action.
The function
daqSetErrorHandler
tells Visual Basic to assign ERR to a specific value when a Daq
device error is encountered. The following line tells Visual Basic to set ERR to 100 when a Daq device
error is encountered. (Other languages work similarly; refer to specific language documentation as
needed.)
handle& = VBdaqOpen&(“DaqBook0”)
ret& = VBdaqSetErrorHandler&(handle&, 100)
On Error GoTo ErrorHandler
The
On Error GoTo
command (in Visual Basic) allows a user-defined error handler to be provided,
rather than the standard error handler that Visual Basic uses automatically. The program uses
On Error
GoTo
to transfer program control to the label ErrorHandler if an error is encountered.
2-10 API Programming, General Models
988594
Programmer’s
Manual