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

Page 23

Advertising
background image

232DRIO-0308 Manual

21

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

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

C/C++ (DEMO232.EXE and DEMO232.CPP)

DEMO232.CPP is a demonstration program for use with B&B

Electronics model 232DRIO module. Much of the work associated
with using COM ports in C/C++ has been made easier by including
the 232DRIO.LIB with this program.
Including

“232DRIO.H” in the pre-processor directive and

compiling your .cpp file as a project along with the 232DRIO.LIB file
will enable you to use the following functions in your program.

Important Note: For Borland C++, the compiler must be set

for large memory model for your program to compile properly.
Access this by the pulldown menu Options/Compiler/Code
Generation/
to change model size and click on ok.

#include”232DRIO.H”

void main ()

{
/* put your program here */
}

Read I/O States Command

states = bbDRIO_ReadIOLines(hComDev, int mode)

Mode is 1 if harsh environment is enabled or 0 if disabled. Returns
–1 if an error occurred.

Example 5.3 – Determining the status of Relay #1

If(states & 0x01)

Æ True if Relay #1 is on

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

Set Output States Command

bbDRIO_SetOutputLines(unsigned short hComDev,
unsigned char states, int mode)
Example 5.4 – Various ways to energized/de-energized Relay #1
1) A relay can be energized by “ORing” states with the
appropriate mask.

states |= 0x01

Æ Will energized Relay #1

2) A relay can be de-energized by “ANDing” with the

complement of the mask. (~mask)

states &= 0xFE

Æ Will de-energized Relay #1

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

appropriate mask.

states ^= 0x01

Æ Will energized Relay #1 if it is de-

energized or vice versa

Advertising