B&B Electronics 232DRIO manual QuickBasic DEMO232.EXE and DEMO232.BAS, Read I/O States Command

Page 22

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

20

232DRIO-0308 Manual

B&B Electronics --

PO Box 1040 -- Ottawa, IL 61350

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

Image 22
Contents Designed and Manufactured Ottawa, Illinois Model 232DRIOElectronics Mfg. Co. Inc InternetPage Table of Contents Table of Contents 232DRIO-0308 Manual Appendix B232DRIO Features Introduction232DRIO Specifications Non-polarized, Optically Isolated Input 232DRIO-0308 ManualCommunications Power SupplyRelay Outputs EnvironmentRelay Outputs blue terminal blocks ConnectionsOpto-isolated Input black terminal blocks Ground232DRIO Terminal Blocks RS232 Connector PinoutSerial Port Connections 232DRIO To DTE Connections Power Supply Connections232DRIO To DCE Connections 01FE #0RComp = not x and &HFF Equivalent Values 232DRIO CommandsFunction Command Response SyntaxBit Assignments for I/O Lines Data BytesRelay #2 Relay #1 Example Set Output Lines Data Byte Relays Binary DecimalInput #1 Relay #2 Relay #1 0R00000000 Read I/O Lines CommandSet Output Lines Command Shown in bold face0S00000011 Argument … shown in bold face0S03 …~… shown in bold faceBoard Layout Opto-isolated Input Switch Input Isolated Mechanical Input Relay Outputs 232DRIO External Circuit Opening a COM Port SymbolDigital I/O Mask Values Closing a COM PortSet Output States Command Using the 232DRIO.LIB with QuickBasicRead I/O States Command QuickBasic DEMO232.EXE and DEMO232.BAS++ DEMO232.EXE and DEMO232.CPP #include232DRIO.H void mainRunning Demonstration Program QuickBasicAppendix a Appendix a 232DRIO-0308 Manual Decimal to HEX to Ascii Conversion TableAppendix B Decimal to Hexadecimal Conversion Appendix B 232DRIO-0308 Manual