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
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
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
1)A relay can be energized by “ORing” states with the appropriate mask.
states = 0x01 Æ Will energized Relay #1
2)A relay can be
states &= 0xFE Æ Will
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
21 |
B&B Electronics
PH (815)