B&B Electronics manual ++ DEMO232.EXE and DEMO232.CPP, #include232DRIO.H void main

Page 23

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

232DRIO-0308 Manual

21

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

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

Image 23
Contents Internet Model 232DRIOElectronics Mfg. Co. Inc Designed and Manufactured Ottawa, IllinoisPage Table of Contents Appendix B Table of Contents 232DRIO-0308 ManualIntroduction 232DRIO FeaturesNon-polarized, Optically Isolated Input 232DRIO-0308 Manual 232DRIO SpecificationsEnvironment Power SupplyRelay Outputs CommunicationsGround ConnectionsOpto-isolated Input black terminal blocks Relay Outputs blue terminal blocksSerial Port Connections RS232 Connector Pinout232DRIO Terminal Blocks 232DRIO To DCE Connections Power Supply Connections232DRIO To DTE Connections Comp = not x and &HFF #0R01FE Syntax 232DRIO CommandsFunction Command Response Equivalent ValuesData Bytes Bit Assignments for I/O LinesInput #1 Relay #2 Relay #1 Example Set Output Lines Data Byte Relays Binary DecimalRelay #2 Relay #1 Shown in bold face Read I/O Lines CommandSet Output Lines Command 0R00000000…~… shown in bold face Argument … shown in bold face0S03 0S00000011Board Layout Opto-isolated Input Switch Input Isolated Mechanical Input Relay Outputs 232DRIO External Circuit Closing a COM Port SymbolDigital I/O Mask Values Opening a COM PortQuickBasic DEMO232.EXE and DEMO232.BAS Using the 232DRIO.LIB with QuickBasicRead I/O States Command Set Output States Command#include232DRIO.H void main ++ DEMO232.EXE and DEMO232.CPPQuickBasic Running Demonstration ProgramAppendix a Decimal to HEX to Ascii Conversion Table Appendix a 232DRIO-0308 ManualAppendix B Appendix B 232DRIO-0308 Manual Decimal to Hexadecimal Conversion