B&B Electronics RS-232 Digital Relay I/O 232DRIO User Manual

Page 22

Advertising
background image

20 232DRIO-0308

Manual

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

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

QuickBasic (DEMO232.EXE and DEMO232.BAS)

This section shows steps and examples of programming the

232DRIO in QuickBasic. If you are programming in another
language, this section can be helpful as a guideline for programming
the 232DRIO.

Using the 232DRIO.LIB with QuickBasic:

Using this library will make it easier to program the 232DRIO

module and allows greater flexibility in choosing serial ports. At the
DOS prompt, start QuickBasic with the 232DRIO Quick Library by
typing:

QB program.bas /L 232DRIO.QLB

This allows you to call the 232DRIO functions from the QuickBasic
editor.

‘$INCLUDE: ‘232DRIO.BI’

Æ Include the function definitions

mem = SETMEM(-2000)

Æ Tell QB to set aside memory for the

232DRIO library to use

Read I/O States Command

states = bbDRIOReadIOLines(hComDev, mode)

When the line is executed, states will contain a byte that can be
read by “ANDing” states with the appropriate mask.

Example 5.1 - Determining the status of Relay #1

If (states AND 0x01)

Æ True if relay 1 is on

If (states & 0x01)


Set Output States Command

status = bbDRIOSetOutputLines(unsigned short hComDev,
unsigned char states, int mode)

Æ Returns a negative number

on error

Example 5.2 – Various ways to energized/de-energized Relay #1
1) A relay can be energized by “ORing” states with the
appropriate mask.

states = states OR &H01

Æ Will energized Relay #1

2) A relay can be de-energized by “ANDing” with the
complement of the mask. (~mask)

states = states AND &HFE

Æ Will de-energized Relay #1

3) A relay can be switched by “Exclusive ORing” states with the
appropriate mask.

states = states XOR &H01

Æ Will energized Relay #1 if it is

de-energized or vice versa

Advertising