beautypg.com

Measurement Computing Personal488 rev.3.0 For DOS & Windows 3.Xi User Manual

Page 226

background image

II. SOFTWARE GUIDES - 10. Driver488/W31

10E. C Languages

Personal488 User’s Manual, Rev. 3.0

II-211

/* Open Driver488/W31 */
if ((ieee=OpenName(“IEEE”))<0) {

MessageBox(hWndDlg,(LPSTR)"Cannot initialize IEEE system",
NULL,MB_OK);
EndDialog(hWndDlg, TRUE);
return TRUE;

}

/* Open or create the device named ADC */
Error(ieee, OFF);
switch (adc=OpenName(“ADC”)) {

case -2:

MessageBox(hWndDlg,(LPSTR)"ADC device already open",NULL,
MB_OK);
EndDialog(hWndDlg, TRUE);
return TRUE;

case -1:

/* Create the device ADC by copying the default device WAVE*/
switch (devhandle=OpenName(“WAVE”)) {

case -2:

MessageBox(hWndDlg,(LPSTR)"WAVE device already
open",NULL,MB_OK);
EndDialog(hWndDlg, TRUE);
return TRUE;

case -1:

MessageBox(hWndDlg,(LPSTR)"Cannot open WAVE
device",NULL,MB_OK);
EndDialog(hWndDlg, TRUE);
return TRUE;

default:

break;

}
if ((adc=MakeDevice(devhandle, “ADC”))) {

MessageBox(hWndDlg, (LPSTR)"Cannot create ADC device", NULL,
MB_OK);
EndDialog(hWndDlg, TRUE);
return TRUE;

}
Close(devhandle);

break;

default:

break;

}
GetError(ieee, textstr);
BusAddress(adc, 14, -1);

If the

ADC

was not configured within Driver488/W31, it can be optionally created “on the fly”, as

shown above. First

Error

was used to turn

OFF

automatic error reporting so that our application can

trap the error instead. If opening the name

ADC

failed, the handle of the device

IEEE

, which is always

available within Driver488/W31, is used to clone a new device called

ADC

using the

MakeDevice

command.

GetError

is then called to clear the internal error registered within Driver488/W31.

Lastly, the IEEE bus address

14

is assigned to the

ADC

.

If other devices were needed for the application at hand, they could either be defined in the startup
configuration for Driver488/W31 or they could be created “on the fly” from the application:

adc2 = MakeDevice(adc, “ADC2")
BusAddress (adc2,10,-1)

The new device

ADC2

is configured to reside at a different bus address so that the two devices may be

distinguished. There is one other important difference between

ADC

and

ADC2

at this point.

ADC2

is a

temporary device; that is, as soon as the creating application closes,

ADC2

ceases to exist. If our intent

was to create a device that could be accessed after this application ends, we must tell Driver488/W31
this:

KeepDevice (adc2)

After executing the previous statement,

ADC2

is marked as being permanent; that is, the device will not

be removed when the creating application exits. If we later wish to remove the device, however, we
can do so explicitly:

RemoveDevice (adc2)