ASCII Protocol
Introduction
The ASCII protocol is a query-response communication protocol in which a host PC uses ASCII characters to send commands to a device and then receives responses back. The ASCII command set is used to configure devices, send data to devices and to read data and status information back from devices.
Command Format
The command string is made up of several different parts. For example, the command #AA00DD can be broken down into:
| Component | Description |
|---|---|
| Delimiter | Single character prefix (#, %, $, @, or ~) |
| AA | Address of the device (hexadecimal 00-FF) |
| Command | The command code |
| Data | Data to send (if required) |
| [CS] | Optional checksum |
| (CR) | Carriage Return (hex 0x0D) |
Delimiter Characters
| Character | ASCII Value | Usage |
|---|---|---|
# | 0x23 | Digital output commands |
% | 0x25 | Configuration commands |
$ | 0x24 | Read commands |
@ | 0x40 | I/O status commands |
~ | 0x7E | Watchdog and name commands |
All commands sent to the device must be in UPPERCASE characters.
Address Field
Since the ASCII protocol was developed for RS485 bus systems containing many devices, each command must include the target device address (00-FF). The default address is 01.
Some broadcast commands use ** instead of an address to target all devices.
Checksum
An optional two character checksum can be included before the carriage return. When enabled, all commands and responses must contain a valid checksum. Default: Disabled.
Assuming checksum is disabled and device address is 01:
Command: @01(CR) - Read digital I/O status
Response: >01FA(CR) - Returns I/O status
Response Format
| Component | Description |
|---|---|
| Delimiter | > (valid), ! (valid with data), or ? (invalid) |
| AA | Address of the responding device |
| Data | Response data (if applicable) |
| [CS] | Checksum (if enabled) |
| (CR) | Carriage Return |
Command Reference
Quick Reference Table
| Command | Response | Description | Devices |
|---|---|---|---|
%AANNTTCCFF | !AA | Set Device Configuration | All |
#** | None | Synchronized Sampling | All |
#AA00DD | > | Set Digital Output (Lower 8) | With Outputs |
#AA0ADD | > | Set Digital Output (Lower 8) | With Outputs |
#AA0BDD | > | Set Digital Output (Upper 8) | With Outputs |
#AA1cDD | > | Set Single Digital Output (Lower 8) | With Outputs |
#AAAcDD | > | Set Single Digital Output (Lower 8) | With Outputs |
#AABcDD | > | Set Single Digital Output (Upper 8) | 8+ Outputs |
#AAN | !AA(Data) | Read Digital Input Counter | With Inputs |
$AA2 | !AANNTTCCFF | Read Device Configuration | All |
$AA4 | !S(Data) | Read Synchronized Data | All |
$AA5 | !AAS | Read Reset Status | All |
$AA6 | !(Data) | Read Digital I/O Status | All |
$AAC | !AA | Clear Latched Digital Input | With Inputs |
$AACN | !AA | Clear Digital Input Counter | With Inputs |
$AAF | !AA(Data) | Read Firmware Version | All |
$AALS | !(Data) | Read Latched Digital Input | With Inputs |
$AAM | !AA(Data) | Read Device Name | All |
$AAS1 | !AA | Restore Factory Defaults | All |
$AARS | None | Reset Device | All |
@AA | >(Data) | Read Digital I/O Status | All |
@AA(Data) | > | Set Digital Output | With Outputs |
~AAO(Name) | !AA | Set Device Name | All |
~** | None | Host OK | All |
~AA0 | !AASS | Read Watchdog Status | All |
~AA1 | !AA | Reset Watchdog Status | All |
~AA2 | !AAVV | Read Watchdog Timeout | All |
~AA3EVV | !AA | Set Watchdog Timeout | All |
~AA4V | !AA(Data) | Read Power On/Safe Value | With Outputs |
~AA5V | !AA | Set Power On/Safe Value | With Outputs |
Detailed Command Reference
%AANNTTCCFF - Set Device Configuration
Sets the device configuration including address, baud rate, and data format.
Syntax:
%AANNTTCCFF[CS](CR)
| Parameter | Description |
|---|---|
AA | Current device address (00-FF) |
NN | New device address (00-FF) |
TT | Type code (40 for DIO module) |
CC | Baud Rate code (see Baud Rate Settings) |
FF | Data format (see Data Format Settings) |
Response:
- Valid:
!AA(CR) - Invalid:
?AA(CR)
Examples:
# Change device address from 01 to 02
Command: %0102400600(CR)
Response: !02(CR)
# Change baud rate to 115200
Command: %0101400A00(CR)
Response: !01(CR)
Address and counter update direction changes take effect immediately. Baud rate and checksum changes take effect after device restart.
#** - Synchronized Sampling
Allows the device to read and store data for later retrieval.
Syntax:
#**[CS](CR)
Response: None
Example:
Command: #**(CR)
# No Response - use $AA4 to retrieve data
#AA00DD - Set Digital Output (Lower 8 Channels)
Sets the digital output value of the lower eight channels.
Syntax:
#AA00DD[CS](CR)
| Parameter | Description |
|---|---|
AA | Device address (00-FF) |
DD | Two digit hexadecimal value. Bit 0 = DOut 0, Bit 1 = DOut 1, etc. |
Response:
- Valid:
>(CR) - Invalid:
?(CR) - Ignored:
!(CR)
Example:
# Set DOut 0-3 ON, DOut 4-7 OFF (0x0F = 0000 1111)
Command: #01000F(CR)
Response: >(CR)
#AA1cDD - Set Single Digital Output
Sets a single digital output channel.
Syntax:
#AA1cDD[CS](CR)
| Parameter | Description |
|---|---|
c | Channel to set (0-7) |
DD | 00 = OFF, 01 = ON |
Example:
# Turn ON DOut 1
Command: #011101(CR)
Response: >(CR)
#AAN - Read Digital Input Counter
Reads the digital input counter value of a specified channel.
Syntax:
#AAN[CS](CR)
| Parameter | Description |
|---|---|
N | Digital input channel (0-F) |
Response:
- 16-bit mode: 5 digit decimal (00000-65535)
- 32-bit mode: 10 digit decimal (0000000000-4294967295)
Example:
# Read counter for channel 3
Command: #013(CR)
Response: !0100274(CR) # Counter value is 274
$AA2 - Read Device Configuration
Reads the current device configuration.
Syntax:
$AA2[CS](CR)
Response: !AATTBBFF(CR)
| Field | Description |
|---|---|
TT | Device Type (40 for DIO) |
BB | Baud Rate code |
FF | Configuration value |
Example:
Command: $012(CR)
Response: !01400600(CR)
$AA6 - Read Digital I/O Status
Reads the digital input and output channel values.
Syntax:
$AA6[CS](CR)
Response: !DDDD00(CR) where DDDD is the I/O status in hexadecimal.
Example:
# All outputs high, all inputs low
Command: $016(CR)
Response: !FF0000(CR)
@AA - Read Digital I/O Status
Reads the status of the digital I/O lines.
Syntax:
@AA[CS](CR)
Response: >DDDD(CR) where DDDD is four hex digits representing I/O status.
Example:
Command: @01(CR)
Response: >0203(CR)
@AA(Data) - Set Digital Output
Sets the digital output channel values.
Syntax:
@AA(Data)[CS](CR)
Example:
# Set alternating outputs (0x55 = 0101 0101)
Command: @0155(CR)
Response: >(CR)
~AAO(Name) - Set Device Name
Sets a new device name (max 10 characters).
Syntax:
~AAO(Name)[CS](CR)
Example:
Command: ~01O588(CR)
Response: !01(CR)
~AA0 - Read Watchdog Status
Reads the watchdog timeout status.
Syntax:
~AA0[CS](CR)
Response: !AASS(CR)
| SS Value | Meaning |
|---|---|
00 | Watchdog timeout is cleared |
04 | Watchdog timeout is set |
~AA3EVV - Set Watchdog Timeout
Enables/disables the watchdog and sets timeout value.
Syntax:
~AA3EVV[CS](CR)
| Parameter | Description |
|---|---|
E | 1 = Enable, 0 = Disable |
VV | Timeout in tenths of a second (01=0.1s, FF=25.5s) |
Example:
# Enable watchdog with 25.5 second timeout
Command: ~0131FF(CR)
Response: !01(CR)
$AAS1 - Restore Factory Defaults
Restores the device settings to factory defaults.
Syntax:
$AAS1[CS](CR)
After responding, the device will reboot and come back online in factory default state. Close all connections after sending this command.
Digital I/O Reset Values:
- Outputs: Reset to OPEN (0)
- Inputs: Depend on NPN/PNP jumper setting and external connections
- NPN (default): Inputs float HIGH (1)
- PNP: Inputs float LOW (0)
$AARS - Reset Device
Resets the device to power on state (reboots).
Syntax:
$AARS[CS](CR)
Response: None
The device can take several seconds to reboot. Close all connections after sending this command.
~AA4V - Read Power On/Safe Value
Reads the power on value or safe value.
Syntax:
~AA4V[CS](CR)
| V | Description |
|---|---|
P | Read power on value |
S | Read safe value |
Example:
# Read power on value
Command: ~014P(CR)
Response: !01F000(CR)
~AA5V - Set Power On/Safe Value
Sets the current output as the power on or safe value.
Syntax:
~AA5V[CS](CR)
| V | Description |
|---|---|
P | Set current output as power on value |
S | Set current output as safe value |
Example:
# Set current output as safe value
Command: ~015S(CR)
Response: !01(CR)