B&B Electronics RS-485 manual Read A/D Command, Command$ = ! + CHR$addr + RA + CHR$channel

Page 26

Chapter 5 - Software

This chapter covers programming techniques such as constructing a command string, receiving data and manipulating data. The various steps and examples are shown in QuickBasic. If you are programming in another language, these sections can be used as a guideline for programming the 485SDA10.

Read A/D Command

The Read A/D channels command returns two bytes 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.

The steps to reading an A/D command are given below:

1.Constructing the command string:

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

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

2.Transmitting the command string:

Print #1, Command$;

3.Receiving the data:

MSB$ = INPUT$(1, #1) LSB$ = INPUT$(1, #1)

4.Manipulating the data:

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

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

5.Repeat Steps 3 & 4 until each channel has been completed.

Example 5.1 - Read A/D channels 1 and 0 of the module with an address of 5.

channel = 1 addr = 5

Command$ = “!” + CHR$(addr) + “RA” + CHR$(channel) Print #1, Command$;

22

485SDA103798 Manual

B&B Electronics -- 707 Dayton Rd. -- PO Box 1040 -- Ottawa, IL 61350

PH (815) 433-5100 -- FAX (815) 434-7094

Image 26 Contents
Internet Electronics Mfg. Co. IncDesigned and Manufactured Ottawa, Illinois Table of Contents Software Tables485SDA103798 Manual Table of Contents Iii 485SDA10 Features 485SDA10 UnitSoftware Installation Packing ListWindows UninstallGetting Started Windows 9x and Windows NTA/D with Variable Resistor 485SDA10 Specifications Inputs #0-10 Ref Input +Typical Connections Ref InputAnalog Ground Digital Inputs #0-2 Digital I/O Connections485SDA10 I/O Port Pinout Digital Outputs #0-2Digital Ground Typical Digital I/O ConnectionsSerial Port Connections RS-485 Terminal Block ConnectionsPower Supply Connections Typical RS-485 2-wire ConnectionCommands 485SDA10 CommandsEquivalent Values Reading A/D Channels CommandSyntax Read A/D Response AddrRA#Ch#MSBch#LSBch#-1MSB...ch0MSBch0LSB States Reading Digital I/O CommandAddrRD Read Digital I/O Response for OutputsAddrSOstates Set Digital Output CommandSet Module Address Command Set Digital Output Data Byte ValuesRead Module Configuration Command Set Power-up States CommandSet Turn-around Delay Command Addressstatesdelay Reference Inputs Sampling RateInput Range Data Range Converting DataPage Print #1, Command$ Read A/D CommandCommand$ = ! + CHR$addr + RA + CHR$channel MSB$ = INPUT$1, #1 LSB$ = INPUT$1, #1Reply$ = INPUT$ 1, #1 Read Digital I/O CommandCommand$ = ! + CHR$addr + RD Set Digital Output States Digital I/O Mask ValuesSet Module Address Command$ = !0SO + CHR$statesCommand$ = ! + CHR$addr + SO + CHR$newaddr Addr =States = states and NOTmask Addr = 5 states =Set Turn-around Delay Command$ = ! + CHR$addr + SC + CHR$delayRead Module Configuration Comp = not x and &HFF #addrRA00FF00FF01FE Table A-1 Extended Commands Appendix B Analog Input Impedance Simplified Analog Input Analysis 1 2 LSB = R s + 1k Ω × 60pF × ln2048485SDA103798 Manual Appendix B Appendix C Decimal to HEX to Ascii Table Table C-1 Decimal to HEX to Ascii TableClass a Equipment
Related manuals
Manual 39 pages 36.61 Kb Manual 46 pages 1.37 Kb