beautypg.com

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

Page 225

background image

10E. C Languages

II. SOFTWARE GUIDES - 10. Driver488/W31

II-210

Personal488 User’s Manual, Rev. 3.0

The program only has one menu with two selections: Go and Quit. When Go is selected, the service
routine for Go opens Driver488/W31. Then the

Hello

function is called, using the handle returned

from the

OpenName

function:

case WM_INITDIALOG:

cwCenter(hWndDlg, 0);
/* initialize working variables */
ieee=OpenName(“IEEE”);
Hello(ieee, hellomsg);
SetDlgItemText(hWndDlg, 101, (LPSTR)hellomsg);
Close(ieee);
break; /* End of WM_INITDIALOG */

After the Hello Message window is displayed, as shown in the figure, the driver handle is closed. Since
in this application the handle is created every time Go is selected, a potential conflict could arise if that
handle is not closed as we exit this subroutine. Clicking the OK button will close this window.

When the application is closed by selecting Quit, the

WM_DESTROY

message is sent to Driver488/W31:

case WM_CLOSE:

/* close the window */

hDriver=FindWindow((LPSTR)"Driver488Loader",
(LPSTR)"Driver488/W31");
SendMessage(hDriver, WM_DESTROY, 0, 0L);
DestroyWindow(hWnd);
if (hWnd == hWndMain)

PostQuitMessage(0);

/* Quit the application */

break;

Establishing Communications

The following program contains most of the function calls of Driver488/W31. The user interface of
this program is intentionally simple to highlight the Driver488/W31 operations. To centralize all of the
Driver488/W31-related code, the architecture of this example is not typical of a C program. This
example operates the multi-channel 16-bit analog-to-digital converter; the ADC488.

In every C program using Driver488/W31, header files of declarations must be merged into the
program. In the next example, those declarations are omitted from the listing for the sake of brevity.

With the associated source files, the following program can be built using the file

EXAMPLE2.MAK

(for

Miscrosoft C or Quick C users) or

EXAMPLE2.PRJ

(for Borland C users) found on the Driver488/W31

disk.

This example has several declarations that will be used later:

HWND hDriver

/* handle for Driver488/W31 */

DevHandleT ieee, adc, devhandle;

/* handles for the IEEE board * /

char textstr[2048], response[64];

/* string for Driver488responses */

double sum, voltage;

/* variables for ADC488 responses */

For the sake of this discussion, assume that Driver488/W31 has been configured to start with a
configuration including the devices

IEEE

(IEEE 488 interface) and

ADC

(ADC488/8S connected to the

IEEE 488 interface). Additional interfaces and/or devices may also have been defined, as the driver
can support up to 4 interfaces and 56 devices simultaneously. To open the two devices of interest, we
use the following statements:

Hello Message Window