beautypg.com

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

Page 249

background image

10F. Visual Basic

II. SOFTWARE GUIDES - 10. Driver488/W31

II-234

Personal488 User’s Manual, Rev. 3.0

Project window. Using the VB File menu, select the item Add File and select

IOTVB10.BAS

. At this

point, all Driver488/W31 functions should be accessible.

If you require event handling support, use the custom control written for event handling. The IEEE
488 Event Custom Control support is included in the file

IOTEVENT.VBX

, which should be included in

the Project window. For more information on using the IEEE 488 Event Custom Control, turn to the
following topic “IEEE 488 Event Custom Control” in this Sub-Chapter.

Opening & Closing the Driver

The first Driver488/W31 programming example is designed for simplicity. Its sole purpose is to verify
proper communication with the driver, and upon closing, remove the driver from memory.

In every Visual Basic program using Driver488/W31, a file of declarations must be merged into the
program, typically to the

GLOBAL.BAS

file. In the following example, those declarations have been

omitted from the listing for the sake of brevity.

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

EXAMPLE1.MAK

found on the Driver488/W31 disk.

This example has two declarations that will be used later:

Declare Function FindWindow Lib “User” (ByVal data1$, ByVal data2$)As

Integer

Declare Function SendMessage Lib “User” (ByVal winHandle%, ByVal

message%, ByVal wp%, ByVal lp As Long) As Integer

The form has only one text box with one button . When the button is pressed, the service routine for

Command1_Click

opens the driver. Then the

Hello

function is called, using the handle returned from

the

OpenName

function.

Sub Command1_Click ()

Dim ieee As Integer
Dim hellomsg As String * 247
ieee = OpenName (“IEEE”)
errcode = Hello (ieee, ByVal hellomsg)
Response.Text = hellomsg
errcode = ioClose(ieee)

End Sub

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 the form button is pressed, a potential conflict could
arise if that handle is not closed as we exit this subroutine. Clicking the HELLO button will close this
window.

When the application is closed by the user, the

Unload

event is sent to the form. Our service routine

for

Unload

uses the functions that were declared earlier in the

GLOBAL.BAS

file.

Sub Form_Unload (Cancel As Integer)

‘Unload the IEEE driver
loaderName$ = “Driver488Loader”
winName$ = “Driver488/W31”
Hdriver% = FindWindow (loaderName$, winName$)
asdf = SendMessage (Hdriver%, &H2, 0, 0)

End Sub

Hello Message Window