B&B Electronics 232OPSDA manual Application Program Interface

Page 20

Chapter 5: Software

Application Program Interface

The application program interface (API) is a set of routines that makes it easy to communicate with the 232OPSDA module from a 16- bit DOS application. Example programs using the API are written in

Borland C++, Borland Pascal and Microsoft® QuickBASIC v4.5. The batch file, MAKEIT.BAT, in the directory for each language shows how to compile and link the demo program with the API routines.

B232OPSDA_ReadAnalog

Purpose: This function reads the A/D input channels.

Syntax:

C:

BOOL B232OPSDA_ReadAnalog (WORD hComDev,

 

 

 

 

 

 

BYTE modAddr, WORD channels, WORD* data);

 

Pascal:

function B232OPSDA_ReadAnalog (hComDev :

 

 

 

word; modAddr : byte; channels : word;

 

BASIC:

data : Pword);

 

 

 

 

FUNCTION B232OPSDAReadAnalog (BYVAL

 

 

 

hComDev AS INTEGER, BYVAL modAddr AS

 

 

 

INTEGER, BYVAL channels AS INTEGER, BYVAL

 

 

 

wdataseg AS INTEGER, BYVAL wdataoff AS

 

 

 

INTEGER)

 

 

 

Remarks:

hComDev is the handle to a serial port where the

 

module is connected. This is the value returned by

 

initComPort. modAddr is the module address, which

 

is always 30H (48 decimal) for the 232OPSDA module.

 

channels is a bit mask for the A/D input channels that

 

should be read. See the table below for the meaning of

 

each bit.

 

 

 

 

 

Bit

 

Channel

Value

Value

 

 

 

 

 

(hex)

(decimal)

 

 

 

 

 

 

 

 

Bit 7

 

(nothing)

80H

128

 

 

Bit 6

 

(nothing)

40H

64

 

 

Bit 5

 

A/D Channel 5

20H

32

 

 

Bit 4

 

A/D Channel 4

10H

16

 

 

Bit 3

 

A/D Channel 3

08H

8

 

 

Bit 2

 

A/D Channel 2

04H

4

 

 

Bit 1

 

A/D Channel 1

02H

2

 

 

Bit 0

 

A/D Channel 0

01H

1

 

data is that address of an array of 16-bit values where the results of the A/D conversion will be stored.

For QuickBASIC users: wdataseg and wdataoff are the

Documentation Number 232OPSDA1397 Manual

19

B&B Electronics -- PO Box 1040 -- Ottawa, IL 61350

PH (815) 433-5100 -- FAX (815) 433-5105

Image 20
Contents Internet Electronics Mfg. Co. IncDesigned and Manufactured Ottawa, Illinois Table of Contents Page 232OPSDA Features IntroductionGeneral Block Diagram Packing ListAnalog to Digital Converter Software Installation232OPSDA Specifications Power Supply Digital InputDigital Output CommunicationsConnections Terminal Function Description Block232OPSDA Digital I/O Connections Serial Port Connections232OPSDA Power Supply Connections Commands Syntax Reading A/D Channels Command Reading Digital I/O Command Set Digital Output Command0RD StatesSampling Rate Converter RangeNon-buffered 0 to 5VDC A/D Inputs Buffered 0 to 5V A/D InputsTo 10VDC A/D Input 20mA Current Loop A/D InputGain = Application Program Interface B232OPSDAReadDigital Syntax CB232OPSDASetDigitalOutput ReturnsDeinitComPort Purpose See AlsoLow-Level Communications Port AddressReturns See Also DeinitComPortRead A/D Command Command$ = !0RA + CHR$channelPrint #1, Command$ MSB$ = INPUT$1, #1 LSB$ = INPUT$1, #1Read Digital I/O Command Command$ = !0RD Reply$ = INPUT$ 1, #1States = ASCReply$ Status = states and maskCommand$ = !0SO + CHR$states Set Digital Output State‘ Set Output High states = states or mask States = states and NOTmaskAppendix a Decimal to Hex to Ascii Conversion Decimal to HEX to Ascii Conversion Table