Serial Communication ProtocolThis section specifies the protocol employed to communicate Parallel Interface units (PI) with the Master Linux host. This is made by the mean of a 3-wires RS-485 bus using the following communication parameters:
19200-N-8
Each unit has an 4-bits address number ranging from 1 to 14 (values 0 and 15 have special meanings). This address must be unique within the same bus. Connecting more that 14 units is possible by placing them in separate buses.
The communication is made based on serial commands sent by the Linux host, some of which require a serial response from the unit back to the host.
Commands fall into the following three groups:
* Setup commands: Establish unit configuration (stored in unit's FLASH memory).
* Action commands: Cause immediate actions such as activating a GPO.
* Query commands: Obtain information from the unit such as status of GPI inputs.
Communication is always initiated by the host. Updated status from all units is obtained by poling the bus in a cycle with query commands.
Command General Format
All commands are encoded in ASCII. Some data represent Hex number
also encoded in ASCII; for example the hex number 1F would be
transmitted in two bytes: "F" then "1". If the Hex represents a bit-map,
its least significant bit corresponds to GPIO-1.
Multibyte words are transmitted least significant byte first.
The general command format is as following:
STX ADDR CMD [ ARGS ] ETX
where
STX is the ASCII start-of-text control character.
ADDR is the address of the intended unit. This is given
as a one-digit Hex number (1 byte).
CMD is the name of the command (1 byte).
ARGS is a sequence of argument bytes, if applicable.
ETX is the ASCII end-of-text control character.
Action and setup commands do not cause any response from the unit back
to the host. Query commands cause a response from the unit in the following
format:
STX ADDR ALM [ DATA ] ETX
where
STX is the ASCII start-of-text control character.
ADDR is the address of the unit being responding.
ALM is the alarm code in the unit (1 byte). "0" means no alarm
condition.
DATA (if applicable) is a sequence of bytes which format and
content varies depending of the command being responded.
ETX is the ASCII control character end-of-text.
Address "0" is reserved for SETUP commands. The unit Firmware will ignore setup commands
and possibly raise an alarm condition if a setup command is received while the address
configured in the unit is other than zero.
Address "F" means: broadcast. Commands sent with this address will be processed for all
units with disregard of their programmed address.
Broadcasting is restricted to the following commands, resulting in error otherwise:
SET_ALM
SET_RESET
Setup Commands
Units need to be setup to establish the direction of GPIOs (GPI or GPO) and GPO modes (PULSE or LATCH). Setup commands are issued by the gpconfig program running at the Configuration PC to which the unit must be connected via serial port (RS-422), during an initial setup session prior to put the unit in service.
The unit will not accept setup commands if its address is other than zero. Consequently, all setup commands must be issued with ADDR = 0h, causing an alarm condition otherwise.
The configuration is stored in unit FLASH. If no setup command is ever received, default values are set depending of the unit model. Some units can be designed to remain in alarm condition until the CONFIG GPIOS command is received; others can be designed to auto-discover GPIO directions.
GPO modes are the following:
PULSE: When fired, activate for a short period of time, then deactivate automatically.
LATCH: Once activated or deactivated, remain in that estate until another command estate to change.
Setup commands are the following:
SETUP_GPIOS
Establishes GPIO directions (GPI or GPO).
CMD: 'c'
DATA:
Data is a Hex bit-map of GPIO directions (1 for GPI, 0 for GPO). The number of bytes depends on unit size; for example, it will be 4 bytes for GP-116 units because those have 16 GPIOs.
SETUP_MODES
Setup GPO modes (PULSE or LATCH).
CMD: 'm'
DATA:
Data is a Hex bit-map of GPO modes (1 for PULSE, 0 for LATCH). Bit positions represent GPIO numbers, not necessarily GPOs. Bits corresponding to GPIs will be ignored by the unit's firmware.
SET_DUR_GPO
Set activation time for given GPO in mode PULSE.
CMD: 'd'
DATA: GPO DUR
where GPO is the GPIO number in Hex (2 bytes) and DUR is the pulse duration in Hex representing miliseconds in increments of 50 (2 bytes); for example DUR="05" means: 250ms.
If DUR is zero, default PULSE duraction time is assumed.
SET_DUR_GPO_DFLT
Overwrite firmware default activation time.
Pulse duration set by this command applies to all GPOs configured in pulse mode, overwriting the default duration established by the unit firmware.
CMD: 'D'
DATA: DUR
where DUR is the pulse duration in Hex representing miliseconds in increments of 50ms (2 bytes).
If DUR is zero, the command is ignored.
Action Commands
SET_ADDR
Establishes the unit address.
In some units, address is set by DIP switches or jumpers, in which case this command takes no effect. Some other units require the address to be set with this command.
CMD: 'A'
DATA: address (Hex)
SET_ALM
Establishes an alarm condition (code) in the unit forcing the ALARM LED to illuminate.
CMD: '!'
DATA: alarm code (1 byte)
Code zero means no alarm condition, so asserting this command with argument zero effectively clears the alarm condition turning the ALM LED off. This can also be done using address Fh (broadcast) to clear all units at once.
Broadcasting an alarm code other than zero is illegal resulting in error.
SET_GPO_ON
Activates given GPO.
CMD: 'G'
DATA: GPO number in Hex (2 bytes)
SET_GPO_OFF
Deactivates given GPO.
CMD: 'g'
DATA: GPO number in Hex (2 bytes)
SET_RESET
Deactivates all GPOs in the unit and clears alarm condition.
CMD: 'r'
DATA: none
Query Commands
GET_STATUS
CMD: 't'
DATA: none
RESPONSE:
The unit responds with a bit-map of GPIO states (1 if active, 0 if not active). The number of bytes depends of the unit model; for example, a unit with 16 GPIOs will response with four bytes of data: each one being a Hex digit (encoded in ASCII) equivalent to 4 bits.
Bit positions in the bit-map represent GPIO numbers (either GPIs or GPOs, depending of unit configuration). The least significant bit of the first byte corresponds to GPIO-1 and so on.
GET_SETUP
Reads the current setup as stored in the FLASH.
CMD: 's'
DATA: none
RESPONSE:
The unit responds with the following sequence of bytes:
* Unit address --> 1 bytes
* Unit GPIOs count --> 2 bytes.
* Bit-map of GPIOs directions (1 for input, 0 for output) --> 1 byte for every 4 bits.
* Bit-map of GPO modes (1 for PULSE, 0 for LATCH). Bits for GPIO numbers configured as
input are set to 0. --> 1 byte (Hex) for every 4 bits.
* Default PULSE duration in 50ms increments --> 2 bytes.
* PULSE duration in 50ms increments of each GPO configured as PULSE with no default
duration.
--> For each: 2 bytes GPO number, 2 bytes duration.
GET_ADDR
This is a broadcast command (ADDR="F"). Units respond at random intervals to avoid collision.
CMD: 'a'
DATA: none
RESPONSE:
No data is present in the response frame.
This command can be used for auto-discovered purposes.
GET_VERSION
Get Firmware version.
CMD: 'v'
DATA: none
RESPONSE:
Response from the unit contains three Hex numbers (6 bytes) representing the mayor, minor and built number respectively (2 hex digits each) of the Firmware version. First byte (least significant) is the built number.
GET_PROTO
Get protocol version supported by unit Firmware. Protocol version consists of a single decimal digit.
CMD: 'V'
DATA: none
RESPONSE:
Response from the unit contains a two digits Hex number (2 bytes) representing serial protocol version.
Alarm Codes
Alarm code is a Hex digit (1 byte) generated by the unit Firmware to characterize the alarm condition.
Alarm codes are the following:
0 ALM_NONE No alarm condition exists
1 ALM_INIT Firmware is initializing
2 ALM_NOSETUP Get-status command received while unit is not setup
3 ALM_NOETX No ETX char received before timeout (broken frame)
4 ALM_NOTAGPO Attempt to fire or setup a GPI instead of a GPO
15 ALM_PING Used for diagnostic purposes
|