Skip to main content

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:

ComponentDescription
DelimiterSingle character prefix (#, %, $, @, or ~)
AAAddress of the device (hexadecimal 00-FF)
CommandThe command code
DataData to send (if required)
[CS]Optional checksum
(CR)Carriage Return (hex 0x0D)

Delimiter Characters

CharacterASCII ValueUsage
#0x23Digital output commands
%0x25Configuration commands
$0x24Read commands
@0x40I/O status commands
~0x7EWatchdog and name commands
important

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.

Example Command

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

ComponentDescription
Delimiter> (valid), ! (valid with data), or ? (invalid)
AAAddress of the responding device
DataResponse data (if applicable)
[CS]Checksum (if enabled)
(CR)Carriage Return

Command Reference

Quick Reference Table

CommandResponseDescriptionDevices
%AANNTTCCFF!AASet Device ConfigurationAll
#**NoneSynchronized SamplingAll
#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 CounterWith Inputs
$AA2!AANNTTCCFFRead Device ConfigurationAll
$AA4!S(Data)Read Synchronized DataAll
$AA5!AASRead Reset StatusAll
$AA6!(Data)Read Digital I/O StatusAll
$AAC!AAClear Latched Digital InputWith Inputs
$AACN!AAClear Digital Input CounterWith Inputs
$AAF!AA(Data)Read Firmware VersionAll
$AALS!(Data)Read Latched Digital InputWith Inputs
$AAM!AA(Data)Read Device NameAll
$AAS1!AARestore Factory DefaultsAll
$AARSNoneReset DeviceAll
@AA>(Data)Read Digital I/O StatusAll
@AA(Data)>Set Digital OutputWith Outputs
~AAO(Name)!AASet Device NameAll
~**NoneHost OKAll
~AA0!AASSRead Watchdog StatusAll
~AA1!AAReset Watchdog StatusAll
~AA2!AAVVRead Watchdog TimeoutAll
~AA3EVV!AASet Watchdog TimeoutAll
~AA4V!AA(Data)Read Power On/Safe ValueWith Outputs
~AA5V!AASet Power On/Safe ValueWith Outputs

Detailed Command Reference

%AANNTTCCFF - Set Device Configuration

Sets the device configuration including address, baud rate, and data format.

Syntax:

%AANNTTCCFF[CS](CR)
ParameterDescription
AACurrent device address (00-FF)
NNNew device address (00-FF)
TTType code (40 for DIO module)
CCBaud Rate code (see Baud Rate Settings)
FFData 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)
note

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)
ParameterDescription
AADevice address (00-FF)
DDTwo 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)
ParameterDescription
cChannel to set (0-7)
DD00 = 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)
ParameterDescription
NDigital 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)

FieldDescription
TTDevice Type (40 for DIO)
BBBaud Rate code
FFConfiguration 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 ValueMeaning
00Watchdog timeout is cleared
04Watchdog timeout is set

~AA3EVV - Set Watchdog Timeout

Enables/disables the watchdog and sets timeout value.

Syntax:

~AA3EVV[CS](CR)
ParameterDescription
E1 = Enable, 0 = Disable
VVTimeout 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)
warning

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

warning

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)
VDescription
PRead power on value
SRead 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)
VDescription
PSet current output as power on value
SSet current output as safe value

Example:

# Set current output as safe value
Command: ~015S(CR)
Response: !01(CR)