beautypg.com

Sample drivers, Visual basic drivers – Sensoray 417 User Manual

Page 10

background image

9

Sensoray Model 417

Chapter

4

Programming

Sample Drivers

We recommend that you incorporate procedures in your application software that will conceal the
coprocessor handshake protocol from higher host software levels. This will serve to simplify your
programming requirements and reduce software maintenance costs.

This section contains simple software drivers that implement the required handshake protocol. In
addition, the Visual Basic routines listed below are referenced throughout this chapter in numerous
programming examples. Feel free to plagiarize and adapt these routines for your application.

Visual Basic Drivers

Note to Microsoft Visual Basic programmers: the Visual Basic programming language does not
support direct I/O access. You will need a third-party tool, or a simple DLL of your own design, to
access the Model 417 from within a Visual Basic application.

All Visual Basic code examples assume the availability of external procedures, “INP” and “OUT,”
for implementing direct I/O access.

‘*******************************************************************

‘ Status Port mask constants

‘*******************************************************************

Const CRMT = &H80

‘Command Register eMpTy

Const DAV = &H40

‘Data AVailable

Const ALARM = &H20

‘Limit alarm(s) sounding

Const FAULT = &H10

‘Board fault

‘*******************************************************************

‘ Storage declarations

‘*******************************************************************

Dim BaseAdrs As Integer

‘ Base address of 417 board

‘*******************************************************************

‘ Handshake a byte into the 417 command register

‘*******************************************************************

Sub SendByte (BasePort As Integer, CommandByte As Integer)

Do: Loop Until (INP(BasePort + 1) And CRMT)

‘wait for CRMT

Call OUT(BasePort, CommandByte)

‘send the byte

End Sub

‘*******************************************************************

‘ Handshake a byte from the 417 data register

‘*******************************************************************

Function ReadByte%(BasePort As Integer)

Do: Loop Until (INP(BasePort + 1) And DAV)

‘wait for DAV

ReadByte = INP(BasePort)

‘read the byte

End Function