Commands, Opcodes, Conventions – Sensoray 118 User Manual
Page 13: Low level drivers, Manifest constants, 2 commands, 3 low level drivers

Sensoray Model 118 Smart A/D™ Instruction Manual
11
Programming
5.2 Commands
The Smart A/D™ board is accessed and controlled by
means of a simple, yet powerful, built-in command set.
Commands consist of byte strings that have varying
lengths, due to differences in the amount of data
embedded in each command. In some cases, invocation
of a command will cause the Smart A/D™ to return data
to the host.
5.2.1 Opcodes
Each command consists of at least one byte. The first
byte of a command generally conforms to the format
shown in Table 6.
The opcode, which is always present in the first
command byte, specifies the function to be performed.
The channel number is required only in commands that
address a specific channel.
5.2.2 Conventions
The following conventions are used to specify commands
and command responses:
q
The symbolic name CHAN represents a Smart A/D™
channel number. Valid channel numbers range from 0
through 7.
q
A byte is represented as an expression contained by
parenthesis. For example, (16+CHAN) specifies a byte
that has a value equal to 16 plus a channel number.
q
A byte string is an ordered sequence of bytes separated by
commas. The sequence is ordered from left to right. For
example, the string (95+CHAN),(5),(0) contains
three bytes.
q
A command is a byte string that is handshaked, one byte
at a time, from the host to the Smart A/D™. All bytes of a
command must be handshaked to the Smart A/D™ before
fetching a response or issuing another command.
q
A command response is a byte string that is handshaked,
one byte at a time, from the Smart A/D™ to the host. All
bytes of a pending response must be handshaked from the
Smart A/D™ before issuing another command.
5.3 Low Level Drivers
We recommend that you incorporate procedures in your
application program that will conceal the Smart A/D™
handshake protocol from higher host software layers.
This will serve to simplify your programming efforts as
well as help to reduce software maintenance costs.
This section contains sample low-level driver functions
that implement the required handshake protocol. These
functions are referenced throughout the command
programming examples in Chapter 6.
5.3.1 Manifest Constants
Several constants are required by the sample drivers in
Section 5.3.2 and the programming examples in Chapter
6. Instead of embedding constants in the examples in
which they are referenced, all constants have been
gathered here. By grouping the constants here,
programming examples are easier to read and understand
and unnecessary duplication is prevented.
#define MyBasePort 0xB200 /* Base address for all examples */
// ====== COMMAND OPCODES ======
#define CMD_SET_TYPE 16 /* DECLARE CHANNEL SENSOR */
#define CMD_SET_LIMITS 32 /* SET ALARM LIMITS */
#define CMD_GET_ALARMS 48 /* READ ALARM FLAGS */
#define CMD_GET_AMBIENT 64 /* READ AMBIENT TEMPERATURE */
#define CMD_SET_REJECT50HZ 72 /* START 50HZ REJECTION MODE */
#define CMD_SET_OPENFLAGS 80 /* SET OPEN-DETECT MODE FLAGS */
#define CMD_READ_ALL 88 /* READ ALL SENSOR CHANNELS */
#define CMD_SET_FILT 96 /* SET FILTER TIME CONSTANT */
#define CMD_SET_GAGETARE 112 /* TARE GAGE */
#define CMD_GET_GAGECAL 128 /* GET GAGE CALIBRATION */
#define CMD_SET_GAGECAL 144 /* SET GAGE CALIBRATION */
Table 6: Format of first command byte
D7
D6
D5
D4
D3
D2
D1
D0
OPCODE
CHANNEL