B&B Electronics 232OPSDA Read A/D Command, Command$ = !0RA + CHR$channel, Print #1, Command$

Page 24

Open the serial port.

OPEN “COM1:9600,N,8,1,cd,ds” FOR RANDOM AS #1 PAUSE (.5)

Close the serial port when finished.

CLOSE #1

Read A/D Command

The read A/D channels command returns two bytes of data for each channel read. The two bytes represent the most significant byte (MSB) and least significant byte (LSB) of the reading. The MSB is received first, followed by the LSB. This command requires a data byte. The data byte is used to specify the number of the highest channel to be read. All channels less than this channel will be read as well.

Step 1 - Constructing the command string:

Command$ = “!0RA” + CHR$(channel)

The value of channel is equal to the highest channel to be read.

Step 2 - Transmitting the command string:

Print #1, Command$;

Step 3 - Receiving the data:

MSB$ = INPUT$(1, #1)

LSB$ = INPUT$(1, #1)

Step 4 - Manipulating the data:

reading = (ASC(MSB$) * 256) + ASC(LSB$)

The value of reading is the result of the A/D conversion.

Documentation Number 232OPSDA1397 Manual

23

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

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

Image 24
Contents Electronics Mfg. Co. Inc Designed and Manufactured Ottawa, IllinoisInternet Table of Contents Page 232OPSDA Features IntroductionGeneral Block Diagram Packing ListSoftware Installation 232OPSDA SpecificationsAnalog to Digital Converter Power Supply Digital InputDigital Output CommunicationsConnections Terminal Function Description Block232OPSDA Digital I/O Connections Serial Port Connections232OPSDA Power Supply Connections Commands Syntax Reading A/D Channels Command Reading Digital I/O Command Set Digital Output Command0RD StatesSampling Rate Converter RangeNon-buffered 0 to 5VDC A/D Inputs Buffered 0 to 5V A/D InputsTo 10VDC A/D Input 20mA Current Loop A/D InputGain = Application Program Interface B232OPSDAReadDigital Syntax CB232OPSDASetDigitalOutput ReturnsDeinitComPort Purpose See AlsoLow-Level Communications Port AddressReturns See Also DeinitComPortRead A/D Command Command$ = !0RA + CHR$channelPrint #1, Command$ MSB$ = INPUT$1, #1 LSB$ = INPUT$1, #1Read Digital I/O Command Command$ = !0RD Reply$ = INPUT$ 1, #1States = ASCReply$ Status = states and maskCommand$ = !0SO + CHR$states Set Digital Output State‘ Set Output High states = states or mask States = states and NOTmaskAppendix a Decimal to Hex to Ascii Conversion Decimal to HEX to Ascii Conversion Table