beautypg.com

Measurement Computing Personal Daq rev.6.0 User Manual

Page 121

background image

Personal Daq User’s Manual Appendix A,

878495

API Custom Program Modules A-3

All Visual Basic programs should include the

PDAQX.BAS

file into their project. The

PDAQX.BAS

file

provides the necessary definitions and function prototyping for the

DaqX

driver

DLL

.

handle& = VBdaqOpen&(“PDAQ123456”)
ret& = VBdaqClose&(handle&)

The PersonalDaq device is opened and initialized with the daqOpen function. daqOpen takes one
parameter—the name of the device to be opened. The device name is the device serial# pre-prended with

PDAQ

”.

For instance if the serial# for the Personal Daq is 123456 then the device name to use to open that device
would be “

PDAQ123456

”. 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 Personal Daq 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&(“PDAQ123456”) < 0) Then
“Cannot open PDaq”

Personal Daq 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
Personal Daq function call. Although not necessary, this sample program transfers program control to a
user-defined routine when an error is detected. Without a Personal Daq 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 Personal Daq error is encountered. The following line tells Visual
Basic to set ERR to 100 when a Personal Daq error is encountered. Other languages work similarly; refer
to specific language documentation as needed.

handle& = VBdaqOpen&(“PDAQ123456”)
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 routine ErrorHandler if an error is encountered.

Personal Daq errors will send the program into the error handling routine. This is the error handler.
Program control is sent here on error.

ErrorHandler:

errorString$ = "ERROR in ADC1"
errorString$ = errorString$ & Chr(10) & "BASIC Error :" + Str$(Err)
If Err = 100 Then errorString$ = errorString$ & Chr(10) & "DaqBook Error

: " + Hex$(daqErrno&)


MsgBox errorString$, , "Error!"

End Sub

This manual is related to the following products: