NAV
Command Line Ruby Python PHP Perl Java NodeJS Javascript

Introduction

Welcome to the EKM METERING API!

We at EKM see easy access to your data, and the scalable systems behind the EKM Push, as crucial to moving our products into the future. To that end, we do what is unheard of in our industry, we give you your data for FREE.

The EKM API is organized around Representational State Transfer, or REST. You can use our Application Programming Interface, or API, to access EKM API endpoints, which can get you information on various EKM Push meter/ioStack data and utilize it in your own application, database, billing system, or building automation system.

We have language bindings in Shell (cURL), Ruby, Python, PHP, Perl, Java, Javascript and Nodejs! You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.

Our API is designed to have predictable, resource-oriented URLs and to use HTTP response codes to indicate API errors. We use built-in HTTP features, like HTTP authentication and HTTP verbs, which can be understood by off-the-shelf HTTP clients, and we support cross-origin resource sharing to allow you to interact securely with our API from a client-side web application (though you should remember that you should never expose your secret EKM Push API key in any public website’s client-side code). JSON will be returned in all responses from the API, including errors (though if you’re using API bindings, we will convert the response to the appropriate language-specific object).

To authorize, make sure to use your personal EKM Push account key.

The examples in this API documentation use the demo key of MTAxMDoyMDIw. Please make sure you remove this key and place your personal key in the https address if you are trying to access the meters in your account.

With shell, you can just pass the correct address with each request
curl -s "URL Here"
Authorization: "EKM Push Key"
# Ruby Version: 3.1.2

# Load required modules
require 'net/http'
require 'json'
require 'uri'

# Call the call_api method to create a usable
# object named api_object from the API request URI
# Put the API request URI in the call

def call_api(api_path)
  uri = URI.parse("URL Here#{api_path}")
  response = Net::HTTP.get_response(uri)
  puts response.uri
  JSON.parse(response.body)
end

# Call the call_api method to create a usable
# object named api_object from the API request URI
# Put the API request URI in the call
# URI only NOT URL - Do not include for example https://summary.ekmpush.com
api_object = call_api('URI Here')

# This just displays the object but you can use what ever
# code you would like to work with the object here
require 'pp'
pp api_object

'''
Python version: 3.9.12
'''

# Required Python Modules
import urllib.request
import urllib.error
import urllib.parse
import json
import pprint

# This function accesses the api_request URL and converts
# the contents to a usable Python object and returns it
def call_api ( api_request ):
    '''
    Make http request
    '''
    response = urllib.request.urlopen(api_request)
    response = response.read()
    json_object = json.loads(response.decode())
    return json_object

# Call the call_api function to create a usable
# object named api_object from the API request URL.
# Put the API request URL in the call
api_object = call_api("URL Here")

# This just displays the object but you can use what ever
# code you would like to work with the object here
pprint.pprint(api_object)

<?php
// PHP 8.0.17 (cli)

// Call the callApi function to create a usable
// object named $apiObject from the API request URL.
// Put the API request URL in the call
$apiObject=callApi('URL Here');

// This just displays the object but you can use what ever
// code you would like to work with the object here
var_dump($apiObject);

// This function accesses the apiRequest URL and converts
// the contents to a usable PHP object and returns it
function callApi ($apiRequest='') {

        $json=@file_get_contents($apiRequest);
        $jsonObject=json_decode($json);
        return ($jsonObject);

}
?>    
#!/usr/bin/perl
# Perl version: v5.34
# CPAN.pm version 2.2
# Perl Modules Version:
# JSON: 4.05
# LWP::Protocol::https: 6.10
# LWP::Simple: 6.62
#
# OS Prerequisites
# UBUNTU
# apt install cpanminus
#
# Install Perl Modules
#       cpan LWP::Simple
#       cpan LWP::Protocol::https
#       cpan JSON

# Required Perl Modules
use strict;
use warnings;
use LWP::Simple;
use JSON;
use Data::Dumper;

# This function accesses the api_request URL and converts
# the contents to a usable Perl object and returns it
sub call_api {
    my $api_request = shift;
    my $json_text   = get($api_request);
    my $json_object = JSON->new->utf8->decode($json_text);
    return $json_object;
}

# Call the call_api function to create a usable
# object named api_object from the API request URL.
# Put the API request URL in the call
my $api_object = call_api('URL Here');

# This just displays the object but you can use what ever
# code you would like to work with the object here
print Dumper($api_object);    ## no critic (InputOutput::RequireCheckedSyscalls)

/*
 openjdk version "17.0.2" 2022-01-18

 Download the correct org.json jar version for your
 needs from: https://mvnrepository.com/artifact/org.json/json

 This example uses version 20220320 accessible here:
 https://repo1.maven.org/maven2/org/json/json/20220320/json-20220320.jar

 Instructions to run this program

 1. Put this code in a file named EKM.java
 2. Copy the downloaded org.json jar and EKM.java to the same directory
 3. Compile
  javac -cp .:./json-20220320.jar ./EKM.java
 4. Run
  java -cp .:./json-20220320.jar EKM
*/

//Import required classes
import java.net.*;
import java.io.*;
import org.json.*;

@java.lang.SuppressWarnings({"java:S106", "java:S112", "java:S125"})

public class EKM {
    public static JSONObject callApi(String apiRequest) throws Exception {

        // This code accesses the apiRequest URL and converts
        // the contents to a usable JSON object

        URL url = new URL(apiRequest);
        URLConnection connection = url.openConnection();
        BufferedReader in = new BufferedReader(
                                               new InputStreamReader(
                                                                     connection.getInputStream()));

        StringBuilder response = new StringBuilder();
        String inputLine;

        while ((inputLine = in.readLine()) != null)
            response.append(inputLine);

        in.close();

        return new JSONObject(response.toString());
    }

    public static void main(String[] args) throws Exception {
        /*
         Call callApi to create a usable
         object named apiObject from the API request URL.
         Put the API request URL in the call
         */
        JSONObject apiObject = EKM.callApi("URL Here");

        /*
         You can access any part of the apiObject using code like this:
         JSONArray  readData = apiObject.getJSONObject("readMeter").getJSONArray("ReadSet").
         getJSONObject(0).getJSONArray("ReadData");
        */

        // This just outputs the whole apiObject
        System.out.println(apiObject.toString(4));
    }
}
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">

// The example function is called from the 
// body tag when the page loads
function example(){

// Call the callApi function to create a usable
// object named apiObject from the API request URL.
// Put the API request URL in the call
callApi('URL Here',function(apiObject){

       // This just displays the object in the result div
       // you can use what ever code you would like to work 
       // with the object here
       document.getElementById("result").innerHTML = "<pre>"+JSON.stringify(apiObject, null, 4)+"</pre>";
       });

};

// This code accesses the apiRequest URL and converts
// the contents to a usable JSON object named apiObject
function callApi(apiRequest,callback) {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
      if (xhttp.readyState == 4 && xhttp.status == 200) {
        var jsonObject = JSON.parse(xhttp.responseText);
        callback(jsonObject);
      }
    };
    xhttp.open("GET", apiRequest, true);
    xhttp.send();
}
</script>

</head>
  <body onload="example()">
    <div id="result"/>
  </body>
</html>
/*
* Requirements
* NodeJS: v16.14.2
* Axios:  0.27.2
*/

// Load modules
const axios = require('axios');

const apiClient = axios.create({
  baseURL: 'URL Here',
  timeout: 1000 * 15,
})

// This code accesses the apiRequest query and
// logs the response data or the error
;(async () => {
  try {
    const res = await apiClient.get('URI Here');
    const apiResData = res.data;

    console.log(JSON.stringify(apiResData, null, 2));
  } catch (error) {
    console.error(error.message);
  }
})();

Make sure to replace the sample key: MTAxMDoyMDIw, with your API key in the https address.

Authentication

EKM uses API keys to allow access to the API. You authenticate to the EKM API by providing one of your unique API keys in each request. Each Push account holder is provided with an EKM Push User Key, which provides access to all meters in their account. This key carries lots of privileges so we encourage you to keep it secret. In addition to this master key, additional keys are also provided to give access to each meter/ioStack individually, and keys can be created to provide access to sub groups of meters/ioStacks upon request. These secondary keys can be used to share single meters/ioStacks, or a subset of meters/ioStacks, without sharing access to all meters/ioStacks in an account. For example, if you are a landlord with multiple rentals and meters/ioStacks, you could share specific meter/ioStack keys with each of your tenants, so that they could have access to only the data that pertains to their usage.

Authentication to the API occurs via HTTP Basic Auth. Provide your API key as the basic authorized username. You do not need to provide a password. You must authenticate for all requests.

The EKM Push API expects the API key to be included in all requests to the server. The key is included in the URL in the following way:

Authorization: key=MTAxMDoyMDIw

Realtime API

Click here to go to Realtime Documentation

If you are developing your own app, cloud-to-cloud solution, billing system, or other SAS solution, our Real-Time API allows you to easily access your EKM Push data in any format that you need. Below you will find descriptions regarding how to access the data, and about the filters you can apply so the data comes to you in a format that is easily digested and inserted into your software solution.

The Real-Time API returns recent reads that are still available in storage for each of your meters, ioStack devices, and gateways. How far back that goes depends on how many one-hour shards still hold data for the device (up to 24 shards)—not a fixed “last 24 hours” or a 1,000-read cap. If your device is being read once per minute, new data is available once per minute, per device. Whether you have one device or 10,000 devices, this is the easiest and most scalable way to access your data.

The EKM Dash, EKM Widget, encompass.io, wattvision.com, pvoutput.org, the other solutions in our Push App Store, as well as other customers that have their own custom solutions, all use this API to access their data. We use the same API as you and do not give ourselves any special permissions, we see what you see, which forces us to make the API as great as possible for everyone. We have even given you code examples that can be copy and pasted into your own software language to make the data access that much easier.

Use the API definition, metered values definition, code snippet suggestion, and guide to get you on your way to developing your next killer app. If you create something great, let us know; we’re open to adding all useful apps into the Push App Store.

We also have a Realtime API Request Builder Tool found here:

Realtime API Builder

Account API

Click here to go to Account API Documentation

This API provides information for accounts and devices owned by the account.

Get information for the specified target, which can be account, gateway, meter or ioStack.

You could make API request with the EKM Push Key that is your own Authorization Key that you received for your Push Account, or instead the EKM Push Key you could use Gateway Key for more restricted access. Be aware that if you use the Gateway Key, you will only receive information regards to that gateway.

Gateway Settings API

Click here to go to Gateway Settings API Documentation

This API is used to send commands and settings to devices connected to a Push3 gateway as well as the gateway device itself.

Trigger API

Click here to go to Trigger API Documentation

A REST API to lookup/create/update/delete triggers.

EKM Push3 gateway triggers are among the most powerful tools that EKM offers. You can automate how and when the EKM Push system reacts to metered values. For example, you can have the Push gateway send you an email, send a webhook to your server, or control a relay to turn on/off a switch or close a valve based on the metered data. Push3 gateways can trigger specific actions based on conditions you set up. These triggers reside on the Push3 gateways, allowing them to function even without an internet connection. Triggers can control the relays on v.4 Omnimeters to turn devices on or off, send webhooks to alert your software system, or email you notifications. You can set up new triggers in the Account Portal or via web APIs.

Please note: v.3 Omnimeters do not have controllable relays, so relay triggers will not work, but email triggers will.

Summary V2 API

Click here to go to Summary V2 Documentation

Summary V2 API is a new set of summary features, such as First/Last to get the first and/or last reported date for the given meter(s)/ioStack(s), GStat for getting the status of one or more gateways, IOStack for getting information from new sensors, and more.

MQTT Messaging

Click here to go to MQTT Documentation

MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol designed for low-bandwidth, high-latency, or unreliable networks, often used in Internet of Things (IoT) applications. It follows a publish-subscribe model, where devices (clients) can publish messages to topics or subscribe to topics to receive messages.

MQTT will only work with Push3 Gateways. It is more efficient than making hundreds of API calls, allowing continuous realtime or summary data streaming (you can stream 24/7). However, it lacks message history, meaning that if you need past data, you will have to make an API request to retrieve realtime or summary information as far back as necessary, and then resume streaming via MQTT. If the connection is lost, you will need to request realtime or summary data again to fill in any gaps before continuing with the MQTT stream. This combination of API and MQTT helps ensure a smooth data flow while compensating for potential disruptions.

Meter RS-485 Communications

Click here to go to Meter RS-485 Documentation

This section is for developers, or individuals, that want to communicate with their EKM Meters directly using their own software or embedded solution.

The code examples found in this section are in the simplest possible method to get you started. You are welcome to make them more robust.

First we start you out just connecting to the meter. You will find there is a very simple command line process to help you get started.

After that we cover the CRC method required for most communication to the meter.

Then we put it all together, in a simple test script that will show reads, and also open and close the relays.

Last we cover how to convert the 255 character strings that the meter responds with to a usable array containing field names and their values. It is our hope that after you go through these steps you will have all the information you need, to build whatever tools you like to access the meter.

Our meters use an IEC 62056-21 communication standard that has been optimized for our own needs. We are more than happy to share this with you. With this you can write your own software or embedded solution to access your meter data.

IEC 62056 is a set of standards for Electricity metering data exchange by International Electrotechnical Commission.

To learn more about the IEC 62056 standard click the button below to visit the WikiPedia website.

Additional PDF docs are available:

v.3 Meter Settings Protocol

v.3 Meter Parsing

v.4/v.5 Meter Settings Protocol

v.4/v.5 Meter Parsing

v.4/v.5 Meter Alternate Modbus Protocol

ioStack RS-485 Communications

This section is for developers, or individuals, that want to communicate with their EKM ioStack directly using their own software or embedded solution.

The code examples found in this section are in the simplest possible method to get you started. You are welcome to make them more robust.

First we start you out just connecting to the ioStack. You will find there is a very simple command line process to help you get started.

After that we cover the CRC method required for every request to the ioStack.

Then we put it all together, in a simple test script that sends the Echo and Get Status requests and checks the responses.

Last we cover how to convert the binary response body that the ioStack answers with to usable values. It is our hope that after you go through these steps you will have all the information you need, to build whatever tools you like to access the ioStack.

The ioStack does not use the meter protocol. Its messages are binary, not ASCII. Every request is a short binary frame that ends with a CRC-16, and every response has the same shape.

What you can do over RS-485:

  • Read the four pulse inputs (counts, states, rates) and the four analog inputs.
  • Set and read the four digital outputs, including timed waveforms.
  • Read the 1-wire temperature sensors and the I2C inputs.
  • Set watch levels and counts, and read the watch state.
  • Read and set the real-time clock and the names.

Each ioStack answers to its own serial number. You can also send a request to serial number 999999999999. Every ioStack on the bus accepts that address, so use it only when a single device is on the bus (see Get Status).

The examples use serial number 123456789012. Replace it with your device’s serial number. Always use the factory password 00000000.

Serial Settings

Serial settings for the ioStack: 8 data bits, No Parity, 1 Stop Bit, No Flow Control, 9600 baud rate.

Note that this differs from the meter. Meters use 7 data bits with even parity, so do not reuse meter settings for an ioStack.

The baud rate can be changed with the Set UART command. The supported rates are:

Index Baud rate
0 9600 (default)
1 19200
2 38400
3 57600
4 115200
5 230400

Every byte is binary. Do not convert the values to ASCII.

Connecting to ioStack

# The serial device in this example is /dev/ttyUSB0

# First set up your serial port
stty -F /dev/ttyUSB0 cs8 -parenb -cstopb -ixon raw -echo 9600

# Now we start hexdump to monitor the serial port
hexdump -v -e '1/1 "%02x "' /dev/ttyUSB0 &

# In this example we send a Get Status request (opcode 0x02) to serial number 123456789012
# The serial number in hex is 1C BE 99 1A 14. The last 2 bytes are the CRC
printf '\x43\x1c\xbe\x99\x1a\x14\x02\x00\x98\x91' > /dev/ttyUSB0

# Wait a moment for the response, then kill hexdump to stop monitoring the serial port
sleep 1
killall -9 hexdump
# Ruby Version: 2.7.0
# Serialport version: 1.3.2
# Requires the SerialPort gem
# (http://rubygems.org/gems/serialport)
# gem install serialport

require 'serialport'

# Params for serial port
# Change /dev/ttyUSB0 to match your system
port_str = '/dev/ttyUSB0'
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE

# Open connection to serial port
port = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
port.flow_control = SerialPort::NONE

# Wait up to 5 seconds (in milliseconds) for each read
port.read_timeout = 5000

# ioStack serial number 123456789012 is 1C BE 99 1A 14 in 5 bytes (big-endian)
# Request: 43 (start), serial number, 02 (Get Status), 00 (no body), then the 2 CRC bytes (low byte first)
request = [0x43, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x02, 0x00, 0x98, 0x91].pack('C*')

# Send the request to the ioStack
port.write(request)

# Get the response header: 8 bytes. Byte 7 holds the length of the body
header = port.read(8)
abort('Connection timed out!') if header.nil? || header.bytesize < 8

# Get the body and the 2 CRC bytes
response = header + port.read(header.getbyte(7) + 2)

# Show response as HEX
puts response.unpack('C*').map { |b| format('%02x', b) }.join(' ')

# Close connection to serial port
port.close
'''
Python version: 3.8.10
Modules:
Pyserial version: 3.4
Requires pyserial module:
    pip3 install pyserial
'''

import serial

# Open connection to serial port
# Change /dev/ttyUSB0 to match your system
port = serial.Serial(
    port='/dev/ttyUSB0',
    baudrate=9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    xonxoff=0,
    timeout=5  # seconds to wait for a response
)

# ioStack serial number 123456789012 is 1C BE 99 1A 14 in 5 bytes (big-endian)
# Request: 43 (start), serial number, 02 (Get Status), 00 (no body), then the 2 CRC bytes (low byte first)
request = bytes([0x43, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x02, 0x00, 0x98, 0x91])

# Send the request to the ioStack
port.write(request)

# Get the response header: 8 bytes. Byte 7 holds the length of the body
header = port.read(8)
if len(header) < 8:
    raise SystemExit('Connection timed out!')

# Get the body and the 2 CRC bytes
rest = port.read(header[7] + 2)
response = header + rest

# Show response as HEX
print(' '.join('{0:02x}'.format(b) for b in response))

# Close connection to serial port
port.close()
<?php
/*
* Requirements:
* PHP: 8.1.5
* DIO: 0.2.1
*
* Install php8.1-dev on ubuntu to compile DIO module.
* apt install php8.1-dev
* Compile DIO module from source:
* Download the latest tarball from: https://pecl.php.net/package/dio
* Uncompress: tar xfz dio-0.2.1.tgz
* cd dio-0.2.1/
* phpize
* ./configure
* make
* sudo make install
* You will see a path like: /usr/lib/php/20210902/
* Edit your php.ini
* vi /etc/php/8.1/cli/php.ini
* In the extension section add:
* extension=/usr/lib/php/20210902/dio.so
* Now you can run your php script.
* Ex: php connect.php
*/

// Reads exactly $n bytes from the port. Gives up after 5 seconds.
function read_bytes($port, int $n, int $timeout = 5): string {
    $data = '';
    $end = time() + $timeout;
    while (strlen($data) < $n && time() < $end) {
        $chunk = dio_read($port, $n - strlen($data));
        if ($chunk === false || $chunk === null || $chunk === '') {
            usleep(10000);
        } else {
            $data .= $chunk;
        }
    }
    if (strlen($data) < $n) {
        throw new RuntimeException('Connection timed out!');
    }
    return $data;
}

// Open connection to serial port
// Change /dev/ttyUSB0 to match your system
$port = dio_open('/dev/ttyUSB0', O_RDWR | O_NONBLOCK);

// Configure the port
dio_tcsetattr($port, array(
   'baud'         => 9600,
   'bits'         => 8,
   'stop'         => 1,
   'parity'       => 0,
   'flow_control' => 0,
   'is_canonical' => 0
));

// ioStack serial number 123456789012 is 1C BE 99 1A 14 in 5 bytes (big-endian)
// Request: 43 (start), serial number, 02 (Get Status), 00 (no body), then the 2 CRC bytes (low byte first)
$request = pack('C*', 0x43, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x02, 0x00, 0x98, 0x91);

// Send the request to the ioStack
dio_write($port, $request);

// Get the response header: 8 bytes. Byte 7 holds the length of the body
$header = read_bytes($port, 8);

// Get the body and the 2 CRC bytes
$response = $header . read_bytes($port, ord($header[7]) + 2);

// Show response as HEX
echo implode(' ', str_split(bin2hex($response), 2)) . "\n";

// Close connection to serial port
dio_close($port);

?>
#!/usr/bin/perl
# Perl version: v5.30.0
# CPAN.pm version v2.34
#
# Requires the Device::SerialPort module
# Device::SerialPort: 1.04
#
# Install Perl Modules
#       cpan Device::SerialPort

use strict;
use warnings;
use Device::SerialPort;

# Reads exactly $n bytes from the port. Gives up after 5 seconds.
sub read_bytes {
    my ($port, $n) = @_;
    my $timeout = 5;
    my $data = '';
    while (length($data) < $n && $timeout > 0) {
        my ($count, $read) = $port->read($n - length($data));
        if ($count > 0) {
            $data .= $read;
        }
        else {
            $timeout--;
        }
    }
    die "Connection timed out!\n" if length($data) < $n;
    return $data;
}

# Open connection to serial port
# Change /dev/ttyUSB0 to match your system
my $port = Device::SerialPort->new('/dev/ttyUSB0') or die "Cannot open /dev/ttyUSB0\n";

# Configure the port
$port->baudrate(9600);
$port->parity('none');
$port->databits(8);
$port->stopbits(1);
$port->handshake('none');
$port->write_settings;

# don't wait for each character
$port->read_char_time(0);

# wait for 1 second per unfulfilled read
$port->read_const_time(1000);

# ioStack serial number 123456789012 is 1C BE 99 1A 14 in 5 bytes (big-endian)
# Request: 43 (start), serial number, 02 (Get Status), 00 (no body), then the 2 CRC bytes (low byte first)
my $request = pack('C*', 0x43, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x02, 0x00, 0x98, 0x91);

# Send the request to the ioStack
$port->write($request);

# Get the response header: 8 bytes. Byte 7 holds the length of the body
my $header = read_bytes($port, 8);

# Get the body and the 2 CRC bytes
my $response = $header . read_bytes($port, ord(substr($header, 7, 1)) + 2);

# Show response as HEX
print join(' ', map { sprintf '%02x', ord } split //, $response), "\n";

# Close connection to serial port
$port->close;
undef $port;
/*
 openjdk version "17.0.2" 2022-01-18
 Download the jssc.jar (java-simple-serial-connector)
 from: https://code.google.com/archive/p/java-simple-serial-connector/
 Version: jSSC-2.8.0

 Instructions to run this program

 1. Put this code in a file named Connect.java
 2. Copy the downloaded jssc.jar and Connect.java to the same directory
 3. Compile
  javac -cp .:./jssc.jar ./Connect.java
 4. Run
  java -cp .:./jssc.jar Connect
*/

// Import required classes
import jssc.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class Connect {

    // Joins byte arrays one after the other
    static byte[] concat(byte[]... parts) {
        int total = 0;
        for (byte[] p : parts) total += p.length;
        byte[] out = new byte[total];
        int pos = 0;
        for (byte[] p : parts) {
            System.arraycopy(p, 0, out, pos, p.length);
            pos += p.length;
        }
        return out;
    }

    // Bytes as a string of hex pairs
    static String toHex(byte[] data) {
        StringBuilder sb = new StringBuilder();
        for (byte b : data) {
            sb.append(String.format("%02x ", b & 0xFF));
        }
        return sb.toString().trim();
    }

    public static void main(String[] args) throws Exception {
        SerialPort port = new SerialPort("/dev/ttyUSB0");
        try {
            // Open connection to serial port
            // Change /dev/ttyUSB0 to match your system
            port.openPort();

            // Configure the port
            port.setParams(SerialPort.BAUDRATE_9600,
                           SerialPort.DATABITS_8,
                           SerialPort.STOPBITS_1,
                           SerialPort.PARITY_NONE);
            port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);

            // ioStack serial number 123456789012 is 1C BE 99 1A 14 in 5 bytes (big-endian)
            // Request: 43 (start), serial number, 02 (Get Status), 00 (no body), then the 2 CRC bytes (low byte first)
            byte[] request = { (byte) 0x43, (byte) 0x1C, (byte) 0xBE, (byte) 0x99, (byte) 0x1A, (byte) 0x14, (byte) 0x02, (byte) 0x00, (byte) 0x98, (byte) 0x91 };

            // Send the request to the ioStack
            port.writeBytes(request);

            // Get the response header: 8 bytes. Byte 7 holds the length of the body
            byte[] header = port.readBytes(8, 5000);

            // Get the body and the 2 CRC bytes
            byte[] response = concat(header, port.readBytes((header[7] & 0xFF) + 2, 5000));

            // Show response as HEX
            System.out.println(toHex(response));

            // Close connection to serial port
            port.closePort();
        }
        catch (SerialPortTimeoutException ex) {
            System.out.println("Connection Timed out");
        }
        catch (SerialPortException ex) {
            System.out.println(ex);
        }
    }
}
/*
* Requirements
* NodeJS: v16.15.0
* Serialport: 10.4.0
*/

// Load modules
const {SerialPort} = require('serialport');

// Bytes as a string of hex pairs
const toHex = (data) => [...data].map((b) => b.toString(16).padStart(2, '0')).join(' ');

// Params for Serial Port
// Change path to match your system
const port = new SerialPort({
  path: '/dev/ttyUSB0',
  baudRate: 9600,
  parity: 'none',
  dataBits: 8,
  stopBits: 1,
});

// Collects what the ioStack sends and resolves with one whole frame
let pending = Buffer.alloc(0);
port.on('data', (chunk) => { pending = Buffer.concat([pending, chunk]); });
const readFrame = (timeoutMs = 5000) => new Promise((resolve, reject) => {
  const start = Date.now();
  const check = () => {
    // The first 8 bytes are the header. Byte 7 holds the length of the body
    if (pending.length >= 8 && pending.length >= 8 + pending[7] + 2) {
      const frame = pending.subarray(0, 8 + pending[7] + 2);
      pending = Buffer.alloc(0);
      resolve(frame);
    } else if (Date.now() - start > timeoutMs) {
      reject(new Error('Connection timed out!'));
    } else {
      setTimeout(check, 20);
    }
  };
  check();
});

// Start ioStack communication
;(async () => {
  // Wait for the port to open
  await new Promise((resolve, reject) => { port.once('open', resolve); port.once('error', reject); });
  console.log('Connection Opened');

  // ioStack serial number 123456789012 is 1C BE 99 1A 14 in 5 bytes (big-endian)
  // Request: 43 (start), serial number, 02 (Get Status), 00 (no body), then the 2 CRC bytes (low byte first)
  const request = Buffer.from([0x43, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x02, 0x00, 0x98, 0x91]);

  // Send the request to the ioStack
  port.write(request);

  // Get the response header: 8 bytes. Byte 7 holds the length of the body
  const response = await readFrame();

  // Show response as HEX
  console.log(toHex(response));

  // Close connection to serial port
  port.close();
})();

For security reasons browsers have very limited access to the machines resources, writing browser ran Javascript (client-side) is not a viable option

The above example returns the following results:


02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

Connecting to ioStack

Send any of your ioStacks on your RS-485 network this simple request (including its serial number) and the targeted ioStack will respond with its status: device type, firmware version, uptime, chip ID and clock.

The ioStack waits about 5 ms before it answers. Use a read timeout of at least 100 ms, the examples use 5 seconds.

Each request and its response stand on their own. There is no connection string to open a session and no close string to end it, like the meters use.

To connect the request would be structured like: 43 (5 Bytes Serial Number) 02 00 (2 Byte CRC)

Example: \x43\x1c\xbe\x99\x1a\x14\x02\x00\x98\x91

Get Status Request Parameters

Parameter Description
43 Start of a request. Every request starts with this byte
1C BE 99 1A 14 5 byte serial number = ioStack serial number: 123456789012
02 opcode. This hex code is for a Get Status request
00 body length. Get Status has no body
98 91 2 byte CRC-16, low byte first. See the CRC-16 Checksum section

Response from an ioStack

Here is a typical Get Status response hex code from an ioStack:

02 1C BE 99 1A 14 00 25 85 01 01 02 00 00 00 00 05 26 5C 00 A1 B2 C3 D4 E5 F6 07 18 29 3A 4B 5C 6D 7E 8F 90 00 05 1E 0F 0C 1B 0B 07 EA A3 81

Parameter Description
02 1 byte address = informs the computer that a packet is coming from the ioStack. This is the opcode of the request
1C BE 99 1A 14 5 byte serial number = ioStack serial number: 123456789012
00 1 byte status = 00 means the command ran. See the Parsing Responses section
25 1 byte body length = 37 bytes follow before the CRC
85 01 2 byte address = device type (85) and model number (01)
01 02 2 byte address = firmware version, major 01 and minor 02
00 00 00 00 05 26 5C 00 8 byte address = milliseconds since the chip was first started (86400000)
A1 B2 C3 D4 E5 F6 07 18 29 3A 4B 5C 6D 7E 8F 90 16 byte address = unique chip ID
00 05 2 byte address = real-time clock adjustment value
1E 0F 0C 1B 0B 5 bytes = second 30, minute 15, hour 12, day 27, month 11
07 EA 2 byte address = year 2026
A3 81 2 byte CRC-16, low byte first

CRC-16 Checksum

# CRC-16/MODBUS has no simple shell command.
# Use one of the other languages to calculate the CRC.
# Ruby Version: 2.7.0
# Serialport version: 1.3.2
# Requires the SerialPort gem
# (http://rubygems.org/gems/serialport)
# gem install serialport

require 'serialport'

# CRC-16/MODBUS of data. Returns the 2 CRC bytes, low byte first.
def ekm_crc16(data)
  crc = 0xFFFF
  data.each_byte do |b|
    crc ^= b
    8.times { crc = crc.odd? ? (crc >> 1) ^ 0xA001 : crc >> 1 }
  end
  [crc & 0xFF, (crc >> 8) & 0xFF].pack('C*')
end

# This is the request without its 2 CRC bytes: Get Status for serial number 123456789012
message = [0x43, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x02, 0x00].pack('C*')

# Calculate the CRC. The result is 2 bytes, low byte first
crc = ekm_crc16(message)

# Show the CRC as HEX
puts crc.unpack('C*').map { |b| format('%02x', b) }.join(' ')

# To send the request, add the CRC to the end of the message
request = message + crc

# Show the whole request as HEX
puts request.unpack('C*').map { |b| format('%02x', b) }.join(' ')

# A response is checked the same way: the CRC of every byte before the last 2
# must equal the last 2 bytes of the response
response = [0x02, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x00, 0x25, 0x85, 0x01, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5C, 0x00, 0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6, 0x07, 0x18, 0x29, 0x3A, 0x4B, 0x5C, 0x6D, 0x7E, 0x8F, 0x90, 0x00, 0x05, 0x1E, 0x0F, 0x0C, 0x1B, 0x0B, 0x07, 0xEA, 0xA3, 0x81].pack('C*')
puts "Response CRC ok: #{ekm_crc16(response.byteslice(0, response.bytesize - 2)) == response.byteslice(-2, 2)}"
'''
Python version: 3.8.10
Modules:
Pyserial version: 3.4
Requires pyserial module:
    pip3 install pyserial
'''

import serial

def ekm_crc16(data):
    """CRC-16/MODBUS of data. Returns the 2 CRC bytes, low byte first."""
    crc = 0xFFFF
    for b in data:
        crc ^= b
        for _ in range(8):
            crc = (crc >> 1) ^ 0xA001 if crc & 1 else crc >> 1
    return bytes([crc & 0xFF, (crc >> 8) & 0xFF])

# This is the request without its 2 CRC bytes: Get Status for serial number 123456789012
message = bytes([0x43, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x02, 0x00])

# Calculate the CRC. The result is 2 bytes, low byte first
crc = ekm_crc16(message)

# Show the CRC as HEX
print(' '.join('{0:02x}'.format(b) for b in crc))

# To send the request, add the CRC to the end of the message
request = message + crc

# Show the whole request as HEX
print(' '.join('{0:02x}'.format(b) for b in request))

# A response is checked the same way: the CRC of every byte before the last 2
# must equal the last 2 bytes of the response
response = bytes([0x02, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x00, 0x25, 0x85, 0x01, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5C, 0x00, 0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6, 0x07, 0x18, 0x29, 0x3A, 0x4B, 0x5C, 0x6D, 0x7E, 0x8F, 0x90, 0x00, 0x05, 0x1E, 0x0F, 0x0C, 0x1B, 0x0B, 0x07, 0xEA, 0xA3, 0x81])
print('Response CRC ok:', ekm_crc16(response[:-2]) == response[-2:])
<?php
/*
* Requirements:
* PHP: 8.1.5
* DIO: 0.2.1
*
* Install php8.1-dev on ubuntu to compile DIO module.
* apt install php8.1-dev
* Compile DIO module from source:
* Download the latest tarball from: https://pecl.php.net/package/dio
* Uncompress: tar xfz dio-0.2.1.tgz
* cd dio-0.2.1/
* phpize
* ./configure
* make
* sudo make install
* You will see a path like: /usr/lib/php/20210902/
* Edit your php.ini
* vi /etc/php/8.1/cli/php.ini
* In the extension section add:
* extension=/usr/lib/php/20210902/dio.so
* Now you can run your php script.
* Ex: php connect.php
*/

// CRC-16/MODBUS of $data. Returns the 2 CRC bytes, low byte first.
function ekm_crc16(string $data): string {
    $crc = 0xFFFF;
    for ($i = 0; $i < strlen($data); $i++) {
        $crc ^= ord($data[$i]);
        for ($j = 0; $j < 8; $j++) {
            $crc = ($crc & 1) ? (($crc >> 1) ^ 0xA001) : ($crc >> 1);
        }
    }
    return chr($crc & 0xFF) . chr(($crc >> 8) & 0xFF);
}

// This is the request without its 2 CRC bytes: Get Status for serial number 123456789012
$message = pack('C*', 0x43, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x02, 0x00);

// Calculate the CRC. The result is 2 bytes, low byte first
$crc = ekm_crc16($message);

// Show the CRC as HEX
echo implode(' ', str_split(bin2hex($crc), 2)) . "\n";

// To send the request, add the CRC to the end of the message
$request = $message . $crc;

// Show the whole request as HEX
echo implode(' ', str_split(bin2hex($request), 2)) . "\n";

// A response is checked the same way: the CRC of every byte before the last 2
// must equal the last 2 bytes of the response
$response = pack('C*', 0x02, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x00, 0x25, 0x85, 0x01, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5C, 0x00, 0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6, 0x07, 0x18, 0x29, 0x3A, 0x4B, 0x5C, 0x6D, 0x7E, 0x8F, 0x90, 0x00, 0x05, 0x1E, 0x0F, 0x0C, 0x1B, 0x0B, 0x07, 0xEA, 0xA3, 0x81);
echo 'Response CRC ok: ' . (ekm_crc16(substr($response, 0, -2)) === substr($response, -2) ? 'true' : 'false') . "\n";

?>
#!/usr/bin/perl
# Perl version: v5.30.0
# CPAN.pm version v2.34
#
# Requires the Device::SerialPort module
# Device::SerialPort: 1.04
#
# Install Perl Modules
#       cpan Device::SerialPort

use strict;
use warnings;
use Device::SerialPort;

# CRC-16/MODBUS of $data. Returns the 2 CRC bytes, low byte first.
sub ekm_crc16 {
    my ($data) = @_;
    my $crc = 0xFFFF;
    for my $b (unpack 'C*', $data) {
        $crc ^= $b;
        for (1 .. 8) {
            $crc = ($crc & 1) ? (($crc >> 1) ^ 0xA001) : ($crc >> 1);
        }
    }
    return pack('C2', $crc & 0xFF, ($crc >> 8) & 0xFF);
}

# This is the request without its 2 CRC bytes: Get Status for serial number 123456789012
my $message = pack('C*', 0x43, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x02, 0x00);

# Calculate the CRC. The result is 2 bytes, low byte first
my $crc = ekm_crc16($message);

# Show the CRC as HEX
print join(' ', map { sprintf '%02x', ord } split //, $crc), "\n";

# To send the request, add the CRC to the end of the message
my $request = $message . $crc;

# Show the whole request as HEX
print join(' ', map { sprintf '%02x', ord } split //, $request), "\n";

# A response is checked the same way: the CRC of every byte before the last 2
# must equal the last 2 bytes of the response
my $response = pack('C*', 0x02, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x00, 0x25, 0x85, 0x01, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5C, 0x00, 0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6, 0x07, 0x18, 0x29, 0x3A, 0x4B, 0x5C, 0x6D, 0x7E, 0x8F, 0x90, 0x00, 0x05, 0x1E, 0x0F, 0x0C, 0x1B, 0x0B, 0x07, 0xEA, 0xA3, 0x81);
print 'Response CRC ok: ', (ekm_crc16(substr($response, 0, -2)) eq substr($response, -2) ? 'true' : 'false'), "\n";
/*
 openjdk version "17.0.2" 2022-01-18
 Download the jssc.jar (java-simple-serial-connector)
 from: https://code.google.com/archive/p/java-simple-serial-connector/
 Version: jSSC-2.8.0

 Instructions to run this program

 1. Put this code in a file named Crc.java
 2. Copy the downloaded jssc.jar and Crc.java to the same directory
 3. Compile
  javac -cp .:./jssc.jar ./Crc.java
 4. Run
  java -cp .:./jssc.jar Crc
*/

// Import required classes
import jssc.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class Crc {

    // CRC-16/MODBUS of data. Returns the 2 CRC bytes, low byte first.
    static byte[] crc16(byte[] data) {
        int crc = 0xFFFF;
        for (byte b : data) {
            crc ^= (b & 0xFF);
            for (int i = 0; i < 8; i++) {
                crc = (crc & 1) != 0 ? (crc >> 1) ^ 0xA001 : crc >> 1;
            }
        }
        return new byte[] { (byte) (crc & 0xFF), (byte) ((crc >> 8) & 0xFF) };
    }

    // Joins byte arrays one after the other
    static byte[] concat(byte[]... parts) {
        int total = 0;
        for (byte[] p : parts) total += p.length;
        byte[] out = new byte[total];
        int pos = 0;
        for (byte[] p : parts) {
            System.arraycopy(p, 0, out, pos, p.length);
            pos += p.length;
        }
        return out;
    }

    // Bytes as a string of hex pairs
    static String toHex(byte[] data) {
        StringBuilder sb = new StringBuilder();
        for (byte b : data) {
            sb.append(String.format("%02x ", b & 0xFF));
        }
        return sb.toString().trim();
    }

    public static void main(String[] args) throws Exception {
        // This is the request without its 2 CRC bytes: Get Status for serial number 123456789012
        byte[] message = { (byte) 0x43, (byte) 0x1C, (byte) 0xBE, (byte) 0x99, (byte) 0x1A, (byte) 0x14, (byte) 0x02, (byte) 0x00 };

        // Calculate the CRC. The result is 2 bytes, low byte first
        byte[] crc = crc16(message);

        // Show the CRC as HEX
        System.out.println(toHex(crc));

        // To send the request, add the CRC to the end of the message
        byte[] request = concat(message, crc);

        // Show the whole request as HEX
        System.out.println(toHex(request));

        // A response is checked the same way: the CRC of every byte before the last 2
        // must equal the last 2 bytes of the response
        byte[] response = { (byte) 0x02, (byte) 0x1C, (byte) 0xBE, (byte) 0x99, (byte) 0x1A, (byte) 0x14, (byte) 0x00, (byte) 0x25, (byte) 0x85, (byte) 0x01, (byte) 0x01, (byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05, (byte) 0x26, (byte) 0x5C, (byte) 0x00, (byte) 0xA1, (byte) 0xB2, (byte) 0xC3, (byte) 0xD4, (byte) 0xE5, (byte) 0xF6, (byte) 0x07, (byte) 0x18, (byte) 0x29, (byte) 0x3A, (byte) 0x4B, (byte) 0x5C, (byte) 0x6D, (byte) 0x7E, (byte) 0x8F, (byte) 0x90, (byte) 0x00, (byte) 0x05, (byte) 0x1E, (byte) 0x0F, (byte) 0x0C, (byte) 0x1B, (byte) 0x0B, (byte) 0x07, (byte) 0xEA, (byte) 0xA3, (byte) 0x81 };
        System.out.println("Response CRC ok: " + Arrays.equals(crc16(Arrays.copyOfRange(response, 0, response.length - 2)),
                           Arrays.copyOfRange(response, response.length - 2, response.length)));
    }
}
/*
* Requirements
* NodeJS: v16.15.0
* Serialport: 10.4.0
*/

// Load modules
const {SerialPort} = require('serialport');

// CRC-16/MODBUS of data. Returns the 2 CRC bytes, low byte first.
const crc16 = (data) => {
  let crc = 0xFFFF;
  for (const b of data) {
    crc ^= b;
    for (let i = 0; i < 8; i++) {
      crc = (crc & 1) ? (crc >> 1) ^ 0xA001 : crc >> 1;
    }
  }
  return Buffer.from([crc & 0xFF, (crc >> 8) & 0xFF]);
};

// Bytes as a string of hex pairs
const toHex = (data) => [...data].map((b) => b.toString(16).padStart(2, '0')).join(' ');

;(async () => {
  // This is the request without its 2 CRC bytes: Get Status for serial number 123456789012
  const message = Buffer.from([0x43, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x02, 0x00]);

  // Calculate the CRC. The result is 2 bytes, low byte first
  const crc = crc16(message);

  // Show the CRC as HEX
  console.log(toHex(crc));

  // To send the request, add the CRC to the end of the message
  const request = Buffer.concat([message, crc]);

  // Show the whole request as HEX
  console.log(toHex(request));

  // A response is checked the same way: the CRC of every byte before the last 2
  // must equal the last 2 bytes of the response
  const response = Buffer.from([0x02, 0x1C, 0xBE, 0x99, 0x1A, 0x14, 0x00, 0x25, 0x85, 0x01, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x05, 0x26, 0x5C, 0x00, 0xA1, 0xB2, 0xC3, 0xD4, 0xE5, 0xF6, 0x07, 0x18, 0x29, 0x3A, 0x4B, 0x5C, 0x6D, 0x7E, 0x8F, 0x90, 0x00, 0x05, 0x1E, 0x0F, 0x0C, 0x1B, 0x0B, 0x07, 0xEA, 0xA3, 0x81]);
  console.log('Response CRC ok:', crc16(response.subarray(0, -2)).equals(response.subarray(-2)));
})();

For security reasons browsers have very limited access to the machines resources, writing browser ran Javascript (client-side) is not a viable option

The above example returns the following results:


98 91
43 1c be 99 1a 14 02 00 98 91
Response CRC ok: true

98 91
43 1c be 99 1a 14 02 00 98 91
Response CRC ok: true

98 91
43 1c be 99 1a 14 02 00 98 91
Response CRC ok: True

98 91
43 1c be 99 1a 14 02 00 98 91
Response CRC ok: true

98 91
43 1c be 99 1a 14 02 00 98 91
Response CRC ok: true

98 91
43 1c be 99 1a 14 02 00 98 91
Response CRC ok: true

98 91
43 1c be 99 1a 14 02 00 98 91
Response CRC ok: true

CRC-16 Checksum

Once you have established a connection to the ioStack, you will want to start making use of the CRC-16 checksum in communication with the ioStack. Every request you send must end with it. The ioStack checks it before it does anything, and answers with status 0x81 (CRC error) when it is wrong.

You do not need to validate the checksum on messages you receive from the ioStack, however, it is handy to verify your communication is working. A response that fails its CRC was damaged on the way and should be thrown away.

The ioStack uses the CRC-16/MODBUS checksum: start value 0xFFFF, polynomial 0xA001, bytes processed one at a time. The 2 CRC bytes are sent low byte first.

On requests and on responses the checksum is calculated from the first byte to the 3rd from the last byte. That is every byte before the CRC itself.

For example when you send a Get Status request to serial number 123456789012 you would send this:

1 Byte - 43 Start of a request. This is where the CRC-16 Checksum starts
5 Bytes - 1C BE 99 1A 14 This is the ioStack serial number, 123456789012
1 Byte - 02 This is the opcode, Get Status
1 Byte - 00 This is the body length. Get Status has no body. This is where the CRC-16 Checksum ends
2 Bytes - 98 91 This is the CRC-16 Checksum, low byte first

Sending Requests to ioStack

# The serial device in this example is /dev/ttyUSB0

# First set up your serial port
stty -F /dev/ttyUSB0 cs8 -parenb -cstopb -ixon raw -echo 9600

# Now we start hexdump to monitor the serial port
hexdump -v -e '1/1 "%02x "' /dev/ttyUSB0 &

# In this example we send a Get Status request (opcode 0x02) to serial number 123456789012
# The serial number in hex is 1C BE 99 1A 14. The last 2 bytes are the CRC
printf '\x43\x1c\xbe\x99\x1a\x14\x02\x00\x98\x91' > /dev/ttyUSB0

# Wait a moment for the response, then kill hexdump to stop monitoring the serial port
sleep 1
killall -9 hexdump
# Ruby Version: 2.7.0
# Serialport version: 1.3.2
# Requires the SerialPort gem
# (http://rubygems.org/gems/serialport)
# gem install serialport

require 'serialport'

# CRC-16/MODBUS of data. Returns the 2 CRC bytes, low byte first.
def ekm_crc16(data)
  crc = 0xFFFF
  data.each_byte do |b|
    crc ^= b
    8.times { crc = crc.odd? ? (crc >> 1) ^ 0xA001 : crc >> 1 }
  end
  [crc & 0xFF, (crc >> 8) & 0xFF].pack('C*')
end

# Big-endian bytes of value, `size` bytes long
def be(value, size)
  (0...size).map { |i| (value >> (8 * (size - 1 - i))) & 0xFF }.pack('C*')
end

# Text as bytes, NUL-padded to `size` bytes
def padded(text, size)
  [text].pack("a#{size}")
end

# Builds one request frame: 0x43, serial number, opcode, body length, body, CRC
def build_request(sn, opcode, body = '')
  body = body.b
  msg = "\x43".b + be(sn, 5) + [opcode, body.bytesize].pack('C*') + body
  msg + ekm_crc16(msg)
end

# Reads exactly n bytes from the port. Gives up after 5 seconds.
def read_bytes(port, n, timeout = 5)
  data = ''.b
  deadline = Time.now + timeout
  while data.bytesize < n && Time.now < deadline
    chunk = port.read(n - data.bytesize)
    data << chunk if chunk
  end
  raise 'Connection timed out!' if data.bytesize < n

  data
end

# Reads one response frame and checks its CRC
def read_response(port)
  # The first 8 bytes are the header. Byte 7 is the length of the body
  header = read_bytes(port, 8)
  body_len = header.getbyte(7)

  # The rest of the frame is the body and the 2 CRC bytes
  frame = header + read_bytes(port, body_len + 2)

  # The CRC covers every byte before the CRC itself
  raise 'Bad CRC in response!' unless ekm_crc16(frame.byteslice(0, frame.bytesize - 2)) == frame.byteslice(-2, 2)

  { opcode: frame.getbyte(0), rc: frame.getbyte(6), body: frame.byteslice(8, body_len), frame: frame }
end

# Params for serial port
# Change /dev/ttyUSB0 to match your system
port_str = '/dev/ttyUSB0'
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE

# Open connection to serial port
port = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
port.flow_control = SerialPort::NONE

# Wait up to 5 seconds (in milliseconds) for each read
port.read_timeout = 5000

# In this code example we make a simple function that takes the opcode and the body of
# the request you want to send to the ioStack. It builds the frame with its CRC, sends it,
# then gets the response and checks its CRC and its status byte to make sure the response is correct
def send_request(port, opcode, body = '')
  port.write(build_request(123456789012, opcode, body))
  rsp = read_response(port)
  raise format('Request failed: 0x%02X', rsp[:rc]) unless rsp[:rc] == 0x00

  rsp
end

# Echo: the ioStack sends back the same bytes (opcode 0x01)
rsp = send_request(port, 0x01, 'hello')
puts rsp[:frame].unpack('C*').map { |b| format('%02x', b) }.join(' ')

# Get Status: no body (opcode 0x02)
rsp = send_request(port, 0x02)
puts rsp[:frame].unpack('C*').map { |b| format('%02x', b) }.join(' ')

# Close connection to serial port
port.close
'''
Python version: 3.8.10
Modules:
Pyserial version: 3.4
Requires pyserial module:
    pip3 install pyserial
'''

import serial

def ekm_crc16(data):
    """CRC-16/MODBUS of data. Returns the 2 CRC bytes, low byte first."""
    crc = 0xFFFF
    for b in data:
        crc ^= b
        for _ in range(8):
            crc = (crc >> 1) ^ 0xA001 if crc & 1 else crc >> 1
    return bytes([crc & 0xFF, (crc >> 8) & 0xFF])

def be(value, size):
    """Big-endian bytes of value, size bytes long."""
    return (value & ((1 << (8 * size)) - 1)).to_bytes(size, 'big')


def padded(text, size):
    """Text as bytes, NUL-padded to size bytes."""
    return text.encode('ascii')[:size].ljust(size, b'\x00')


def build_request(sn, opcode, body=b''):
    """Builds one request frame: 0x43, serial number, opcode, body length, body, CRC."""
    msg = b'\x43' + be(sn, 5) + bytes([opcode, len(body)]) + body
    return msg + ekm_crc16(msg)

def read_response(port):
    """Reads one response frame and checks its CRC."""
    # The first 8 bytes are the header. Byte 7 is the length of the body
    header = port.read(8)
    if len(header) < 8:
        raise IOError('Connection timed out!')
    body_len = header[7]

    # The rest of the frame is the body and the 2 CRC bytes
    rest = port.read(body_len + 2)
    if len(rest) < body_len + 2:
        raise IOError('Connection timed out!')
    frame = header + rest

    # The CRC covers every byte before the CRC itself
    if ekm_crc16(frame[:-2]) != frame[-2:]:
        raise IOError('Bad CRC in response!')
    return {'opcode': frame[0], 'rc': frame[6], 'body': frame[8:8 + body_len], 'frame': frame}

# Open connection to serial port
# Change /dev/ttyUSB0 to match your system
port = serial.Serial(
    port='/dev/ttyUSB0',
    baudrate=9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    xonxoff=0,
    timeout=5  # seconds to wait for a response
)

# In this code example we make a simple function that takes the opcode and the body of
# the request you want to send to the ioStack. It builds the frame with its CRC, sends it,
# then gets the response and checks its CRC and its status byte to make sure the response is correct
def send_request(opcode, body=b''):
    port.write(build_request(123456789012, opcode, body))
    rsp = read_response(port)
    if rsp['rc'] != 0x00:
        raise IOError('Request failed: {0:#04x}'.format(rsp['rc']))
    return rsp

# Echo: the ioStack sends back the same bytes (opcode 0x01)
rsp = send_request(0x01, b'hello')
print(' '.join('{0:02x}'.format(b) for b in rsp['frame']))

# Get Status: no body (opcode 0x02)
rsp = send_request(0x02)
print(' '.join('{0:02x}'.format(b) for b in rsp['frame']))

# Close connection to serial port
port.close()
<?php
/*
* Requirements:
* PHP: 8.1.5
* DIO: 0.2.1
*
* Install php8.1-dev on ubuntu to compile DIO module.
* apt install php8.1-dev
* Compile DIO module from source:
* Download the latest tarball from: https://pecl.php.net/package/dio
* Uncompress: tar xfz dio-0.2.1.tgz
* cd dio-0.2.1/
* phpize
* ./configure
* make
* sudo make install
* You will see a path like: /usr/lib/php/20210902/
* Edit your php.ini
* vi /etc/php/8.1/cli/php.ini
* In the extension section add:
* extension=/usr/lib/php/20210902/dio.so
* Now you can run your php script.
* Ex: php connect.php
*/

// CRC-16/MODBUS of $data. Returns the 2 CRC bytes, low byte first.
function ekm_crc16(string $data): string {
    $crc = 0xFFFF;
    for ($i = 0; $i < strlen($data); $i++) {
        $crc ^= ord($data[$i]);
        for ($j = 0; $j < 8; $j++) {
            $crc = ($crc & 1) ? (($crc >> 1) ^ 0xA001) : ($crc >> 1);
        }
    }
    return chr($crc & 0xFF) . chr(($crc >> 8) & 0xFF);
}

// Big-endian bytes of $value, $size bytes long
function be(int $value, int $size): string {
    $out = '';
    for ($i = $size - 1; $i >= 0; $i--) {
        $out .= chr(($value >> (8 * $i)) & 0xFF);
    }
    return $out;
}

// Text as bytes, NUL-padded to $size bytes
function padded(string $text, int $size): string {
    return str_pad(substr($text, 0, $size), $size, "\0");
}

// Builds one request frame: 0x43, serial number, opcode, body length, body, CRC
function build_request(int $sn, int $opcode, string $body = ''): string {
    $msg = chr(0x43) . be($sn, 5) . chr($opcode) . chr(strlen($body)) . $body;
    return $msg . ekm_crc16($msg);
}

// Reads exactly $n bytes from the port. Gives up after 5 seconds.
function read_bytes($port, int $n, int $timeout = 5): string {
    $data = '';
    $end = time() + $timeout;
    while (strlen($data) < $n && time() < $end) {
        $chunk = dio_read($port, $n - strlen($data));
        if ($chunk === false || $chunk === null || $chunk === '') {
            usleep(10000);
        } else {
            $data .= $chunk;
        }
    }
    if (strlen($data) < $n) {
        throw new RuntimeException('Connection timed out!');
    }
    return $data;
}

// Reads one response frame and checks its CRC
function read_response($port): array {
    // The first 8 bytes are the header. Byte 7 is the length of the body
    $header = read_bytes($port, 8);
    $body_len = ord($header[7]);

    // The rest of the frame is the body and the 2 CRC bytes
    $frame = $header . read_bytes($port, $body_len + 2);

    // The CRC covers every byte before the CRC itself
    if (ekm_crc16(substr($frame, 0, -2)) !== substr($frame, -2)) {
        throw new RuntimeException('Bad CRC in response!');
    }
    return ['opcode' => ord($frame[0]), 'rc' => ord($frame[6]), 'body' => substr($frame, 8, $body_len), 'frame' => $frame];
}

// Open connection to serial port
// Change /dev/ttyUSB0 to match your system
$port = dio_open('/dev/ttyUSB0', O_RDWR | O_NONBLOCK);

// Configure the port
dio_tcsetattr($port, array(
   'baud'         => 9600,
   'bits'         => 8,
   'stop'         => 1,
   'parity'       => 0,
   'flow_control' => 0,
   'is_canonical' => 0
));

// In this code example we make a simple function that takes the opcode and the body of
// the request you want to send to the ioStack. It builds the frame with its CRC, sends it,
// then gets the response and checks its CRC and its status byte to make sure the response is correct
function send_request($port, int $opcode, string $body = ''): array {
    dio_write($port, build_request(123456789012, $opcode, $body));
    $rsp = read_response($port);
    if ($rsp['rc'] !== 0x00) {
        throw new RuntimeException(sprintf('Request failed: 0x%02X', $rsp['rc']));
    }
    return $rsp;
}

// Echo: the ioStack sends back the same bytes (opcode 0x01)
$rsp = send_request($port, 0x01, 'hello');
echo implode(' ', str_split(bin2hex($rsp['frame']), 2)) . "\n";

// Get Status: no body (opcode 0x02)
$rsp = send_request($port, 0x02);
echo implode(' ', str_split(bin2hex($rsp['frame']), 2)) . "\n";

// Close connection to serial port
dio_close($port);

?>
#!/usr/bin/perl
# Perl version: v5.30.0
# CPAN.pm version v2.34
#
# Requires the Device::SerialPort module
# Device::SerialPort: 1.04
#
# Install Perl Modules
#       cpan Device::SerialPort

use strict;
use warnings;
use Device::SerialPort;

# CRC-16/MODBUS of $data. Returns the 2 CRC bytes, low byte first.
sub ekm_crc16 {
    my ($data) = @_;
    my $crc = 0xFFFF;
    for my $b (unpack 'C*', $data) {
        $crc ^= $b;
        for (1 .. 8) {
            $crc = ($crc & 1) ? (($crc >> 1) ^ 0xA001) : ($crc >> 1);
        }
    }
    return pack('C2', $crc & 0xFF, ($crc >> 8) & 0xFF);
}

# Big-endian bytes of $value, $size bytes long
sub be {
    my ($value, $size) = @_;
    return join '', map { chr(($value >> (8 * ($size - 1 - $_))) & 0xFF) } 0 .. $size - 1;
}

# Text as bytes, NUL-padded to $size bytes
sub padded {
    my ($text, $size) = @_;
    return pack("a$size", $text);
}

# Builds one request frame: 0x43, serial number, opcode, body length, body, CRC
sub build_request {
    my ($sn, $opcode, $body) = @_;
    $body //= '';
    my $msg = chr(0x43) . be($sn, 5) . pack('C2', $opcode, length $body) . $body;
    return $msg . ekm_crc16($msg);
}

# Reads exactly $n bytes from the port. Gives up after 5 seconds.
sub read_bytes {
    my ($port, $n) = @_;
    my $timeout = 5;
    my $data = '';
    while (length($data) < $n && $timeout > 0) {
        my ($count, $read) = $port->read($n - length($data));
        if ($count > 0) {
            $data .= $read;
        }
        else {
            $timeout--;
        }
    }
    die "Connection timed out!\n" if length($data) < $n;
    return $data;
}

# Reads one response frame and checks its CRC
sub read_response {
    my ($port) = @_;

    # The first 8 bytes are the header. Byte 7 is the length of the body
    my $header = read_bytes($port, 8);
    my $body_len = ord(substr($header, 7, 1));

    # The rest of the frame is the body and the 2 CRC bytes
    my $frame = $header . read_bytes($port, $body_len + 2);

    # The CRC covers every byte before the CRC itself
    die "Bad CRC in response!\n" unless ekm_crc16(substr($frame, 0, -2)) eq substr($frame, -2);
    return {
        opcode => ord(substr($frame, 0, 1)),
        rc     => ord(substr($frame, 6, 1)),
        body   => substr($frame, 8, $body_len),
        frame  => $frame,
    };
}

# Open connection to serial port
# Change /dev/ttyUSB0 to match your system
my $port = Device::SerialPort->new('/dev/ttyUSB0') or die "Cannot open /dev/ttyUSB0\n";

# Configure the port
$port->baudrate(9600);
$port->parity('none');
$port->databits(8);
$port->stopbits(1);
$port->handshake('none');
$port->write_settings;

# don't wait for each character
$port->read_char_time(0);

# wait for 1 second per unfulfilled read
$port->read_const_time(1000);

# In this code example we make a simple function that takes the opcode and the body of
# the request you want to send to the ioStack. It builds the frame with its CRC, sends it,
# then gets the response and checks its CRC and its status byte to make sure the response is correct
sub send_request {
    my ($port, $opcode, $body) = @_;
    $port->write(build_request(123456789012, $opcode, $body));
    my $rsp = read_response($port);
    die sprintf("Request failed: 0x%02X\n", $rsp->{rc}) unless $rsp->{rc} == 0x00;
    return $rsp;
}

# Echo: the ioStack sends back the same bytes (opcode 0x01)
my $rsp = send_request($port, 0x01, 'hello');
print join(' ', map { sprintf '%02x', ord } split //, $rsp->{frame}), "\n";

# Get Status: no body (opcode 0x02)
$rsp = send_request($port, 0x02);
print join(' ', map { sprintf '%02x', ord } split //, $rsp->{frame}), "\n";

# Close connection to serial port
$port->close;
undef $port;
/*
 openjdk version "17.0.2" 2022-01-18
 Download the jssc.jar (java-simple-serial-connector)
 from: https://code.google.com/archive/p/java-simple-serial-connector/
 Version: jSSC-2.8.0

 Instructions to run this program

 1. Put this code in a file named SendRequests.java
 2. Copy the downloaded jssc.jar and SendRequests.java to the same directory
 3. Compile
  javac -cp .:./jssc.jar ./SendRequests.java
 4. Run
  java -cp .:./jssc.jar SendRequests
*/

// Import required classes
import jssc.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class SendRequests {

    // CRC-16/MODBUS of data. Returns the 2 CRC bytes, low byte first.
    static byte[] crc16(byte[] data) {
        int crc = 0xFFFF;
        for (byte b : data) {
            crc ^= (b & 0xFF);
            for (int i = 0; i < 8; i++) {
                crc = (crc & 1) != 0 ? (crc >> 1) ^ 0xA001 : crc >> 1;
            }
        }
        return new byte[] { (byte) (crc & 0xFF), (byte) ((crc >> 8) & 0xFF) };
    }

    // Big-endian bytes of value, size bytes long
    static byte[] be(long value, int size) {
        byte[] out = new byte[size];
        for (int i = size - 1; i >= 0; i--) {
            out[i] = (byte) (value & 0xFF);
            value >>= 8;
        }
        return out;
    }

    // Text as bytes, NUL-padded to size bytes
    static byte[] padded(String text, int size) {
        byte[] out = new byte[size];
        byte[] src = text.getBytes(StandardCharsets.US_ASCII);
        System.arraycopy(src, 0, out, 0, Math.min(src.length, size));
        return out;
    }

    // Joins byte arrays one after the other
    static byte[] concat(byte[]... parts) {
        int total = 0;
        for (byte[] p : parts) total += p.length;
        byte[] out = new byte[total];
        int pos = 0;
        for (byte[] p : parts) {
            System.arraycopy(p, 0, out, pos, p.length);
            pos += p.length;
        }
        return out;
    }

    // Builds one request frame: 0x43, serial number, opcode, body length, body, CRC
    static byte[] buildRequest(long sn, int opcode, byte[]... body) {
        byte[] payload = body.length > 0 ? body[0] : new byte[0];
        byte[] msg = concat(new byte[] { 0x43 }, be(sn, 5), new byte[] { (byte) opcode, (byte) payload.length }, payload);
        return concat(msg, crc16(msg));
    }

    // Bytes as a string of hex pairs
    static String toHex(byte[] data) {
        StringBuilder sb = new StringBuilder();
        for (byte b : data) {
            sb.append(String.format("%02x ", b & 0xFF));
        }
        return sb.toString().trim();
    }

    // Reads one response frame and checks its CRC
    static byte[] readResponse(SerialPort port) throws Exception {
        // The first 8 bytes are the header. Byte 7 is the length of the body
        byte[] header = port.readBytes(8, 5000);
        int bodyLen = header[7] & 0xFF;

        // The rest of the frame is the body and the 2 CRC bytes
        byte[] frame = concat(header, port.readBytes(bodyLen + 2, 5000));

        // The CRC covers every byte before the CRC itself
        byte[] crc = Arrays.copyOfRange(frame, frame.length - 2, frame.length);
        if (!Arrays.equals(crc, crc16(Arrays.copyOfRange(frame, 0, frame.length - 2)))) {
            throw new Exception("Bad CRC in response!");
        }
        return frame;
    }

    // In this code example we make a simple function that takes the opcode and the body of
    // the request you want to send to the ioStack. It builds the frame with its CRC, sends it,
    // then gets the response and checks its CRC and its status byte to make sure the response is correct
    static byte[] sendRequest(SerialPort port, int opcode, byte[]... body) throws Exception {
        port.writeBytes(buildRequest(123456789012L, opcode, body));
        byte[] frame = readResponse(port);
        if ((frame[6] & 0xFF) != 0x00) {
            throw new Exception(String.format("Request failed: 0x%02X", frame[6] & 0xFF));
        }
        return frame;
    }

    public static void main(String[] args) throws Exception {
        SerialPort port = new SerialPort("/dev/ttyUSB0");
        try {
            // Open connection to serial port
            // Change /dev/ttyUSB0 to match your system
            port.openPort();

            // Configure the port
            port.setParams(SerialPort.BAUDRATE_9600,
                           SerialPort.DATABITS_8,
                           SerialPort.STOPBITS_1,
                           SerialPort.PARITY_NONE);
            port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);

            // Echo: the ioStack sends back the same bytes (opcode 0x01)
            byte[] rsp = sendRequest(port, 0x01, "hello".getBytes(StandardCharsets.US_ASCII));
            System.out.println(toHex(rsp));

            // Get Status: no body (opcode 0x02)
            rsp = sendRequest(port, 0x02);
            System.out.println(toHex(rsp));

            // Close connection to serial port
            port.closePort();
        }
        catch (SerialPortTimeoutException ex) {
            System.out.println("Connection Timed out");
        }
        catch (SerialPortException ex) {
            System.out.println(ex);
        }
    }
}
/*
* Requirements
* NodeJS: v16.15.0
* Serialport: 10.4.0
*/

// Load modules
const {SerialPort} = require('serialport');

// CRC-16/MODBUS of data. Returns the 2 CRC bytes, low byte first.
const crc16 = (data) => {
  let crc = 0xFFFF;
  for (const b of data) {
    crc ^= b;
    for (let i = 0; i < 8; i++) {
      crc = (crc & 1) ? (crc >> 1) ^ 0xA001 : crc >> 1;
    }
  }
  return Buffer.from([crc & 0xFF, (crc >> 8) & 0xFF]);
};

// Big-endian bytes of value, size bytes long
const be = (value, size) => {
  const out = Buffer.alloc(size);
  for (let i = size - 1; i >= 0; i--) {
    out[i] = value % 256;
    value = Math.floor(value / 256);
  }
  return out;
};

// Text as bytes, NUL-padded to size bytes
const padded = (text, size) => {
  const out = Buffer.alloc(size);
  Buffer.from(text, 'ascii').copy(out, 0, 0, size);
  return out;
};

// Builds one request frame: 0x43, serial number, opcode, body length, body, CRC
const buildRequest = (sn, opcode, body = Buffer.alloc(0)) => {
  const msg = Buffer.concat([Buffer.from([0x43]), be(sn, 5), Buffer.from([opcode, body.length]), body]);
  return Buffer.concat([msg, crc16(msg)]);
};

// Bytes as a string of hex pairs
const toHex = (data) => [...data].map((b) => b.toString(16).padStart(2, '0')).join(' ');

// Reads one response frame and checks its CRC. Resolves with the whole frame as a Buffer.
const readResponse = (port, timeoutMs = 5000) => new Promise((resolve, reject) => {
  let buf = Buffer.alloc(0);
  const onData = (chunk) => {
    buf = Buffer.concat([buf, chunk]);

    // The first 8 bytes are the header. Byte 7 is the length of the body
    if (buf.length < 8) return;

    // The rest of the frame is the body and the 2 CRC bytes
    const total = 8 + buf[7] + 2;
    if (buf.length < total) return;
    clearTimeout(timer);
    port.off('data', onData);
    const frame = buf.subarray(0, total);

    // The CRC covers every byte before the CRC itself
    if (!crc16(frame.subarray(0, -2)).equals(frame.subarray(-2))) {
      reject(new Error('Bad CRC in response!'));
    } else {
      resolve(frame);
    }
  };
  const timer = setTimeout(() => {
    port.off('data', onData);
    reject(new Error('Connection timed out!'));
  }, timeoutMs);
  port.on('data', onData);
});

// Params for Serial Port
// Change path to match your system
const port = new SerialPort({
  path: '/dev/ttyUSB0',
  baudRate: 9600,
  parity: 'none',
  dataBits: 8,
  stopBits: 1,
});

// In this code example we make a simple function that takes the opcode and the body of
// the request you want to send to the ioStack. It builds the frame with its CRC, sends it,
// then gets the response and checks its CRC and its status byte to make sure the response is correct
const sendRequest = async (opcode, body = Buffer.alloc(0)) => {
  port.write(buildRequest(123456789012, opcode, body));
  const frame = await readResponse(port);
  if (frame[6] !== 0x00) throw new Error(`Request failed: 0x${frame[6].toString(16)}`);
  return frame;
};

// Start ioStack communication
;(async () => {
  // Wait for the port to open
  await new Promise((resolve, reject) => { port.once('open', resolve); port.once('error', reject); });
  console.log('Connection Opened');

  // Echo: the ioStack sends back the same bytes (opcode 0x01)
  let rsp = await sendRequest(0x01, Buffer.from('hello'));
  console.log(toHex(rsp));

  // Get Status: no body (opcode 0x02)
  rsp = await sendRequest(0x02);
  console.log(toHex(rsp));

  // Close connection to serial port
  port.close();
})();

For security reasons browsers have very limited access to the machines resources, writing browser ran Javascript (client-side) is not a viable option

The above example returns the following results:


01 1c be 99 1a 14 00 05 68 65 6c 6c 6f 05 03
02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

01 1c be 99 1a 14 00 05 68 65 6c 6c 6f 05 03
02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

01 1c be 99 1a 14 00 05 68 65 6c 6c 6f 05 03
02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

01 1c be 99 1a 14 00 05 68 65 6c 6c 6f 05 03
02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

01 1c be 99 1a 14 00 05 68 65 6c 6c 6f 05 03
02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

01 1c be 99 1a 14 00 05 68 65 6c 6c 6f 05 03
02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

01 1c be 99 1a 14 00 05 68 65 6c 6c 6f 05 03
02 1c be 99 1a 14 00 25 85 01 01 02 00 00 00 00 05 26 5c 00 a1 b2 c3 d4 e5 f6 07 18 29 3a 4b 5c 6d 7e 8f 90 00 05 1e 0f 0c 1b 0b 07 ea a3 81

Sending Requests

Every request is one frame. The frame is:

Byte Field
0 Header 0x43
1-5 Serial number, 5 bytes, big-endian
6 Opcode
7 Body length, 0 to 255
8 to n Body, the length given by byte 7
last 2 CRC-16/MODBUS of all bytes before it, low byte first

Send the frame at 9600 8N1. Each byte is binary, so do not convert values to ASCII.

The examples build the frame with the build_request function. It writes the header, the serial number and the opcode, then the length and the body, and adds the CRC to the end. The send_request function sends the frame, reads the response, and stops with an error when the CRC is wrong or when the ioStack answers with a status other than 0x00.

Communication Sequence for Requests to the ioStack

43 ( 5 Byte Serial Number ) ( Opcode ) ( Body Length ) ( Body ) ?? ?? The request. The body is only there for requests that have parameters, for example Echo has the text to send back.
( Opcode ) ( 5 Byte Serial Number ) ( Status ) ( Body Length ) ( Body ) ?? ?? The response from the ioStack. The status is 00 when the command ran, see the Parsing Responses section.

Requests that change settings

Requests that change a setting or an output carry a 4 byte Password field in the body, for example Set Serial Number, Set UART and DO Set Level. Always use the factory password 00000000 (bytes 00 00 00 00). Unlike the meters, the ioStack answers a wrong password with status 0x84 (Security error), so you can rely on the status byte to know whether the request was accepted.

Parsing Responses from ioStack

# The serial device in this example is /dev/ttyUSB0

# First set up your serial port
stty -F /dev/ttyUSB0 cs8 -parenb -cstopb -ixon raw -echo 9600

# Now we start hexdump to monitor the serial port
hexdump -v -e '1/1 "%02x "' /dev/ttyUSB0 &

# In this example we send a Get Status request (opcode 0x02) to serial number 123456789012
# The serial number in hex is 1C BE 99 1A 14. The last 2 bytes are the CRC
printf '\x43\x1c\xbe\x99\x1a\x14\x02\x00\x98\x91' > /dev/ttyUSB0

# Wait a moment for the response, then kill hexdump to stop monitoring the serial port
sleep 1
killall -9 hexdump
# Ruby Version: 2.7.0
# Serialport version: 1.3.2
# Requires the SerialPort gem
# (http://rubygems.org/gems/serialport)
# gem install serialport

require 'serialport'

# CRC-16/MODBUS of data. Returns the 2 CRC bytes, low byte first.
def ekm_crc16(data)
  crc = 0xFFFF
  data.each_byte do |b|
    crc ^= b
    8.times { crc = crc.odd? ? (crc >> 1) ^ 0xA001 : crc >> 1 }
  end
  [crc & 0xFF, (crc >> 8) & 0xFF].pack('C*')
end

# Big-endian bytes of value, `size` bytes long
def be(value, size)
  (0...size).map { |i| (value >> (8 * (size - 1 - i))) & 0xFF }.pack('C*')
end

# Text as bytes, NUL-padded to `size` bytes
def padded(text, size)
  [text].pack("a#{size}")
end

# Builds one request frame: 0x43, serial number, opcode, body length, body, CRC
def build_request(sn, opcode, body = '')
  body = body.b
  msg = "\x43".b + be(sn, 5) + [opcode, body.bytesize].pack('C*') + body
  msg + ekm_crc16(msg)
end

# Reads exactly n bytes from the port. Gives up after 5 seconds.
def read_bytes(port, n, timeout = 5)
  data = ''.b
  deadline = Time.now + timeout
  while data.bytesize < n && Time.now < deadline
    chunk = port.read(n - data.bytesize)
    data << chunk if chunk
  end
  raise 'Connection timed out!' if data.bytesize < n

  data
end

# Reads one response frame and checks its CRC
def read_response(port)
  # The first 8 bytes are the header. Byte 7 is the length of the body
  header = read_bytes(port, 8)
  body_len = header.getbyte(7)

  # The rest of the frame is the body and the 2 CRC bytes
  frame = header + read_bytes(port, body_len + 2)

  # The CRC covers every byte before the CRC itself
  raise 'Bad CRC in response!' unless ekm_crc16(frame.byteslice(0, frame.bytesize - 2)) == frame.byteslice(-2, 2)

  { opcode: frame.getbyte(0), rc: frame.getbyte(6), body: frame.byteslice(8, body_len), frame: frame }
end

# Unsigned big-endian integer from `size` bytes at `pos`
def be_uint(body, pos, size)
  body.byteslice(pos, size).unpack('C*').inject(0) { |acc, b| (acc << 8) | b }
end

# Signed big-endian integer from `size` bytes at `pos`
def be_int(body, pos, size)
  value = be_uint(body, pos, size)
  value >= (1 << (8 * size - 1)) ? value - (1 << (8 * size)) : value
end

# NUL-padded text from `size` bytes at `pos`
def be_str(body, pos, size)
  body.byteslice(pos, size).split("\x00", 2).first.to_s
end

# Hex string from `size` bytes at `pos`
def be_hex(body, pos, size)
  body.byteslice(pos, size).unpack1('H*')
end

# Params for serial port
# Change /dev/ttyUSB0 to match your system
port_str = '/dev/ttyUSB0'
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE

# Open connection to serial port
port = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
port.flow_control = SerialPort::NONE

# Wait up to 5 seconds (in milliseconds) for each read
port.read_timeout = 5000

# In this code example we make a simple function that takes the opcode and the body of
# the request you want to send to the ioStack. It builds the frame with its CRC, sends it,
# then gets the response and checks its CRC and its status byte to make sure the response is correct
def send_request(port, opcode, body = '')
  port.write(build_request(123456789012, opcode, body))
  rsp = read_response(port)
  raise format('Request failed: 0x%02X', rsp[:rc]) unless rsp[:rc] == 0x00

  rsp
end

# Send Get Status (opcode 0x02, no body)
rsp = send_request(port, 0x02)
body = rsp[:body]

# Move through the body field by field. Every field is big-endian
pos = 0
device_info = be_uint(body, pos, 2)
pos += 2
firmware_version = be_uint(body, pos, 2)
pos += 2
lifetime_ms = be_uint(body, pos, 8)
pos += 8
chip_id = be_hex(body, pos, 16)
pos += 16
rtc_tcr = be_uint(body, pos, 2)
pos += 2
second = be_uint(body, pos, 1)
pos += 1
minute = be_uint(body, pos, 1)
pos += 1
hour = be_uint(body, pos, 1)
pos += 1
day = be_uint(body, pos, 1)
pos += 1
month = be_uint(body, pos, 1)
pos += 1
year = be_uint(body, pos, 2)
pos += 2

# Show the fields
puts "Device type: #{device_info >> 8} model: #{device_info & 0xFF}"
puts "Firmware: #{firmware_version >> 8}.#{firmware_version & 0xFF}"
puts "Lifetime (ms): #{lifetime_ms}"
puts "Chip ID: #{chip_id}"
puts "RTC adjustment: #{rtc_tcr}"
puts format('Clock: %04d-%02d-%02d %02d:%02d:%02d', year, month, day, hour, minute, second)

# Close connection to serial port
port.close
'''
Python version: 3.8.10
Modules:
Pyserial version: 3.4
Requires pyserial module:
    pip3 install pyserial
'''

import serial

def ekm_crc16(data):
    """CRC-16/MODBUS of data. Returns the 2 CRC bytes, low byte first."""
    crc = 0xFFFF
    for b in data:
        crc ^= b
        for _ in range(8):
            crc = (crc >> 1) ^ 0xA001 if crc & 1 else crc >> 1
    return bytes([crc & 0xFF, (crc >> 8) & 0xFF])

def be(value, size):
    """Big-endian bytes of value, size bytes long."""
    return (value & ((1 << (8 * size)) - 1)).to_bytes(size, 'big')


def padded(text, size):
    """Text as bytes, NUL-padded to size bytes."""
    return text.encode('ascii')[:size].ljust(size, b'\x00')


def build_request(sn, opcode, body=b''):
    """Builds one request frame: 0x43, serial number, opcode, body length, body, CRC."""
    msg = b'\x43' + be(sn, 5) + bytes([opcode, len(body)]) + body
    return msg + ekm_crc16(msg)

def read_response(port):
    """Reads one response frame and checks its CRC."""
    # The first 8 bytes are the header. Byte 7 is the length of the body
    header = port.read(8)
    if len(header) < 8:
        raise IOError('Connection timed out!')
    body_len = header[7]

    # The rest of the frame is the body and the 2 CRC bytes
    rest = port.read(body_len + 2)
    if len(rest) < body_len + 2:
        raise IOError('Connection timed out!')
    frame = header + rest

    # The CRC covers every byte before the CRC itself
    if ekm_crc16(frame[:-2]) != frame[-2:]:
        raise IOError('Bad CRC in response!')
    return {'opcode': frame[0], 'rc': frame[6], 'body': frame[8:8 + body_len], 'frame': frame}

def be_uint(body, pos, size):
    """Unsigned big-endian integer from size bytes at pos."""
    return int.from_bytes(body[pos:pos + size], 'big')


def be_int(body, pos, size):
    """Signed big-endian integer from size bytes at pos."""
    return int.from_bytes(body[pos:pos + size], 'big', signed=True)


def be_str(body, pos, size):
    """NUL-padded text from size bytes at pos."""
    return body[pos:pos + size].split(b'\x00', 1)[0].decode('ascii', errors='replace')


def be_hex(body, pos, size):
    """Hex string from size bytes at pos."""
    return body[pos:pos + size].hex()

# Open connection to serial port
# Change /dev/ttyUSB0 to match your system
port = serial.Serial(
    port='/dev/ttyUSB0',
    baudrate=9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    xonxoff=0,
    timeout=5  # seconds to wait for a response
)

# In this code example we make a simple function that takes the opcode and the body of
# the request you want to send to the ioStack. It builds the frame with its CRC, sends it,
# then gets the response and checks its CRC and its status byte to make sure the response is correct
def send_request(opcode, body=b''):
    port.write(build_request(123456789012, opcode, body))
    rsp = read_response(port)
    if rsp['rc'] != 0x00:
        raise IOError('Request failed: {0:#04x}'.format(rsp['rc']))
    return rsp

# Send Get Status (opcode 0x02, no body)
rsp = send_request(0x02)
body = rsp['body']

# Move through the body field by field. Every field is big-endian
pos = 0
device_info = be_uint(body, pos, 2); pos += 2
firmware_version = be_uint(body, pos, 2); pos += 2
lifetime_ms = be_uint(body, pos, 8); pos += 8
chip_id = be_hex(body, pos, 16); pos += 16
rtc_tcr = be_uint(body, pos, 2); pos += 2
second = be_uint(body, pos, 1); pos += 1
minute = be_uint(body, pos, 1); pos += 1
hour = be_uint(body, pos, 1); pos += 1
day = be_uint(body, pos, 1); pos += 1
month = be_uint(body, pos, 1); pos += 1
year = be_uint(body, pos, 2); pos += 2

# Show the fields
print('Device type:', device_info >> 8, 'model:', device_info & 0xFF)
print('Firmware: {0}.{1}'.format(firmware_version >> 8, firmware_version & 0xFF))
print('Lifetime (ms):', lifetime_ms)
print('Chip ID:', chip_id)
print('RTC adjustment:', rtc_tcr)
print('Clock: {0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'.format(year, month, day, hour, minute, second))

# Close connection to serial port
port.close()
<?php
/*
* Requirements:
* PHP: 8.1.5
* DIO: 0.2.1
*
* Install php8.1-dev on ubuntu to compile DIO module.
* apt install php8.1-dev
* Compile DIO module from source:
* Download the latest tarball from: https://pecl.php.net/package/dio
* Uncompress: tar xfz dio-0.2.1.tgz
* cd dio-0.2.1/
* phpize
* ./configure
* make
* sudo make install
* You will see a path like: /usr/lib/php/20210902/
* Edit your php.ini
* vi /etc/php/8.1/cli/php.ini
* In the extension section add:
* extension=/usr/lib/php/20210902/dio.so
* Now you can run your php script.
* Ex: php connect.php
*/

// CRC-16/MODBUS of $data. Returns the 2 CRC bytes, low byte first.
function ekm_crc16(string $data): string {
    $crc = 0xFFFF;
    for ($i = 0; $i < strlen($data); $i++) {
        $crc ^= ord($data[$i]);
        for ($j = 0; $j < 8; $j++) {
            $crc = ($crc & 1) ? (($crc >> 1) ^ 0xA001) : ($crc >> 1);
        }
    }
    return chr($crc & 0xFF) . chr(($crc >> 8) & 0xFF);
}

// Big-endian bytes of $value, $size bytes long
function be(int $value, int $size): string {
    $out = '';
    for ($i = $size - 1; $i >= 0; $i--) {
        $out .= chr(($value >> (8 * $i)) & 0xFF);
    }
    return $out;
}

// Text as bytes, NUL-padded to $size bytes
function padded(string $text, int $size): string {
    return str_pad(substr($text, 0, $size), $size, "\0");
}

// Builds one request frame: 0x43, serial number, opcode, body length, body, CRC
function build_request(int $sn, int $opcode, string $body = ''): string {
    $msg = chr(0x43) . be($sn, 5) . chr($opcode) . chr(strlen($body)) . $body;
    return $msg . ekm_crc16($msg);
}

// Reads exactly $n bytes from the port. Gives up after 5 seconds.
function read_bytes($port, int $n, int $timeout = 5): string {
    $data = '';
    $end = time() + $timeout;
    while (strlen($data) < $n && time() < $end) {
        $chunk = dio_read($port, $n - strlen($data));
        if ($chunk === false || $chunk === null || $chunk === '') {
            usleep(10000);
        } else {
            $data .= $chunk;
        }
    }
    if (strlen($data) < $n) {
        throw new RuntimeException('Connection timed out!');
    }
    return $data;
}

// Reads one response frame and checks its CRC
function read_response($port): array {
    // The first 8 bytes are the header. Byte 7 is the length of the body
    $header = read_bytes($port, 8);
    $body_len = ord($header[7]);

    // The rest of the frame is the body and the 2 CRC bytes
    $frame = $header . read_bytes($port, $body_len + 2);

    // The CRC covers every byte before the CRC itself
    if (ekm_crc16(substr($frame, 0, -2)) !== substr($frame, -2)) {
        throw new RuntimeException('Bad CRC in response!');
    }
    return ['opcode' => ord($frame[0]), 'rc' => ord($frame[6]), 'body' => substr($frame, 8, $body_len), 'frame' => $frame];
}

// Unsigned big-endian integer from $size bytes at $pos
function be_uint(string $body, int $pos, int $size): int {
    $v = 0;
    for ($i = 0; $i < $size; $i++) {
        $v = $v * 256 + ord($body[$pos + $i]);
    }
    return $v;
}

// Signed big-endian integer from $size bytes at $pos
function be_int(string $body, int $pos, int $size): int {
    $v = be_uint($body, $pos, $size);
    return $v >= (1 << (8 * $size - 1)) ? $v - (1 << (8 * $size)) : $v;
}

// NUL-padded text from $size bytes at $pos
function be_str(string $body, int $pos, int $size): string {
    return explode("\0", substr($body, $pos, $size), 2)[0];
}

// Hex string from $size bytes at $pos
function be_hex(string $body, int $pos, int $size): string {
    return bin2hex(substr($body, $pos, $size));
}

// Open connection to serial port
// Change /dev/ttyUSB0 to match your system
$port = dio_open('/dev/ttyUSB0', O_RDWR | O_NONBLOCK);

// Configure the port
dio_tcsetattr($port, array(
   'baud'         => 9600,
   'bits'         => 8,
   'stop'         => 1,
   'parity'       => 0,
   'flow_control' => 0,
   'is_canonical' => 0
));

// In this code example we make a simple function that takes the opcode and the body of
// the request you want to send to the ioStack. It builds the frame with its CRC, sends it,
// then gets the response and checks its CRC and its status byte to make sure the response is correct
function send_request($port, int $opcode, string $body = ''): array {
    dio_write($port, build_request(123456789012, $opcode, $body));
    $rsp = read_response($port);
    if ($rsp['rc'] !== 0x00) {
        throw new RuntimeException(sprintf('Request failed: 0x%02X', $rsp['rc']));
    }
    return $rsp;
}

// Send Get Status (opcode 0x02, no body)
$rsp = send_request($port, 0x02);
$body = $rsp['body'];

// Move through the body field by field. Every field is big-endian
$pos = 0;
$device_info = be_uint($body, $pos, 2); $pos += 2;
$firmware_version = be_uint($body, $pos, 2); $pos += 2;
$lifetime_ms = be_uint($body, $pos, 8); $pos += 8;
$chip_id = be_hex($body, $pos, 16); $pos += 16;
$rtc_tcr = be_uint($body, $pos, 2); $pos += 2;
$second = be_uint($body, $pos, 1); $pos += 1;
$minute = be_uint($body, $pos, 1); $pos += 1;
$hour = be_uint($body, $pos, 1); $pos += 1;
$day = be_uint($body, $pos, 1); $pos += 1;
$month = be_uint($body, $pos, 1); $pos += 1;
$year = be_uint($body, $pos, 2); $pos += 2;

// Show the fields
echo 'Device type: ' . ($device_info >> 8) . ' model: ' . ($device_info & 0xFF) . "\n";
echo 'Firmware: ' . ($firmware_version >> 8) . '.' . ($firmware_version & 0xFF) . "\n";
echo "Lifetime (ms): $lifetime_ms\n";
echo "Chip ID: $chip_id\n";
echo "RTC adjustment: $rtc_tcr\n";
printf("Clock: %04d-%02d-%02d %02d:%02d:%02d\n", $year, $month, $day, $hour, $minute, $second);

// Close connection to serial port
dio_close($port);

?>
#!/usr/bin/perl
# Perl version: v5.30.0
# CPAN.pm version v2.34
#
# Requires the Device::SerialPort module
# Device::SerialPort: 1.04
#
# Install Perl Modules
#       cpan Device::SerialPort

use strict;
use warnings;
use Device::SerialPort;

# CRC-16/MODBUS of $data. Returns the 2 CRC bytes, low byte first.
sub ekm_crc16 {
    my ($data) = @_;
    my $crc = 0xFFFF;
    for my $b (unpack 'C*', $data) {
        $crc ^= $b;
        for (1 .. 8) {
            $crc = ($crc & 1) ? (($crc >> 1) ^ 0xA001) : ($crc >> 1);
        }
    }
    return pack('C2', $crc & 0xFF, ($crc >> 8) & 0xFF);
}

# Big-endian bytes of $value, $size bytes long
sub be {
    my ($value, $size) = @_;
    return join '', map { chr(($value >> (8 * ($size - 1 - $_))) & 0xFF) } 0 .. $size - 1;
}

# Text as bytes, NUL-padded to $size bytes
sub padded {
    my ($text, $size) = @_;
    return pack("a$size", $text);
}

# Builds one request frame: 0x43, serial number, opcode, body length, body, CRC
sub build_request {
    my ($sn, $opcode, $body) = @_;
    $body //= '';
    my $msg = chr(0x43) . be($sn, 5) . pack('C2', $opcode, length $body) . $body;
    return $msg . ekm_crc16($msg);
}

# Reads exactly $n bytes from the port. Gives up after 5 seconds.
sub read_bytes {
    my ($port, $n) = @_;
    my $timeout = 5;
    my $data = '';
    while (length($data) < $n && $timeout > 0) {
        my ($count, $read) = $port->read($n - length($data));
        if ($count > 0) {
            $data .= $read;
        }
        else {
            $timeout--;
        }
    }
    die "Connection timed out!\n" if length($data) < $n;
    return $data;
}

# Reads one response frame and checks its CRC
sub read_response {
    my ($port) = @_;

    # The first 8 bytes are the header. Byte 7 is the length of the body
    my $header = read_bytes($port, 8);
    my $body_len = ord(substr($header, 7, 1));

    # The rest of the frame is the body and the 2 CRC bytes
    my $frame = $header . read_bytes($port, $body_len + 2);

    # The CRC covers every byte before the CRC itself
    die "Bad CRC in response!\n" unless ekm_crc16(substr($frame, 0, -2)) eq substr($frame, -2);
    return {
        opcode => ord(substr($frame, 0, 1)),
        rc     => ord(substr($frame, 6, 1)),
        body   => substr($frame, 8, $body_len),
        frame  => $frame,
    };
}

# Unsigned big-endian integer from $size bytes at $pos
sub be_uint {
    my ($body, $pos, $size) = @_;
    my $v = 0;
    $v = $v * 256 + ord(substr($body, $_, 1)) for $pos .. $pos + $size - 1;
    return $v;
}

# Signed big-endian integer from $size bytes at $pos
sub be_int {
    my ($body, $pos, $size) = @_;
    my $v = be_uint($body, $pos, $size);
    return $v >= 2 ** (8 * $size - 1) ? $v - 2 ** (8 * $size) : $v;
}

# NUL-padded text from $size bytes at $pos
sub be_str {
    my ($body, $pos, $size) = @_;
    my ($text) = split /\0/, substr($body, $pos, $size), 2;
    return defined $text ? $text : '';
}

# Hex string from $size bytes at $pos
sub be_hex {
    my ($body, $pos, $size) = @_;
    return unpack('H*', substr($body, $pos, $size));
}

# Open connection to serial port
# Change /dev/ttyUSB0 to match your system
my $port = Device::SerialPort->new('/dev/ttyUSB0') or die "Cannot open /dev/ttyUSB0\n";

# Configure the port
$port->baudrate(9600);
$port->parity('none');
$port->databits(8);
$port->stopbits(1);
$port->handshake('none');
$port->write_settings;

# don't wait for each character
$port->read_char_time(0);

# wait for 1 second per unfulfilled read
$port->read_const_time(1000);

# In this code example we make a simple function that takes the opcode and the body of
# the request you want to send to the ioStack. It builds the frame with its CRC, sends it,
# then gets the response and checks its CRC and its status byte to make sure the response is correct
sub send_request {
    my ($port, $opcode, $body) = @_;
    $port->write(build_request(123456789012, $opcode, $body));
    my $rsp = read_response($port);
    die sprintf("Request failed: 0x%02X\n", $rsp->{rc}) unless $rsp->{rc} == 0x00;
    return $rsp;
}

# Send Get Status (opcode 0x02, no body)
my $rsp = send_request($port, 0x02);
my $body = $rsp->{body};

# Move through the body field by field. Every field is big-endian
my $pos = 0;
my $device_info = be_uint($body, $pos, 2); $pos += 2;
my $firmware_version = be_uint($body, $pos, 2); $pos += 2;
my $lifetime_ms = be_uint($body, $pos, 8); $pos += 8;
my $chip_id = be_hex($body, $pos, 16); $pos += 16;
my $rtc_tcr = be_uint($body, $pos, 2); $pos += 2;
my $second = be_uint($body, $pos, 1); $pos += 1;
my $minute = be_uint($body, $pos, 1); $pos += 1;
my $hour = be_uint($body, $pos, 1); $pos += 1;
my $day = be_uint($body, $pos, 1); $pos += 1;
my $month = be_uint($body, $pos, 1); $pos += 1;
my $year = be_uint($body, $pos, 2); $pos += 2;

# Show the fields
print 'Device type: ', $device_info >> 8, ' model: ', $device_info & 0xFF, "\n";
print 'Firmware: ', $firmware_version >> 8, '.', $firmware_version & 0xFF, "\n";
print "Lifetime (ms): $lifetime_ms\n";
print "Chip ID: $chip_id\n";
print "RTC adjustment: $rtc_tcr\n";
printf "Clock: %04d-%02d-%02d %02d:%02d:%02d\n", $year, $month, $day, $hour, $minute, $second;

# Close connection to serial port
$port->close;
undef $port;
/*
 openjdk version "17.0.2" 2022-01-18
 Download the jssc.jar (java-simple-serial-connector)
 from: https://code.google.com/archive/p/java-simple-serial-connector/
 Version: jSSC-2.8.0

 Instructions to run this program

 1. Put this code in a file named ParseResponses.java
 2. Copy the downloaded jssc.jar and ParseResponses.java to the same directory
 3. Compile
  javac -cp .:./jssc.jar ./ParseResponses.java
 4. Run
  java -cp .:./jssc.jar ParseResponses
*/

// Import required classes
import jssc.*;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class ParseResponses {

    // CRC-16/MODBUS of data. Returns the 2 CRC bytes, low byte first.
    static byte[] crc16(byte[] data) {
        int crc = 0xFFFF;
        for (byte b : data) {
            crc ^= (b & 0xFF);
            for (int i = 0; i < 8; i++) {
                crc = (crc & 1) != 0 ? (crc >> 1) ^ 0xA001 : crc >> 1;
            }
        }
        return new byte[] { (byte) (crc & 0xFF), (byte) ((crc >> 8) & 0xFF) };
    }

    // Big-endian bytes of value, size bytes long
    static byte[] be(long value, int size) {
        byte[] out = new byte[size];
        for (int i = size - 1; i >= 0; i--) {
            out[i] = (byte) (value & 0xFF);
            value >>= 8;
        }
        return out;
    }

    // Text as bytes, NUL-padded to size bytes
    static byte[] padded(String text, int size) {
        byte[] out = new byte[size];
        byte[] src = text.getBytes(StandardCharsets.US_ASCII);
        System.arraycopy(src, 0, out, 0, Math.min(src.length, size));
        return out;
    }

    // Joins byte arrays one after the other
    static byte[] concat(byte[]... parts) {
        int total = 0;
        for (byte[] p : parts) total += p.length;
        byte[] out = new byte[total];
        int pos = 0;
        for (byte[] p : parts) {
            System.arraycopy(p, 0, out, pos, p.length);
            pos += p.length;
        }
        return out;
    }

    // Builds one request frame: 0x43, serial number, opcode, body length, body, CRC
    static byte[] buildRequest(long sn, int opcode, byte[]... body) {
        byte[] payload = body.length > 0 ? body[0] : new byte[0];
        byte[] msg = concat(new byte[] { 0x43 }, be(sn, 5), new byte[] { (byte) opcode, (byte) payload.length }, payload);
        return concat(msg, crc16(msg));
    }

    // Bytes as a string of hex pairs
    static String toHex(byte[] data) {
        StringBuilder sb = new StringBuilder();
        for (byte b : data) {
            sb.append(String.format("%02x ", b & 0xFF));
        }
        return sb.toString().trim();
    }

    // Reads one response frame and checks its CRC
    static byte[] readResponse(SerialPort port) throws Exception {
        // The first 8 bytes are the header. Byte 7 is the length of the body
        byte[] header = port.readBytes(8, 5000);
        int bodyLen = header[7] & 0xFF;

        // The rest of the frame is the body and the 2 CRC bytes
        byte[] frame = concat(header, port.readBytes(bodyLen + 2, 5000));

        // The CRC covers every byte before the CRC itself
        byte[] crc = Arrays.copyOfRange(frame, frame.length - 2, frame.length);
        if (!Arrays.equals(crc, crc16(Arrays.copyOfRange(frame, 0, frame.length - 2)))) {
            throw new Exception("Bad CRC in response!");
        }
        return frame;
    }

    // Unsigned big-endian integer from size bytes at pos
    static long beUInt(byte[] body, int pos, int size) {
        long v = 0;
        for (int i = 0; i < size; i++) {
            v = (v << 8) | (body[pos + i] & 0xFF);
        }
        return v;
    }

    // Signed big-endian integer from size bytes at pos
    static long beInt(byte[] body, int pos, int size) {
        long v = beUInt(body, pos, size);
        return v >= (1L << (8 * size - 1)) ? v - (1L << (8 * size)) : v;
    }

    // NUL-padded text from size bytes at pos
    static String beStr(byte[] body, int pos, int size) {
        String s = new String(body, pos, size, StandardCharsets.US_ASCII);
        int z = s.indexOf('\0');
        return z >= 0 ? s.substring(0, z) : s;
    }

    // Hex string from size bytes at pos
    static String beHex(byte[] body, int pos, int size) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < size; i++) {
            sb.append(String.format("%02x", body[pos + i] & 0xFF));
        }
        return sb.toString();
    }

    // In this code example we make a simple function that takes the opcode and the body of
    // the request you want to send to the ioStack. It builds the frame with its CRC, sends it,
    // then gets the response and checks its CRC and its status byte to make sure the response is correct
    static byte[] sendRequest(SerialPort port, int opcode, byte[]... body) throws Exception {
        port.writeBytes(buildRequest(123456789012L, opcode, body));
        byte[] frame = readResponse(port);
        if ((frame[6] & 0xFF) != 0x00) {
            throw new Exception(String.format("Request failed: 0x%02X", frame[6] & 0xFF));
        }
        return frame;
    }

    public static void main(String[] args) throws Exception {
        SerialPort port = new SerialPort("/dev/ttyUSB0");
        try {
            // Open connection to serial port
            // Change /dev/ttyUSB0 to match your system
            port.openPort();

            // Configure the port
            port.setParams(SerialPort.BAUDRATE_9600,
                           SerialPort.DATABITS_8,
                           SerialPort.STOPBITS_1,
                           SerialPort.PARITY_NONE);
            port.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);

            // Send Get Status (opcode 0x02, no body)
            byte[] frame = sendRequest(port, 0x02);
            byte[] body = Arrays.copyOfRange(frame, 8, frame.length - 2);

            // Move through the body field by field. Every field is big-endian
            int pos = 0;
            long deviceInfo = beUInt(body, pos, 2); pos += 2;
            long firmwareVersion = beUInt(body, pos, 2); pos += 2;
            long lifetimeMs = beUInt(body, pos, 8); pos += 8;
            String chipId = beHex(body, pos, 16); pos += 16;
            long rtcTcr = beUInt(body, pos, 2); pos += 2;
            long second = beUInt(body, pos, 1); pos += 1;
            long minute = beUInt(body, pos, 1); pos += 1;
            long hour = beUInt(body, pos, 1); pos += 1;
            long day = beUInt(body, pos, 1); pos += 1;
            long month = beUInt(body, pos, 1); pos += 1;
            long year = beUInt(body, pos, 2); pos += 2;

            // Show the fields
            System.out.println("Device type: " + (deviceInfo >> 8) + " model: " + (deviceInfo & 0xFF));
            System.out.println("Firmware: " + (firmwareVersion >> 8) + "." + (firmwareVersion & 0xFF));
            System.out.println("Lifetime (ms): " + lifetimeMs);
            System.out.println("Chip ID: " + chipId);
            System.out.println("RTC adjustment: " + rtcTcr);
            System.out.println(String.format("Clock: %04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second));

            // Close connection to serial port
            port.closePort();
        }
        catch (SerialPortTimeoutException ex) {
            System.out.println("Connection Timed out");
        }
        catch (SerialPortException ex) {
            System.out.println(ex);
        }
    }
}
/*
* Requirements
* NodeJS: v16.15.0
* Serialport: 10.4.0
*/

// Load modules
const {SerialPort} = require('serialport');

// CRC-16/MODBUS of data. Returns the 2 CRC bytes, low byte first.
const crc16 = (data) => {
  let crc = 0xFFFF;
  for (const b of data) {
    crc ^= b;
    for (let i = 0; i < 8; i++) {
      crc = (crc & 1) ? (crc >> 1) ^ 0xA001 : crc >> 1;
    }
  }
  return Buffer.from([crc & 0xFF, (crc >> 8) & 0xFF]);
};

// Big-endian bytes of value, size bytes long
const be = (value, size) => {
  const out = Buffer.alloc(size);
  for (let i = size - 1; i >= 0; i--) {
    out[i] = value % 256;
    value = Math.floor(value / 256);
  }
  return out;
};

// Text as bytes, NUL-padded to size bytes
const padded = (text, size) => {
  const out = Buffer.alloc(size);
  Buffer.from(text, 'ascii').copy(out, 0, 0, size);
  return out;
};

// Builds one request frame: 0x43, serial number, opcode, body length, body, CRC
const buildRequest = (sn, opcode, body = Buffer.alloc(0)) => {
  const msg = Buffer.concat([Buffer.from([0x43]), be(sn, 5), Buffer.from([opcode, body.length]), body]);
  return Buffer.concat([msg, crc16(msg)]);
};

// Bytes as a string of hex pairs
const toHex = (data) => [...data].map((b) => b.toString(16).padStart(2, '0')).join(' ');

// Reads one response frame and checks its CRC. Resolves with the whole frame as a Buffer.
const readResponse = (port, timeoutMs = 5000) => new Promise((resolve, reject) => {
  let buf = Buffer.alloc(0);
  const onData = (chunk) => {
    buf = Buffer.concat([buf, chunk]);

    // The first 8 bytes are the header. Byte 7 is the length of the body
    if (buf.length < 8) return;

    // The rest of the frame is the body and the 2 CRC bytes
    const total = 8 + buf[7] + 2;
    if (buf.length < total) return;
    clearTimeout(timer);
    port.off('data', onData);
    const frame = buf.subarray(0, total);

    // The CRC covers every byte before the CRC itself
    if (!crc16(frame.subarray(0, -2)).equals(frame.subarray(-2))) {
      reject(new Error('Bad CRC in response!'));
    } else {
      resolve(frame);
    }
  };
  const timer = setTimeout(() => {
    port.off('data', onData);
    reject(new Error('Connection timed out!'));
  }, timeoutMs);
  port.on('data', onData);
});

// Unsigned big-endian integer from size bytes at pos
const beUInt = (body, pos, size) => {
  let v = 0;
  for (let i = 0; i < size; i++) v = v * 256 + body[pos + i];
  return v;
};

// Signed big-endian integer from size bytes at pos
const beInt = (body, pos, size) => {
  const v = beUInt(body, pos, size);
  return v >= 2 ** (8 * size - 1) ? v - 2 ** (8 * size) : v;
};

// NUL-padded text from size bytes at pos
const beStr = (body, pos, size) => body.subarray(pos, pos + size).toString('ascii').split('\0')[0];

// Hex string from size bytes at pos
const beHex = (body, pos, size) => body.subarray(pos, pos + size).toString('hex');

// Params for Serial Port
// Change path to match your system
const port = new SerialPort({
  path: '/dev/ttyUSB0',
  baudRate: 9600,
  parity: 'none',
  dataBits: 8,
  stopBits: 1,
});

// In this code example we make a simple function that takes the opcode and the body of
// the request you want to send to the ioStack. It builds the frame with its CRC, sends it,
// then gets the response and checks its CRC and its status byte to make sure the response is correct
const sendRequest = async (opcode, body = Buffer.alloc(0)) => {
  port.write(buildRequest(123456789012, opcode, body));
  const frame = await readResponse(port);
  if (frame[6] !== 0x00) throw new Error(`Request failed: 0x${frame[6].toString(16)}`);
  return frame;
};

// Start ioStack communication
;(async () => {
  // Wait for the port to open
  await new Promise((resolve, reject) => { port.once('open', resolve); port.once('error', reject); });
  console.log('Connection Opened');

  // Send Get Status (opcode 0x02, no body)
  const frame = await sendRequest(0x02);
  const body = frame.subarray(8, frame.length - 2);

  // Move through the body field by field. Every field is big-endian
  let pos = 0;
  const deviceInfo = beUInt(body, pos, 2); pos += 2;
  const firmwareVersion = beUInt(body, pos, 2); pos += 2;
  const lifetimeMs = beUInt(body, pos, 8); pos += 8;
  const chipId = beHex(body, pos, 16); pos += 16;
  const rtcTcr = beUInt(body, pos, 2); pos += 2;
  const second = beUInt(body, pos, 1); pos += 1;
  const minute = beUInt(body, pos, 1); pos += 1;
  const hour = beUInt(body, pos, 1); pos += 1;
  const day = beUInt(body, pos, 1); pos += 1;
  const month = beUInt(body, pos, 1); pos += 1;
  const year = beUInt(body, pos, 2); pos += 2;

  // Show the fields
  const p2 = (n) => String(n).padStart(2, '0');
  console.log(`Device type: ${deviceInfo >> 8} model: ${deviceInfo & 0xFF}`);
  console.log(`Firmware: ${firmwareVersion >> 8}.${firmwareVersion & 0xFF}`);
  console.log(`Lifetime (ms): ${lifetimeMs}`);
  console.log(`Chip ID: ${chipId}`);
  console.log(`RTC adjustment: ${rtcTcr}`);
  console.log(`Clock: ${year}-${p2(month)}-${p2(day)} ${p2(hour)}:${p2(minute)}:${p2(second)}`);

  // Close connection to serial port
  port.close();
})();

For security reasons browsers have very limited access to the machines resources, writing browser ran Javascript (client-side) is not a viable option

The above example returns the following results:


Device type: 133 model: 1
Firmware: 1.2
Lifetime (ms): 86400000
Chip ID: a1b2c3d4e5f60718293a4b5c6d7e8f90
RTC adjustment: 5
Clock: 2026-11-27 12:15:30

Device type: 133 model: 1
Firmware: 1.2
Lifetime (ms): 86400000
Chip ID: a1b2c3d4e5f60718293a4b5c6d7e8f90
RTC adjustment: 5
Clock: 2026-11-27 12:15:30

Device type: 133 model: 1
Firmware: 1.2
Lifetime (ms): 86400000
Chip ID: a1b2c3d4e5f60718293a4b5c6d7e8f90
RTC adjustment: 5
Clock: 2026-11-27 12:15:30

Device type: 133 model: 1
Firmware: 1.2
Lifetime (ms): 86400000
Chip ID: a1b2c3d4e5f60718293a4b5c6d7e8f90
RTC adjustment: 5
Clock: 2026-11-27 12:15:30

Device type: 133 model: 1
Firmware: 1.2
Lifetime (ms): 86400000
Chip ID: a1b2c3d4e5f60718293a4b5c6d7e8f90
RTC adjustment: 5
Clock: 2026-11-27 12:15:30

Device type: 133 model: 1
Firmware: 1.2
Lifetime (ms): 86400000
Chip ID: a1b2c3d4e5f60718293a4b5c6d7e8f90
RTC adjustment: 5
Clock: 2026-11-27 12:15:30

Device type: 133 model: 1
Firmware: 1.2
Lifetime (ms): 86400000
Chip ID: a1b2c3d4e5f60718293a4b5c6d7e8f90
RTC adjustment: 5
Clock: 2026-11-27 12:15:30

Parsing Responses

Each response is one frame. The frame is:

Byte Field
0 Opcode of the request that is answered
1-5 Serial number, 5 bytes, big-endian
6 Status byte (0x00 is OK)
7 Body length, 0 to 255
8 to n Body
last 2 CRC-16/MODBUS of all bytes before it, low byte first

The final step. Parsing the ioStack response

The body is a row of fields, one right after the other. Each field is big-endian and has a fixed size, given in the table of each request. To parse the body, start at position 0, read a field with its size, then move the position forward by that size. For lists, repeat the read as many times as the count field says.

The be_uint, be_int, be_str and be_hex functions read an unsigned number, a signed number, NUL-padded text and raw bytes (as hex). The example above reads the Get Status response with them.

For example the Get Status response body of the sample above is:

Field Bytes Value Description
DeviceInfo 2 85 01 Device type (1 byte) and model number (1 byte)
FirmwareVersion 2 01 02 Major (1 byte) and minor (1 byte) version
LifetimeMS 8 00 00 00 00 05 26 5C 00 Milliseconds since the chip was first started
ChipID 16 A1 B2 ... 8F 90 Unique chip ID, embedded in the chip
RTC_TCR 2 00 05 Real-time clock adjustment value
Second 1 1E Seconds, 0-59
Minute 1 0F Minutes, 0-59
Hour 1 0C Hours, 0-23
Day 1 1B Day of month, 1-31
Month 1 0B Month, 1-12
Year 2 07 EA Year, for example 2026

The status byte

The status byte in every response tells you whether the command ran. When it is not 0x00, the body is empty. Check it before you read the body.

Code Name Meaning
0x00 OK The command succeeded
0x01 Cleared previous watch Success. A previous watch on the pin was cleared
0x02 OneWire IDs full The OneWire known-ID list is full
0x81 CRC error The CRC in the request is wrong
0x82 Unknown opcode The command does not exist
0x83 Length error The body length does not match the command
0x84 Security error The password is wrong, or a special condition blocked the command
0x85 Parameter error A value in the body is out of range
0x86 DI increment error The pulse increment is too large
0x87 Unavailable The command cannot run on this hardware
0x91 No watch found No watch is set on that pin
0x92 No waveform found No waveform is set on that digital output
0x93 DO busy The digital output is busy
0x94 DI busy The digital input is busy
0x95 Update block error A firmware update block number is wrong
0x96 OneWire ID error The OneWire slot ID is not available
0xFB NVRAM verify error The value written to memory did not read back correctly
0xFC NVRAM update error Writing to memory failed. The old value was restored
0xFD Process error The firmware could not complete the action
0xFE Internal error An internal error occurred. This should not happen

The requests in the sections that follow use the functions from the Sending Requests and Parsing Responses sections.

General Requests

Example: Echo

# Echo to serial number 123456789012 (opcode 0x01)
printf '\x43\x1c\xbe\x99\x1a\x14\x01\x05\x68\x65\x6c\x6c\x6f\xec\x41' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  padded('hello', 5),
].join

# Send the request (opcode 0x01)
port.write(build_request(123456789012, 0x01, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Echo failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
body = be_str(rsp_body, pos, 5)
pos += 5
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    padded('hello', 5),
])

# Send the request (opcode 0x01)
port.write(build_request(123456789012, 0x01, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Echo failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
body = be_str(rsp_body, pos, 5)
pos += 5
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    padded('hello', 5),
]);

// Send the request (opcode 0x01)
dio_write($port, build_request(123456789012, 0x01, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Echo failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$body = be_str($rsp_body, $pos, 5);
$pos += 5;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  padded('hello', 5),
);

# Send the request (opcode 0x01)
$port->write(build_request(123456789012, 0x01, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Echo failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $body = be_str($rsp_body, $pos, 5);
$pos += 5;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    padded("hello", 5)
);

// Send the request (opcode 0x01)
port.writeBytes(buildRequest(123456789012L, 0x01, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Echo failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var body = beStr(rspBody, pos, 5);
pos += 5;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    padded('hello', 5),
  ]);

  // Send the request (opcode 0x01)
  port.write(buildRequest(123456789012, 0x01, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Echo failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const body = beStr(rspBody, pos, 5);
  pos += 5;
})();

Echo

Returns the request body unchanged. Use it to test that the link works.

Opcode: 0x01. Body length: 1 to 255.

Request body

Field Bytes Description
Body 5 Any text, 1 to 255 bytes. The example sends hello.

Response body

Field Bytes Description
Body 5 The same bytes that were sent.

Example: Get Status

# Get Status to serial number 123456789012 (opcode 0x02)
printf '\x43\x1c\xbe\x99\x1a\x14\x02\x00\x98\x91' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x02, no body)
port.write(build_request(123456789012, 0x02))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Get Status failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
device_info = be_uint(rsp_body, pos, 2)
pos += 2
firmware_version = be_uint(rsp_body, pos, 2)
pos += 2
lifetime_ms = be_uint(rsp_body, pos, 8)
pos += 8
chip_id = be_hex(rsp_body, pos, 16)
pos += 16
rtc_tcr = be_uint(rsp_body, pos, 2)
pos += 2
second = be_uint(rsp_body, pos, 1)
pos += 1
minute = be_uint(rsp_body, pos, 1)
pos += 1
hour = be_uint(rsp_body, pos, 1)
pos += 1
day = be_uint(rsp_body, pos, 1)
pos += 1
month = be_uint(rsp_body, pos, 1)
pos += 1
year = be_uint(rsp_body, pos, 2)
pos += 2
# Send the request (opcode 0x02, no body)
port.write(build_request(123456789012, 0x02))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Get Status failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
device_info = be_uint(rsp_body, pos, 2)
pos += 2
firmware_version = be_uint(rsp_body, pos, 2)
pos += 2
lifetime_ms = be_uint(rsp_body, pos, 8)
pos += 8
chip_id = be_hex(rsp_body, pos, 16)
pos += 16
rtc_tcr = be_uint(rsp_body, pos, 2)
pos += 2
second = be_uint(rsp_body, pos, 1)
pos += 1
minute = be_uint(rsp_body, pos, 1)
pos += 1
hour = be_uint(rsp_body, pos, 1)
pos += 1
day = be_uint(rsp_body, pos, 1)
pos += 1
month = be_uint(rsp_body, pos, 1)
pos += 1
year = be_uint(rsp_body, pos, 2)
pos += 2
// Send the request (opcode 0x02, no body)
dio_write($port, build_request(123456789012, 0x02));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Get Status failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$device_info = be_uint($rsp_body, $pos, 2);
$pos += 2;
$firmware_version = be_uint($rsp_body, $pos, 2);
$pos += 2;
$lifetime_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
$chip_id = be_hex($rsp_body, $pos, 16);
$pos += 16;
$rtc_tcr = be_uint($rsp_body, $pos, 2);
$pos += 2;
$second = be_uint($rsp_body, $pos, 1);
$pos += 1;
$minute = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hour = be_uint($rsp_body, $pos, 1);
$pos += 1;
$day = be_uint($rsp_body, $pos, 1);
$pos += 1;
$month = be_uint($rsp_body, $pos, 1);
$pos += 1;
$year = be_uint($rsp_body, $pos, 2);
$pos += 2;
# Send the request (opcode 0x02, no body)
$port->write(build_request(123456789012, 0x02));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Get Status failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $device_info = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $firmware_version = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $lifetime_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
my $chip_id = be_hex($rsp_body, $pos, 16);
$pos += 16;
my $rtc_tcr = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $second = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $minute = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hour = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $day = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $month = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $year = be_uint($rsp_body, $pos, 2);
$pos += 2;
// Send the request (opcode 0x02, no body)
port.writeBytes(buildRequest(123456789012L, 0x02));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Get Status failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var deviceInfo = beUInt(rspBody, pos, 2);
pos += 2;
var firmwareVersion = beUInt(rspBody, pos, 2);
pos += 2;
var lifetimeMs = beUInt(rspBody, pos, 8);
pos += 8;
var chipId = beHex(rspBody, pos, 16);
pos += 16;
var rtcTcr = beUInt(rspBody, pos, 2);
pos += 2;
var second = beUInt(rspBody, pos, 1);
pos += 1;
var minute = beUInt(rspBody, pos, 1);
pos += 1;
var hour = beUInt(rspBody, pos, 1);
pos += 1;
var day = beUInt(rspBody, pos, 1);
pos += 1;
var month = beUInt(rspBody, pos, 1);
pos += 1;
var year = beUInt(rspBody, pos, 2);
pos += 2;
(async () => {
  // Send the request (opcode 0x02, no body)
  port.write(buildRequest(123456789012, 0x02));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Get Status failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const deviceInfo = beUInt(rspBody, pos, 2);
  pos += 2;
  const firmwareVersion = beUInt(rspBody, pos, 2);
  pos += 2;
  const lifetimeMs = beUInt(rspBody, pos, 8);
  pos += 8;
  const chipId = beHex(rspBody, pos, 16);
  pos += 16;
  const rtcTcr = beUInt(rspBody, pos, 2);
  pos += 2;
  const second = beUInt(rspBody, pos, 1);
  pos += 1;
  const minute = beUInt(rspBody, pos, 1);
  pos += 1;
  const hour = beUInt(rspBody, pos, 1);
  pos += 1;
  const day = beUInt(rspBody, pos, 1);
  pos += 1;
  const month = beUInt(rspBody, pos, 1);
  pos += 1;
  const year = beUInt(rspBody, pos, 2);
  pos += 2;
})();

Get Status

Returns the device type, firmware version, uptime, chip ID, real-time clock adjustment, and the clock. If only one device is on the bus, you can send this with serial number 999999999999 and the device replies with its real serial number. With more than one device on the bus, they all reply at once.

Opcode: 0x02. Body length: 0.

Request body: none.

Response body

Field Bytes Description
DeviceInfo 2 Device type (1 byte) and model number (1 byte).
FirmwareVersion 2 Major (1 byte) and minor (1 byte) version.
LifetimeMS 8 Milliseconds since the chip was first started.
ChipID 16 Unique chip ID, embedded in the chip.
RTC_TCR 2 Real-time clock adjustment value.
Second 1 Seconds, 0-59.
Minute 1 Minutes, 0-59.
Hour 1 Hours, 0-23.
Day 1 Day of month, 1-31.
Month 1 Month, 1-12.
Year 2 Year, for example 2026.

Example: Set Serial Number

# Set Serial Number to serial number 123456789012 (opcode 0x04)
printf '\x43\x1c\xbe\x99\x1a\x14\x04\x09\x00\x00\x00\x00\x1c\xbe\x99\x1a\x15\x22\xab' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 4),
  be(123456789013, 5),
].join

# Send the request (opcode 0x04)
port.write(build_request(123456789012, 0x04, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Set Serial Number failed: 0x%02X', rc) unless rc == 0x00
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 4),
    be(123456789013, 5),
])

# Send the request (opcode 0x04)
port.write(build_request(123456789012, 0x04, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Set Serial Number failed: {rc:#04x}')
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 4),
    be(123456789013, 5),
]);

// Send the request (opcode 0x04)
dio_write($port, build_request(123456789012, 0x04, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Set Serial Number failed: 0x%02X', $rc));
}
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 4),
  be(123456789013, 5),
);

# Send the request (opcode 0x04)
$port->write(build_request(123456789012, 0x04, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Set Serial Number failed: 0x%02X\n", $rc) unless $rc == 0x00;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 4),
    be(123456789013, 5)
);

// Send the request (opcode 0x04)
port.writeBytes(buildRequest(123456789012L, 0x04, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Set Serial Number failed: 0x%02X", rc));
}
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 4),
    be(123456789013, 5),
  ]);

  // Send the request (opcode 0x04)
  port.write(buildRequest(123456789012, 0x04, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Set Serial Number failed: 0x' + rc.toString(16));
})();

Set Serial Number

Changes the serial number that the device answers to. The serial number is 5 bytes, sent big-endian in the frame header, and the highest valid value is 999999999998. The new number is written to NVRAM and read back to check it. The response returns the value read back.

Opcode: 0x04. Body length: 9.

Request body

Field Bytes Description
Password 4 Password, 4 bytes. Always use the factory password 00000000.
NewSerialNumber 5 New 5-byte serial number.

Response body: status only.

Example: Set UART

# Set UART to serial number 123456789012 (opcode 0x05)
printf '\x43\x1c\xbe\x99\x1a\x14\x05\x05\x00\x00\x00\x00\x04\x7a\x76' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 4),
  be(4, 1),
].join

# Send the request (opcode 0x05)
port.write(build_request(123456789012, 0x05, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Set UART failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
rate_index = be_uint(rsp_body, pos, 1)
pos += 1
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 4),
    be(4, 1),
])

# Send the request (opcode 0x05)
port.write(build_request(123456789012, 0x05, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Set UART failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
rate_index = be_uint(rsp_body, pos, 1)
pos += 1
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 4),
    be(4, 1),
]);

// Send the request (opcode 0x05)
dio_write($port, build_request(123456789012, 0x05, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Set UART failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$rate_index = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 4),
  be(4, 1),
);

# Send the request (opcode 0x05)
$port->write(build_request(123456789012, 0x05, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Set UART failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $rate_index = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 4),
    be(4, 1)
);

// Send the request (opcode 0x05)
port.writeBytes(buildRequest(123456789012L, 0x05, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Set UART failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var rateIndex = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 4),
    be(4, 1),
  ]);

  // Send the request (opcode 0x05)
  port.write(buildRequest(123456789012, 0x05, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Set UART failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const rateIndex = beUInt(rspBody, pos, 1);
  pos += 1;
})();

Set UART

Changes the baud rate. The response is sent at the old rate. Change your serial settings to the new rate before you send the next request.

Opcode: 0x05. Body length: 5.

Request body

Field Bytes Description
Password 4 Password, 4 bytes. Always use the factory password 00000000.
RateIndex 1 Baud rate index, 0-5. See the serial settings table.

Response body

Field Bytes Description
RateIndex 1 The index that was set.

Example: Set Name List

# Set Name List to serial number 123456789012 (opcode 0x1E)
printf '\x43\x1c\xbe\x99\x1a\x14\x1e\x8f\x4d\x79\x42\x6f\x61\x72\x64\x00\x00\x00\x00\x54\x61\x6e\x6b\x00\x00\x00\x00\x00\x00\x00\x46\x6c\x6f\x77\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x44\x6f\x6f\x72\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x50\x75\x6d\x70\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc0\x08' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  padded('MyBoard', 11),
  padded('Tank', 11),
  padded('Flow', 11),
  padded('', 11),
  padded('', 11),
  padded('Door', 11),
  padded('', 11),
  padded('', 11),
  padded('Pump', 11),
  padded('', 11),
  padded('', 11),
  padded('', 11),
  padded('', 11),
].join

# Send the request (opcode 0x1E)
port.write(build_request(123456789012, 0x1E, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Set Name List failed: 0x%02X', rc) unless rc == 0x00
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    padded('MyBoard', 11),
    padded('Tank', 11),
    padded('Flow', 11),
    padded('', 11),
    padded('', 11),
    padded('Door', 11),
    padded('', 11),
    padded('', 11),
    padded('Pump', 11),
    padded('', 11),
    padded('', 11),
    padded('', 11),
    padded('', 11),
])

# Send the request (opcode 0x1E)
port.write(build_request(123456789012, 0x1E, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Set Name List failed: {rc:#04x}')
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    padded('MyBoard', 11),
    padded('Tank', 11),
    padded('Flow', 11),
    padded('', 11),
    padded('', 11),
    padded('Door', 11),
    padded('', 11),
    padded('', 11),
    padded('Pump', 11),
    padded('', 11),
    padded('', 11),
    padded('', 11),
    padded('', 11),
]);

// Send the request (opcode 0x1E)
dio_write($port, build_request(123456789012, 0x1E, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Set Name List failed: 0x%02X', $rc));
}
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  padded('MyBoard', 11),
  padded('Tank', 11),
  padded('Flow', 11),
  padded('', 11),
  padded('', 11),
  padded('Door', 11),
  padded('', 11),
  padded('', 11),
  padded('Pump', 11),
  padded('', 11),
  padded('', 11),
  padded('', 11),
  padded('', 11),
);

# Send the request (opcode 0x1E)
$port->write(build_request(123456789012, 0x1E, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Set Name List failed: 0x%02X\n", $rc) unless $rc == 0x00;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    padded("MyBoard", 11),
    padded("Tank", 11),
    padded("Flow", 11),
    padded("", 11),
    padded("", 11),
    padded("Door", 11),
    padded("", 11),
    padded("", 11),
    padded("Pump", 11),
    padded("", 11),
    padded("", 11),
    padded("", 11),
    padded("", 11)
);

// Send the request (opcode 0x1E)
port.writeBytes(buildRequest(123456789012L, 0x1E, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Set Name List failed: 0x%02X", rc));
}
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    padded('MyBoard', 11),
    padded('Tank', 11),
    padded('Flow', 11),
    padded('', 11),
    padded('', 11),
    padded('Door', 11),
    padded('', 11),
    padded('', 11),
    padded('Pump', 11),
    padded('', 11),
    padded('', 11),
    padded('', 11),
    padded('', 11),
  ]);

  // Send the request (opcode 0x1E)
  port.write(buildRequest(123456789012, 0x1E, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Set Name List failed: 0x' + rc.toString(16));
})();

Set Name List

Sets the names for the board and for each analog input, digital input, and digital output. Each name is 11 bytes, NUL-terminated, so up to 10 characters.

Opcode: 0x1E. Body length: 143.

Request body

Field Bytes Description
Name_Board 11 Board name.
Name_Ain_0 11 Analog input 0 name.
Name_Ain_1 11 Analog input 1 name.
Name_Ain_2 11 Analog input 2 name.
Name_Ain_3 11 Analog input 3 name.
Name_Din_0 11 Digital input 0 name.
Name_Din_1 11 Digital input 1 name.
Name_Din_2 11 Digital input 2 name.
Name_Din_3 11 Digital input 3 name.
Name_Dout_0 11 Digital output 0 name.
Name_Dout_1 11 Digital output 1 name.
Name_Dout_2 11 Digital output 2 name.
Name_Dout_3 11 Digital output 3 name.

Response body: status only.

Example: Get Name List

# Get Name List to serial number 123456789012 (opcode 0x1F)
printf '\x43\x1c\xbe\x99\x1a\x14\x1f\x00\x91\xc1' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x1F, no body)
port.write(build_request(123456789012, 0x1F))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Get Name List failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
name_board = be_str(rsp_body, pos, 11)
pos += 11
name_ain_0 = be_str(rsp_body, pos, 11)
pos += 11
name_ain_1 = be_str(rsp_body, pos, 11)
pos += 11
name_ain_2 = be_str(rsp_body, pos, 11)
pos += 11
name_ain_3 = be_str(rsp_body, pos, 11)
pos += 11
name_din_0 = be_str(rsp_body, pos, 11)
pos += 11
name_din_1 = be_str(rsp_body, pos, 11)
pos += 11
name_din_2 = be_str(rsp_body, pos, 11)
pos += 11
name_din_3 = be_str(rsp_body, pos, 11)
pos += 11
name_dout_0 = be_str(rsp_body, pos, 11)
pos += 11
name_dout_1 = be_str(rsp_body, pos, 11)
pos += 11
name_dout_2 = be_str(rsp_body, pos, 11)
pos += 11
name_dout_3 = be_str(rsp_body, pos, 11)
pos += 11
# Send the request (opcode 0x1F, no body)
port.write(build_request(123456789012, 0x1F))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Get Name List failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
name_board = be_str(rsp_body, pos, 11)
pos += 11
name_ain_0 = be_str(rsp_body, pos, 11)
pos += 11
name_ain_1 = be_str(rsp_body, pos, 11)
pos += 11
name_ain_2 = be_str(rsp_body, pos, 11)
pos += 11
name_ain_3 = be_str(rsp_body, pos, 11)
pos += 11
name_din_0 = be_str(rsp_body, pos, 11)
pos += 11
name_din_1 = be_str(rsp_body, pos, 11)
pos += 11
name_din_2 = be_str(rsp_body, pos, 11)
pos += 11
name_din_3 = be_str(rsp_body, pos, 11)
pos += 11
name_dout_0 = be_str(rsp_body, pos, 11)
pos += 11
name_dout_1 = be_str(rsp_body, pos, 11)
pos += 11
name_dout_2 = be_str(rsp_body, pos, 11)
pos += 11
name_dout_3 = be_str(rsp_body, pos, 11)
pos += 11
// Send the request (opcode 0x1F, no body)
dio_write($port, build_request(123456789012, 0x1F));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Get Name List failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$name_board = be_str($rsp_body, $pos, 11);
$pos += 11;
$name_ain_0 = be_str($rsp_body, $pos, 11);
$pos += 11;
$name_ain_1 = be_str($rsp_body, $pos, 11);
$pos += 11;
$name_ain_2 = be_str($rsp_body, $pos, 11);
$pos += 11;
$name_ain_3 = be_str($rsp_body, $pos, 11);
$pos += 11;
$name_din_0 = be_str($rsp_body, $pos, 11);
$pos += 11;
$name_din_1 = be_str($rsp_body, $pos, 11);
$pos += 11;
$name_din_2 = be_str($rsp_body, $pos, 11);
$pos += 11;
$name_din_3 = be_str($rsp_body, $pos, 11);
$pos += 11;
$name_dout_0 = be_str($rsp_body, $pos, 11);
$pos += 11;
$name_dout_1 = be_str($rsp_body, $pos, 11);
$pos += 11;
$name_dout_2 = be_str($rsp_body, $pos, 11);
$pos += 11;
$name_dout_3 = be_str($rsp_body, $pos, 11);
$pos += 11;
# Send the request (opcode 0x1F, no body)
$port->write(build_request(123456789012, 0x1F));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Get Name List failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $name_board = be_str($rsp_body, $pos, 11);
$pos += 11;
my $name_ain_0 = be_str($rsp_body, $pos, 11);
$pos += 11;
my $name_ain_1 = be_str($rsp_body, $pos, 11);
$pos += 11;
my $name_ain_2 = be_str($rsp_body, $pos, 11);
$pos += 11;
my $name_ain_3 = be_str($rsp_body, $pos, 11);
$pos += 11;
my $name_din_0 = be_str($rsp_body, $pos, 11);
$pos += 11;
my $name_din_1 = be_str($rsp_body, $pos, 11);
$pos += 11;
my $name_din_2 = be_str($rsp_body, $pos, 11);
$pos += 11;
my $name_din_3 = be_str($rsp_body, $pos, 11);
$pos += 11;
my $name_dout_0 = be_str($rsp_body, $pos, 11);
$pos += 11;
my $name_dout_1 = be_str($rsp_body, $pos, 11);
$pos += 11;
my $name_dout_2 = be_str($rsp_body, $pos, 11);
$pos += 11;
my $name_dout_3 = be_str($rsp_body, $pos, 11);
$pos += 11;
// Send the request (opcode 0x1F, no body)
port.writeBytes(buildRequest(123456789012L, 0x1F));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Get Name List failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var nameBoard = beStr(rspBody, pos, 11);
pos += 11;
var nameAin0 = beStr(rspBody, pos, 11);
pos += 11;
var nameAin1 = beStr(rspBody, pos, 11);
pos += 11;
var nameAin2 = beStr(rspBody, pos, 11);
pos += 11;
var nameAin3 = beStr(rspBody, pos, 11);
pos += 11;
var nameDin0 = beStr(rspBody, pos, 11);
pos += 11;
var nameDin1 = beStr(rspBody, pos, 11);
pos += 11;
var nameDin2 = beStr(rspBody, pos, 11);
pos += 11;
var nameDin3 = beStr(rspBody, pos, 11);
pos += 11;
var nameDout0 = beStr(rspBody, pos, 11);
pos += 11;
var nameDout1 = beStr(rspBody, pos, 11);
pos += 11;
var nameDout2 = beStr(rspBody, pos, 11);
pos += 11;
var nameDout3 = beStr(rspBody, pos, 11);
pos += 11;
(async () => {
  // Send the request (opcode 0x1F, no body)
  port.write(buildRequest(123456789012, 0x1F));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Get Name List failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const nameBoard = beStr(rspBody, pos, 11);
  pos += 11;
  const nameAin0 = beStr(rspBody, pos, 11);
  pos += 11;
  const nameAin1 = beStr(rspBody, pos, 11);
  pos += 11;
  const nameAin2 = beStr(rspBody, pos, 11);
  pos += 11;
  const nameAin3 = beStr(rspBody, pos, 11);
  pos += 11;
  const nameDin0 = beStr(rspBody, pos, 11);
  pos += 11;
  const nameDin1 = beStr(rspBody, pos, 11);
  pos += 11;
  const nameDin2 = beStr(rspBody, pos, 11);
  pos += 11;
  const nameDin3 = beStr(rspBody, pos, 11);
  pos += 11;
  const nameDout0 = beStr(rspBody, pos, 11);
  pos += 11;
  const nameDout1 = beStr(rspBody, pos, 11);
  pos += 11;
  const nameDout2 = beStr(rspBody, pos, 11);
  pos += 11;
  const nameDout3 = beStr(rspBody, pos, 11);
  pos += 11;
})();

Get Name List

Returns the names that were set with Set Name List.

Opcode: 0x1F. Body length: 0.

Request body: none.

Response body

Field Bytes Description
Name_Board 11 Board name.
Name_Ain_0 11 Analog input 0 name.
Name_Ain_1 11 Analog input 1 name.
Name_Ain_2 11 Analog input 2 name.
Name_Ain_3 11 Analog input 3 name.
Name_Din_0 11 Digital input 0 name.
Name_Din_1 11 Digital input 1 name.
Name_Din_2 11 Digital input 2 name.
Name_Din_3 11 Digital input 3 name.
Name_Dout_0 11 Digital output 0 name.
Name_Dout_1 11 Digital output 1 name.
Name_Dout_2 11 Digital output 2 name.
Name_Dout_3 11 Digital output 3 name.

Status Read Requests

Example: Read A

# Read A to serial number 123456789012 (opcode 0x08)
printf '\x43\x1c\xbe\x99\x1a\x14\x08\x00\x9e\x31' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x08, no body)
port.write(build_request(123456789012, 0x08))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Read A failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
device_info = be_uint(rsp_body, pos, 2)
pos += 2
firmware_version = be_uint(rsp_body, pos, 2)
pos += 2
second = be_uint(rsp_body, pos, 1)
pos += 1
minute = be_uint(rsp_body, pos, 1)
pos += 1
hour = be_uint(rsp_body, pos, 1)
pos += 1
day = be_uint(rsp_body, pos, 1)
pos += 1
month = be_uint(rsp_body, pos, 1)
pos += 1
year = be_uint(rsp_body, pos, 2)
pos += 2
lifetime_ms = be_uint(rsp_body, pos, 8)
pos += 8
ai_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
ai_values = []
ai_pin_count.times do
  ai_values << be_uint(rsp_body, pos, 2)
  pos += 2
end
ai_l_watch_info = []
ai_pin_count.times do
  ai_l_watch_info << be_uint(rsp_body, pos, 1)
  pos += 1
end
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = be_uint(rsp_body, pos, 1)
pos += 1
di_c_watch_info = []
di_pin_count.times do
  di_c_watch_info << be_uint(rsp_body, pos, 1)
  pos += 1
end
di_l_watch_info = []
di_pin_count.times do
  di_l_watch_info << be_uint(rsp_body, pos, 1)
  pos += 1
end
di_r_watch_info = []
di_pin_count.times do
  di_r_watch_info << be_uint(rsp_body, pos, 1)
  pos += 1
end
do_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
do_levels = be_uint(rsp_body, pos, 1)
pos += 1
do_wave_owner_id = []
do_pin_count.times do
  do_wave_owner_id << be_uint(rsp_body, pos, 1)
  pos += 1
end
one_wire_io_count = be_uint(rsp_body, pos, 1)
pos += 1
one_wire_io_info = []
one_wire_io_count.times do
  rec = {}
  rec['Slot'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['StatePIOA'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['StatePIOB'] = be_uint(rsp_body, pos, 1)
  pos += 1
  one_wire_io_info << rec
end
one_wire_other_count = be_uint(rsp_body, pos, 1)
pos += 1
one_wire_device_info = []
one_wire_other_count.times do
  rec = {}
  rec['Slot'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['Temperature'] = be_int(rsp_body, pos, 2)
  pos += 2
  rec['Humidity'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['Lux'] = be_uint(rsp_body, pos, 2)
  pos += 2
  one_wire_device_info << rec
end
# Send the request (opcode 0x08, no body)
port.write(build_request(123456789012, 0x08))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Read A failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
device_info = be_uint(rsp_body, pos, 2)
pos += 2
firmware_version = be_uint(rsp_body, pos, 2)
pos += 2
second = be_uint(rsp_body, pos, 1)
pos += 1
minute = be_uint(rsp_body, pos, 1)
pos += 1
hour = be_uint(rsp_body, pos, 1)
pos += 1
day = be_uint(rsp_body, pos, 1)
pos += 1
month = be_uint(rsp_body, pos, 1)
pos += 1
year = be_uint(rsp_body, pos, 2)
pos += 2
lifetime_ms = be_uint(rsp_body, pos, 8)
pos += 8
ai_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
ai_values = []
for _ in range(ai_pin_count):
    ai_values.append(be_uint(rsp_body, pos, 2))
    pos += 2
ai_l_watch_info = []
for _ in range(ai_pin_count):
    ai_l_watch_info.append(be_uint(rsp_body, pos, 1))
    pos += 1
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = be_uint(rsp_body, pos, 1)
pos += 1
di_c_watch_info = []
for _ in range(di_pin_count):
    di_c_watch_info.append(be_uint(rsp_body, pos, 1))
    pos += 1
di_l_watch_info = []
for _ in range(di_pin_count):
    di_l_watch_info.append(be_uint(rsp_body, pos, 1))
    pos += 1
di_r_watch_info = []
for _ in range(di_pin_count):
    di_r_watch_info.append(be_uint(rsp_body, pos, 1))
    pos += 1
do_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
do_levels = be_uint(rsp_body, pos, 1)
pos += 1
do_wave_owner_id = []
for _ in range(do_pin_count):
    do_wave_owner_id.append(be_uint(rsp_body, pos, 1))
    pos += 1
one_wire_io_count = be_uint(rsp_body, pos, 1)
pos += 1
one_wire_io_info = []
for _ in range(one_wire_io_count):
    rec = {}
    rec['Slot'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['StatePIOA'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['StatePIOB'] = be_uint(rsp_body, pos, 1)
    pos += 1
    one_wire_io_info.append(rec)
one_wire_other_count = be_uint(rsp_body, pos, 1)
pos += 1
one_wire_device_info = []
for _ in range(one_wire_other_count):
    rec = {}
    rec['Slot'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['Temperature'] = be_int(rsp_body, pos, 2)
    pos += 2
    rec['Humidity'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['Lux'] = be_uint(rsp_body, pos, 2)
    pos += 2
    one_wire_device_info.append(rec)
// Send the request (opcode 0x08, no body)
dio_write($port, build_request(123456789012, 0x08));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Read A failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$device_info = be_uint($rsp_body, $pos, 2);
$pos += 2;
$firmware_version = be_uint($rsp_body, $pos, 2);
$pos += 2;
$second = be_uint($rsp_body, $pos, 1);
$pos += 1;
$minute = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hour = be_uint($rsp_body, $pos, 1);
$pos += 1;
$day = be_uint($rsp_body, $pos, 1);
$pos += 1;
$month = be_uint($rsp_body, $pos, 1);
$pos += 1;
$year = be_uint($rsp_body, $pos, 2);
$pos += 2;
$lifetime_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
$ai_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$ai_values = [];
for ($i = 0; $i < $ai_pin_count; $i++) {
    $ai_values[] = be_uint($rsp_body, $pos, 2);
    $pos += 2;
}
$ai_l_watch_info = [];
for ($i = 0; $i < $ai_pin_count; $i++) {
    $ai_l_watch_info[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_levels = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_c_watch_info = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_c_watch_info[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$di_l_watch_info = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_l_watch_info[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$di_r_watch_info = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_r_watch_info[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$do_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$do_levels = be_uint($rsp_body, $pos, 1);
$pos += 1;
$do_wave_owner_id = [];
for ($i = 0; $i < $do_pin_count; $i++) {
    $do_wave_owner_id[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$one_wire_io_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$one_wire_io_info = [];
for ($i = 0; $i < $one_wire_io_count; $i++) {
    $rec = [];
    $rec['Slot'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['StatePIOA'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['StatePIOB'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $one_wire_io_info[] = $rec;
}
$one_wire_other_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$one_wire_device_info = [];
for ($i = 0; $i < $one_wire_other_count; $i++) {
    $rec = [];
    $rec['Slot'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['Temperature'] = be_int($rsp_body, $pos, 2);
    $pos += 2;
    $rec['Humidity'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['Lux'] = be_uint($rsp_body, $pos, 2);
    $pos += 2;
    $one_wire_device_info[] = $rec;
}
# Send the request (opcode 0x08, no body)
$port->write(build_request(123456789012, 0x08));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Read A failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $device_info = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $firmware_version = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $second = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $minute = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hour = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $day = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $month = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $year = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $lifetime_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
my $ai_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @ai_values;
for (1 .. $ai_pin_count) {
    push @ai_values, be_uint($rsp_body, $pos, 2);
    $pos += 2;
}
my @ai_l_watch_info;
for (1 .. $ai_pin_count) {
    push @ai_l_watch_info, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my $di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $di_levels = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @di_c_watch_info;
for (1 .. $di_pin_count) {
    push @di_c_watch_info, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my @di_l_watch_info;
for (1 .. $di_pin_count) {
    push @di_l_watch_info, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my @di_r_watch_info;
for (1 .. $di_pin_count) {
    push @di_r_watch_info, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my $do_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $do_levels = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @do_wave_owner_id;
for (1 .. $do_pin_count) {
    push @do_wave_owner_id, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my $one_wire_io_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @one_wire_io_info;
for (1 .. $one_wire_io_count) {
    my %rec;
    $rec{'Slot'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'StatePIOA'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'StatePIOB'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    push @one_wire_io_info, \%rec;
}
my $one_wire_other_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @one_wire_device_info;
for (1 .. $one_wire_other_count) {
    my %rec;
    $rec{'Slot'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'Temperature'} = be_int($rsp_body, $pos, 2);
    $pos += 2;
    $rec{'Humidity'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'Lux'} = be_uint($rsp_body, $pos, 2);
    $pos += 2;
    push @one_wire_device_info, \%rec;
}
// Send the request (opcode 0x08, no body)
port.writeBytes(buildRequest(123456789012L, 0x08));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Read A failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var deviceInfo = beUInt(rspBody, pos, 2);
pos += 2;
var firmwareVersion = beUInt(rspBody, pos, 2);
pos += 2;
var second = beUInt(rspBody, pos, 1);
pos += 1;
var minute = beUInt(rspBody, pos, 1);
pos += 1;
var hour = beUInt(rspBody, pos, 1);
pos += 1;
var day = beUInt(rspBody, pos, 1);
pos += 1;
var month = beUInt(rspBody, pos, 1);
pos += 1;
var year = beUInt(rspBody, pos, 2);
pos += 2;
var lifetimeMs = beUInt(rspBody, pos, 8);
pos += 8;
var aiPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var aiValues = new ArrayList<Long>();
for (int i = 0; i < aiPinCount; i++) {
    aiValues.add(beUInt(rspBody, pos, 2));
    pos += 2;
}
var aiLWatchInfo = new ArrayList<Long>();
for (int i = 0; i < aiPinCount; i++) {
    aiLWatchInfo.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var diPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var diLevels = beUInt(rspBody, pos, 1);
pos += 1;
var diCWatchInfo = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diCWatchInfo.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var diLWatchInfo = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diLWatchInfo.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var diRWatchInfo = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diRWatchInfo.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var doPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var doLevels = beUInt(rspBody, pos, 1);
pos += 1;
var doWaveOwnerId = new ArrayList<Long>();
for (int i = 0; i < doPinCount; i++) {
    doWaveOwnerId.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var oneWireIoCount = beUInt(rspBody, pos, 1);
pos += 1;
var oneWireIoInfo = new ArrayList<Map<String, Object>>();
for (int i = 0; i < oneWireIoCount; i++) {
    var rec = new HashMap<String, Object>();
    rec.put("Slot", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("StatePIOA", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("StatePIOB", beUInt(rspBody, pos, 1));
    pos += 1;
    oneWireIoInfo.add(rec);
}
var oneWireOtherCount = beUInt(rspBody, pos, 1);
pos += 1;
var oneWireDeviceInfo = new ArrayList<Map<String, Object>>();
for (int i = 0; i < oneWireOtherCount; i++) {
    var rec = new HashMap<String, Object>();
    rec.put("Slot", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("Temperature", beInt(rspBody, pos, 2));
    pos += 2;
    rec.put("Humidity", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("Lux", beUInt(rspBody, pos, 2));
    pos += 2;
    oneWireDeviceInfo.add(rec);
}
(async () => {
  // Send the request (opcode 0x08, no body)
  port.write(buildRequest(123456789012, 0x08));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Read A failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const deviceInfo = beUInt(rspBody, pos, 2);
  pos += 2;
  const firmwareVersion = beUInt(rspBody, pos, 2);
  pos += 2;
  const second = beUInt(rspBody, pos, 1);
  pos += 1;
  const minute = beUInt(rspBody, pos, 1);
  pos += 1;
  const hour = beUInt(rspBody, pos, 1);
  pos += 1;
  const day = beUInt(rspBody, pos, 1);
  pos += 1;
  const month = beUInt(rspBody, pos, 1);
  pos += 1;
  const year = beUInt(rspBody, pos, 2);
  pos += 2;
  const lifetimeMs = beUInt(rspBody, pos, 8);
  pos += 8;
  const aiPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const aiValues = [];
  for (let i = 0; i < aiPinCount; i++) {
      aiValues.push(beUInt(rspBody, pos, 2));
      pos += 2;
  }
  const aiLWatchInfo = [];
  for (let i = 0; i < aiPinCount; i++) {
      aiLWatchInfo.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const diPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const diLevels = beUInt(rspBody, pos, 1);
  pos += 1;
  const diCWatchInfo = [];
  for (let i = 0; i < diPinCount; i++) {
      diCWatchInfo.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const diLWatchInfo = [];
  for (let i = 0; i < diPinCount; i++) {
      diLWatchInfo.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const diRWatchInfo = [];
  for (let i = 0; i < diPinCount; i++) {
      diRWatchInfo.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const doPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const doLevels = beUInt(rspBody, pos, 1);
  pos += 1;
  const doWaveOwnerId = [];
  for (let i = 0; i < doPinCount; i++) {
      doWaveOwnerId.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const oneWireIoCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const oneWireIoInfo = [];
  for (let i = 0; i < oneWireIoCount; i++) {
      const rec = {};
      rec['Slot'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['StatePIOA'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['StatePIOB'] = beUInt(rspBody, pos, 1);
      pos += 1;
      oneWireIoInfo.push(rec);
  }
  const oneWireOtherCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const oneWireDeviceInfo = [];
  for (let i = 0; i < oneWireOtherCount; i++) {
      const rec = {};
      rec['Slot'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['Temperature'] = beInt(rspBody, pos, 2);
      pos += 2;
      rec['Humidity'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['Lux'] = beUInt(rspBody, pos, 2);
      pos += 2;
      oneWireDeviceInfo.push(rec);
  }
})();

Read A

Returns the full status of the device in one response: analog inputs, digital inputs, digital outputs, and the 1-Wire and TWI device lists. The counts in the response tell you how many entries follow.

Opcode: 0x08. Body length: 0.

Request body: none.

Response body

Field Bytes Description
DeviceInfo 2 Device type.
FirmwareVersion 2 Firmware version.
Second 1 Seconds.
Minute 1 Minutes.
Hour 1 Hours.
Day 1 Day of month.
Month 1 Month.
Year 2 Year.
LifetimeMS 8 Milliseconds since start.
Ai_pin_count 1 Number of analog inputs.
Ai_values[] 2 Analog value per input, 0-4095. 0xFFFF means error. Repeated Ai_pin_count times.
Ai_lWatchInfo[] 1 Level-watch state per analog input. 1 if a watch is set, 2 if its waveform is active. 0 if none. Repeated Ai_pin_count times.
Di_pin_count 1 Number of digital inputs.
Di_levels 1 Bitmap of digital input levels. Bit 0 is DI 0.
Di_cWatchInfo[] 1 Count-watch state per digital input. 1 if a watch is set, 2 if triggered. 0 if none. Repeated Di_pin_count times.
Di_lWatchInfo[] 1 Level-watch state per digital input. 1 if a watch is set, 2 if triggered. 0 if none. Repeated Di_pin_count times.
Di_rWatchInfo[] 1 Rate-watch state per digital input. 1 if a watch is set, 2 if triggered. 0 if none. Repeated Di_pin_count times.
Do_pin_count 1 Number of digital outputs.
Do_levels 1 Bitmap of digital output levels. Bit 0 is DO 0.
Do_waveOwnerId[] 1 Waveform owner ID per output. 0 means none. Repeated Do_pin_count times.
OneWire_io_count 1 Number of 1-Wire I/O devices.
OneWire_io_info[] 3 One entry per 1-Wire I/O device. Repeated OneWire_io_count times. Each entry is 3 bytes.
OneWire_io_info[].Slot 1
OneWire_io_info[].StatePIOA 1 PIOA state, 0 or 1. Bit 1 is the drive level and bit 0 the pin level.
OneWire_io_info[].StatePIOB 1 PIOB state, 0 or 1. Bit 1 is the drive level and bit 0 the pin level.
OneWire_other_count 1 Number of other 1-Wire devices.
OneWire_device_info[] 6 One entry per 1-Wire sensor. Temperature is in tenths of a degree Celsius. Repeated OneWire_other_count times. Each entry is 6 bytes.
OneWire_device_info[].Slot 1
OneWire_device_info[].Temperature 2 Temperature in tenths of a degree Celsius, signed. 0xEE in every field means the device did not respond.
OneWire_device_info[].Humidity 1 Relative humidity in percent. 0xFF means not available.
OneWire_device_info[].Lux 2 Light level in lumens per square meter. 0xFFFF means not available.
  • Each arr section has one entry per pin, in pin order.

Example: Read B

# Read B to serial number 123456789012 (opcode 0x09)
printf '\x43\x1c\xbe\x99\x1a\x14\x09\x00\x9f\xa1' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x09, no body)
port.write(build_request(123456789012, 0x09))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Read B failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
firmware_version = be_uint(rsp_body, pos, 2)
pos += 2
second = be_uint(rsp_body, pos, 1)
pos += 1
minute = be_uint(rsp_body, pos, 1)
pos += 1
hour = be_uint(rsp_body, pos, 1)
pos += 1
day = be_uint(rsp_body, pos, 1)
pos += 1
month = be_uint(rsp_body, pos, 1)
pos += 1
year = be_uint(rsp_body, pos, 2)
pos += 2
lifetime_ms = be_uint(rsp_body, pos, 8)
pos += 8
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = be_uint(rsp_body, pos, 1)
pos += 1
di_curr_level_msec = []
di_pin_count.times do
  di_curr_level_msec << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_prev_hi_ms = []
di_pin_count.times do
  di_prev_hi_ms << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_prev_lo_ms = []
di_pin_count.times do
  di_prev_lo_ms << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_resettable_pulse_counts = []
di_pin_count.times do
  di_resettable_pulse_counts << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_lifetime_pulse_counts = []
di_pin_count.times do
  di_lifetime_pulse_counts << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_total_hi_seconds = []
di_pin_count.times do
  di_total_hi_seconds << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_total_low_seconds = []
di_pin_count.times do
  di_total_low_seconds << be_uint(rsp_body, pos, 8)
  pos += 8
end
do_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
do_levels = be_uint(rsp_body, pos, 1)
pos += 1
# Send the request (opcode 0x09, no body)
port.write(build_request(123456789012, 0x09))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Read B failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
firmware_version = be_uint(rsp_body, pos, 2)
pos += 2
second = be_uint(rsp_body, pos, 1)
pos += 1
minute = be_uint(rsp_body, pos, 1)
pos += 1
hour = be_uint(rsp_body, pos, 1)
pos += 1
day = be_uint(rsp_body, pos, 1)
pos += 1
month = be_uint(rsp_body, pos, 1)
pos += 1
year = be_uint(rsp_body, pos, 2)
pos += 2
lifetime_ms = be_uint(rsp_body, pos, 8)
pos += 8
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = be_uint(rsp_body, pos, 1)
pos += 1
di_curr_level_msec = []
for _ in range(di_pin_count):
    di_curr_level_msec.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_prev_hi_ms = []
for _ in range(di_pin_count):
    di_prev_hi_ms.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_prev_lo_ms = []
for _ in range(di_pin_count):
    di_prev_lo_ms.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_resettable_pulse_counts = []
for _ in range(di_pin_count):
    di_resettable_pulse_counts.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_lifetime_pulse_counts = []
for _ in range(di_pin_count):
    di_lifetime_pulse_counts.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_total_hi_seconds = []
for _ in range(di_pin_count):
    di_total_hi_seconds.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_total_low_seconds = []
for _ in range(di_pin_count):
    di_total_low_seconds.append(be_uint(rsp_body, pos, 8))
    pos += 8
do_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
do_levels = be_uint(rsp_body, pos, 1)
pos += 1
// Send the request (opcode 0x09, no body)
dio_write($port, build_request(123456789012, 0x09));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Read B failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$firmware_version = be_uint($rsp_body, $pos, 2);
$pos += 2;
$second = be_uint($rsp_body, $pos, 1);
$pos += 1;
$minute = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hour = be_uint($rsp_body, $pos, 1);
$pos += 1;
$day = be_uint($rsp_body, $pos, 1);
$pos += 1;
$month = be_uint($rsp_body, $pos, 1);
$pos += 1;
$year = be_uint($rsp_body, $pos, 2);
$pos += 2;
$lifetime_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
$di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_levels = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_curr_level_msec = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_curr_level_msec[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_prev_hi_ms = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_prev_hi_ms[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_prev_lo_ms = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_prev_lo_ms[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_resettable_pulse_counts = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_resettable_pulse_counts[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_lifetime_pulse_counts = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_lifetime_pulse_counts[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_total_hi_seconds = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_total_hi_seconds[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_total_low_seconds = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_total_low_seconds[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$do_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$do_levels = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Send the request (opcode 0x09, no body)
$port->write(build_request(123456789012, 0x09));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Read B failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $firmware_version = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $second = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $minute = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hour = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $day = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $month = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $year = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $lifetime_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
my $di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $di_levels = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @di_curr_level_msec;
for (1 .. $di_pin_count) {
    push @di_curr_level_msec, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_prev_hi_ms;
for (1 .. $di_pin_count) {
    push @di_prev_hi_ms, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_prev_lo_ms;
for (1 .. $di_pin_count) {
    push @di_prev_lo_ms, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_resettable_pulse_counts;
for (1 .. $di_pin_count) {
    push @di_resettable_pulse_counts, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_lifetime_pulse_counts;
for (1 .. $di_pin_count) {
    push @di_lifetime_pulse_counts, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_total_hi_seconds;
for (1 .. $di_pin_count) {
    push @di_total_hi_seconds, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_total_low_seconds;
for (1 .. $di_pin_count) {
    push @di_total_low_seconds, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my $do_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $do_levels = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Send the request (opcode 0x09, no body)
port.writeBytes(buildRequest(123456789012L, 0x09));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Read B failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var firmwareVersion = beUInt(rspBody, pos, 2);
pos += 2;
var second = beUInt(rspBody, pos, 1);
pos += 1;
var minute = beUInt(rspBody, pos, 1);
pos += 1;
var hour = beUInt(rspBody, pos, 1);
pos += 1;
var day = beUInt(rspBody, pos, 1);
pos += 1;
var month = beUInt(rspBody, pos, 1);
pos += 1;
var year = beUInt(rspBody, pos, 2);
pos += 2;
var lifetimeMs = beUInt(rspBody, pos, 8);
pos += 8;
var diPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var diLevels = beUInt(rspBody, pos, 1);
pos += 1;
var diCurrLevelMsec = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diCurrLevelMsec.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diPrevHiMs = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diPrevHiMs.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diPrevLoMs = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diPrevLoMs.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diResettablePulseCounts = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diResettablePulseCounts.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diLifetimePulseCounts = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diLifetimePulseCounts.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diTotalHiSeconds = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diTotalHiSeconds.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diTotalLowSeconds = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diTotalLowSeconds.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var doPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var doLevels = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Send the request (opcode 0x09, no body)
  port.write(buildRequest(123456789012, 0x09));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Read B failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const firmwareVersion = beUInt(rspBody, pos, 2);
  pos += 2;
  const second = beUInt(rspBody, pos, 1);
  pos += 1;
  const minute = beUInt(rspBody, pos, 1);
  pos += 1;
  const hour = beUInt(rspBody, pos, 1);
  pos += 1;
  const day = beUInt(rspBody, pos, 1);
  pos += 1;
  const month = beUInt(rspBody, pos, 1);
  pos += 1;
  const year = beUInt(rspBody, pos, 2);
  pos += 2;
  const lifetimeMs = beUInt(rspBody, pos, 8);
  pos += 8;
  const diPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const diLevels = beUInt(rspBody, pos, 1);
  pos += 1;
  const diCurrLevelMsec = [];
  for (let i = 0; i < diPinCount; i++) {
      diCurrLevelMsec.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diPrevHiMs = [];
  for (let i = 0; i < diPinCount; i++) {
      diPrevHiMs.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diPrevLoMs = [];
  for (let i = 0; i < diPinCount; i++) {
      diPrevLoMs.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diResettablePulseCounts = [];
  for (let i = 0; i < diPinCount; i++) {
      diResettablePulseCounts.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diLifetimePulseCounts = [];
  for (let i = 0; i < diPinCount; i++) {
      diLifetimePulseCounts.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diTotalHiSeconds = [];
  for (let i = 0; i < diPinCount; i++) {
      diTotalHiSeconds.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diTotalLowSeconds = [];
  for (let i = 0; i < diPinCount; i++) {
      diTotalLowSeconds.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const doPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const doLevels = beUInt(rspBody, pos, 1);
  pos += 1;
})();

Read B

Returns the firmware version, time, lifetime, and the digital input and output counters for inputs 0 to 3. The arrays are grouped by field, so all Di_currLevelMsec values come first, then all Di_prevHiMs values, and so on.

Opcode: 0x09. Body length: 0.

Request body: none.

Response body

Field Bytes Description
FirmwareVersion 2 Firmware version.
Second 1 Seconds.
Minute 1 Minutes.
Hour 1 Hours.
Day 1 Day of month.
Month 1 Month.
Year 2 Year.
LifetimeMS 8 Milliseconds since start.
Di_pin_count 1 Number of digital inputs in this group, up to 4.
Di_levels 1 Bitmap of digital input levels.
Di_currLevelMsec[] 8 Milliseconds at the current level. Repeated Di_pin_count times.
Di_prevHiMs[] 8 High time of the previous pulse, in ms. Repeated Di_pin_count times.
Di_prevLoMs[] 8 Low time of the previous pulse, in ms. Repeated Di_pin_count times.
Di_resettablePulseCounts[] 8 Pulse count since the last reset. Repeated Di_pin_count times.
Di_lifetimePulseCounts[] 8 Lifetime pulse count. Repeated Di_pin_count times.
Di_totalHiSeconds[] 8 Total high time, in seconds. Repeated Di_pin_count times.
Di_totalLowSeconds[] 8 Total low time, in seconds. Repeated Di_pin_count times.
Do_pin_count 1 Number of digital outputs.
Do_levels 1 Bitmap of digital output levels.

Example: Read C

# Read C to serial number 123456789012 (opcode 0x1D)
printf '\x43\x1c\xbe\x99\x1a\x14\x1d\x00\x90\xa1' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x1D, no body)
port.write(build_request(123456789012, 0x1D))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Read C failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
firmware_version = be_uint(rsp_body, pos, 2)
pos += 2
second = be_uint(rsp_body, pos, 1)
pos += 1
minute = be_uint(rsp_body, pos, 1)
pos += 1
hour = be_uint(rsp_body, pos, 1)
pos += 1
day = be_uint(rsp_body, pos, 1)
pos += 1
month = be_uint(rsp_body, pos, 1)
pos += 1
year = be_uint(rsp_body, pos, 2)
pos += 2
lifetime_ms = be_uint(rsp_body, pos, 8)
pos += 8
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = be_uint(rsp_body, pos, 1)
pos += 1
di_curr_level_msec = []
di_pin_count.times do
  di_curr_level_msec << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_prev_hi_ms = []
di_pin_count.times do
  di_prev_hi_ms << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_prev_lo_ms = []
di_pin_count.times do
  di_prev_lo_ms << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_resettable_pulse_counts = []
di_pin_count.times do
  di_resettable_pulse_counts << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_lifetime_pulse_counts = []
di_pin_count.times do
  di_lifetime_pulse_counts << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_total_hi_seconds = []
di_pin_count.times do
  di_total_hi_seconds << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_total_low_seconds = []
di_pin_count.times do
  di_total_low_seconds << be_uint(rsp_body, pos, 8)
  pos += 8
end
do_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
do_levels = be_uint(rsp_body, pos, 1)
pos += 1
# Send the request (opcode 0x1D, no body)
port.write(build_request(123456789012, 0x1D))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Read C failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
firmware_version = be_uint(rsp_body, pos, 2)
pos += 2
second = be_uint(rsp_body, pos, 1)
pos += 1
minute = be_uint(rsp_body, pos, 1)
pos += 1
hour = be_uint(rsp_body, pos, 1)
pos += 1
day = be_uint(rsp_body, pos, 1)
pos += 1
month = be_uint(rsp_body, pos, 1)
pos += 1
year = be_uint(rsp_body, pos, 2)
pos += 2
lifetime_ms = be_uint(rsp_body, pos, 8)
pos += 8
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = be_uint(rsp_body, pos, 1)
pos += 1
di_curr_level_msec = []
for _ in range(di_pin_count):
    di_curr_level_msec.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_prev_hi_ms = []
for _ in range(di_pin_count):
    di_prev_hi_ms.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_prev_lo_ms = []
for _ in range(di_pin_count):
    di_prev_lo_ms.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_resettable_pulse_counts = []
for _ in range(di_pin_count):
    di_resettable_pulse_counts.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_lifetime_pulse_counts = []
for _ in range(di_pin_count):
    di_lifetime_pulse_counts.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_total_hi_seconds = []
for _ in range(di_pin_count):
    di_total_hi_seconds.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_total_low_seconds = []
for _ in range(di_pin_count):
    di_total_low_seconds.append(be_uint(rsp_body, pos, 8))
    pos += 8
do_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
do_levels = be_uint(rsp_body, pos, 1)
pos += 1
// Send the request (opcode 0x1D, no body)
dio_write($port, build_request(123456789012, 0x1D));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Read C failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$firmware_version = be_uint($rsp_body, $pos, 2);
$pos += 2;
$second = be_uint($rsp_body, $pos, 1);
$pos += 1;
$minute = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hour = be_uint($rsp_body, $pos, 1);
$pos += 1;
$day = be_uint($rsp_body, $pos, 1);
$pos += 1;
$month = be_uint($rsp_body, $pos, 1);
$pos += 1;
$year = be_uint($rsp_body, $pos, 2);
$pos += 2;
$lifetime_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
$di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_levels = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_curr_level_msec = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_curr_level_msec[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_prev_hi_ms = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_prev_hi_ms[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_prev_lo_ms = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_prev_lo_ms[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_resettable_pulse_counts = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_resettable_pulse_counts[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_lifetime_pulse_counts = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_lifetime_pulse_counts[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_total_hi_seconds = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_total_hi_seconds[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_total_low_seconds = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_total_low_seconds[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$do_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$do_levels = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Send the request (opcode 0x1D, no body)
$port->write(build_request(123456789012, 0x1D));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Read C failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $firmware_version = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $second = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $minute = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hour = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $day = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $month = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $year = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $lifetime_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
my $di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $di_levels = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @di_curr_level_msec;
for (1 .. $di_pin_count) {
    push @di_curr_level_msec, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_prev_hi_ms;
for (1 .. $di_pin_count) {
    push @di_prev_hi_ms, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_prev_lo_ms;
for (1 .. $di_pin_count) {
    push @di_prev_lo_ms, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_resettable_pulse_counts;
for (1 .. $di_pin_count) {
    push @di_resettable_pulse_counts, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_lifetime_pulse_counts;
for (1 .. $di_pin_count) {
    push @di_lifetime_pulse_counts, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_total_hi_seconds;
for (1 .. $di_pin_count) {
    push @di_total_hi_seconds, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_total_low_seconds;
for (1 .. $di_pin_count) {
    push @di_total_low_seconds, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my $do_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $do_levels = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Send the request (opcode 0x1D, no body)
port.writeBytes(buildRequest(123456789012L, 0x1D));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Read C failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var firmwareVersion = beUInt(rspBody, pos, 2);
pos += 2;
var second = beUInt(rspBody, pos, 1);
pos += 1;
var minute = beUInt(rspBody, pos, 1);
pos += 1;
var hour = beUInt(rspBody, pos, 1);
pos += 1;
var day = beUInt(rspBody, pos, 1);
pos += 1;
var month = beUInt(rspBody, pos, 1);
pos += 1;
var year = beUInt(rspBody, pos, 2);
pos += 2;
var lifetimeMs = beUInt(rspBody, pos, 8);
pos += 8;
var diPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var diLevels = beUInt(rspBody, pos, 1);
pos += 1;
var diCurrLevelMsec = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diCurrLevelMsec.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diPrevHiMs = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diPrevHiMs.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diPrevLoMs = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diPrevLoMs.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diResettablePulseCounts = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diResettablePulseCounts.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diLifetimePulseCounts = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diLifetimePulseCounts.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diTotalHiSeconds = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diTotalHiSeconds.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diTotalLowSeconds = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diTotalLowSeconds.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var doPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var doLevels = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Send the request (opcode 0x1D, no body)
  port.write(buildRequest(123456789012, 0x1D));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Read C failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const firmwareVersion = beUInt(rspBody, pos, 2);
  pos += 2;
  const second = beUInt(rspBody, pos, 1);
  pos += 1;
  const minute = beUInt(rspBody, pos, 1);
  pos += 1;
  const hour = beUInt(rspBody, pos, 1);
  pos += 1;
  const day = beUInt(rspBody, pos, 1);
  pos += 1;
  const month = beUInt(rspBody, pos, 1);
  pos += 1;
  const year = beUInt(rspBody, pos, 2);
  pos += 2;
  const lifetimeMs = beUInt(rspBody, pos, 8);
  pos += 8;
  const diPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const diLevels = beUInt(rspBody, pos, 1);
  pos += 1;
  const diCurrLevelMsec = [];
  for (let i = 0; i < diPinCount; i++) {
      diCurrLevelMsec.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diPrevHiMs = [];
  for (let i = 0; i < diPinCount; i++) {
      diPrevHiMs.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diPrevLoMs = [];
  for (let i = 0; i < diPinCount; i++) {
      diPrevLoMs.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diResettablePulseCounts = [];
  for (let i = 0; i < diPinCount; i++) {
      diResettablePulseCounts.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diLifetimePulseCounts = [];
  for (let i = 0; i < diPinCount; i++) {
      diLifetimePulseCounts.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diTotalHiSeconds = [];
  for (let i = 0; i < diPinCount; i++) {
      diTotalHiSeconds.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diTotalLowSeconds = [];
  for (let i = 0; i < diPinCount; i++) {
      diTotalLowSeconds.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const doPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const doLevels = beUInt(rspBody, pos, 1);
  pos += 1;
})();

Read C

Same layout as Read B, but for the digital inputs above input 3. This is only valid on ioStacks with more than four digital inputs. Otherwise the device returns RC_CMD_UNAVAILABLE.

Opcode: 0x1D. Body length: 0.

Request body: none.

Response body

Field Bytes Description
FirmwareVersion 2 Firmware version.
Second 1 Seconds.
Minute 1 Minutes.
Hour 1 Hours.
Day 1 Day of month.
Month 1 Month.
Year 2 Year.
LifetimeMS 8 Milliseconds since start.
Di_pin_count 1 Number of digital inputs in this group.
Di_levels 1 Bitmap of digital input levels.
Di_currLevelMsec[] 8 Milliseconds at the current level. Repeated Di_pin_count times.
Di_prevHiMs[] 8 High time of the previous pulse, in ms. Repeated Di_pin_count times.
Di_prevLoMs[] 8 Low time of the previous pulse, in ms. Repeated Di_pin_count times.
Di_resettablePulseCounts[] 8 Pulse count since the last reset. Repeated Di_pin_count times.
Di_lifetimePulseCounts[] 8 Lifetime pulse count. Repeated Di_pin_count times.
Di_totalHiSeconds[] 8 Total high time, in seconds. Repeated Di_pin_count times.
Di_totalLowSeconds[] 8 Total low time, in seconds. Repeated Di_pin_count times.
Do_pin_count 1 Number of digital outputs.
Do_levels 1 Bitmap of digital output levels.

Example: Read 1

# Read 1 to serial number 123456789012 (opcode 0x0A)
printf '\x43\x1c\xbe\x99\x1a\x14\x0a\x00\x9f\x51' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x0A, no body)
port.write(build_request(123456789012, 0x0A))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Read 1 failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
ai_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
ai_values = []
ai_pin_count.times do
  ai_values << be_uint(rsp_body, pos, 2)
  pos += 2
end
ai_l_watch_info = []
ai_pin_count.times do
  ai_l_watch_info << be_uint(rsp_body, pos, 1)
  pos += 1
end
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = []
di_pin_count.times do
  di_levels << be_uint(rsp_body, pos, 1)
  pos += 1
end
di_curr_level_msec = []
di_pin_count.times do
  di_curr_level_msec << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_c_watch_info = []
di_pin_count.times do
  di_c_watch_info << be_uint(rsp_body, pos, 1)
  pos += 1
end
di_l_watch_info = []
di_pin_count.times do
  di_l_watch_info << be_uint(rsp_body, pos, 1)
  pos += 1
end
di_r_watch_info = []
di_pin_count.times do
  di_r_watch_info << be_uint(rsp_body, pos, 1)
  pos += 1
end
do_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
do_levels = []
do_pin_count.times do
  do_levels << be_uint(rsp_body, pos, 1)
  pos += 1
end
lifetime_ms = be_uint(rsp_body, pos, 8)
pos += 8
# Send the request (opcode 0x0A, no body)
port.write(build_request(123456789012, 0x0A))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Read 1 failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
ai_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
ai_values = []
for _ in range(ai_pin_count):
    ai_values.append(be_uint(rsp_body, pos, 2))
    pos += 2
ai_l_watch_info = []
for _ in range(ai_pin_count):
    ai_l_watch_info.append(be_uint(rsp_body, pos, 1))
    pos += 1
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = []
for _ in range(di_pin_count):
    di_levels.append(be_uint(rsp_body, pos, 1))
    pos += 1
di_curr_level_msec = []
for _ in range(di_pin_count):
    di_curr_level_msec.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_c_watch_info = []
for _ in range(di_pin_count):
    di_c_watch_info.append(be_uint(rsp_body, pos, 1))
    pos += 1
di_l_watch_info = []
for _ in range(di_pin_count):
    di_l_watch_info.append(be_uint(rsp_body, pos, 1))
    pos += 1
di_r_watch_info = []
for _ in range(di_pin_count):
    di_r_watch_info.append(be_uint(rsp_body, pos, 1))
    pos += 1
do_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
do_levels = []
for _ in range(do_pin_count):
    do_levels.append(be_uint(rsp_body, pos, 1))
    pos += 1
lifetime_ms = be_uint(rsp_body, pos, 8)
pos += 8
// Send the request (opcode 0x0A, no body)
dio_write($port, build_request(123456789012, 0x0A));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Read 1 failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$ai_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$ai_values = [];
for ($i = 0; $i < $ai_pin_count; $i++) {
    $ai_values[] = be_uint($rsp_body, $pos, 2);
    $pos += 2;
}
$ai_l_watch_info = [];
for ($i = 0; $i < $ai_pin_count; $i++) {
    $ai_l_watch_info[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_levels = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_levels[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$di_curr_level_msec = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_curr_level_msec[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_c_watch_info = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_c_watch_info[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$di_l_watch_info = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_l_watch_info[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$di_r_watch_info = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_r_watch_info[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$do_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$do_levels = [];
for ($i = 0; $i < $do_pin_count; $i++) {
    $do_levels[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$lifetime_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
# Send the request (opcode 0x0A, no body)
$port->write(build_request(123456789012, 0x0A));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Read 1 failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $ai_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @ai_values;
for (1 .. $ai_pin_count) {
    push @ai_values, be_uint($rsp_body, $pos, 2);
    $pos += 2;
}
my @ai_l_watch_info;
for (1 .. $ai_pin_count) {
    push @ai_l_watch_info, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my $di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @di_levels;
for (1 .. $di_pin_count) {
    push @di_levels, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my @di_curr_level_msec;
for (1 .. $di_pin_count) {
    push @di_curr_level_msec, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_c_watch_info;
for (1 .. $di_pin_count) {
    push @di_c_watch_info, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my @di_l_watch_info;
for (1 .. $di_pin_count) {
    push @di_l_watch_info, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my @di_r_watch_info;
for (1 .. $di_pin_count) {
    push @di_r_watch_info, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my $do_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @do_levels;
for (1 .. $do_pin_count) {
    push @do_levels, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my $lifetime_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
// Send the request (opcode 0x0A, no body)
port.writeBytes(buildRequest(123456789012L, 0x0A));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Read 1 failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var aiPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var aiValues = new ArrayList<Long>();
for (int i = 0; i < aiPinCount; i++) {
    aiValues.add(beUInt(rspBody, pos, 2));
    pos += 2;
}
var aiLWatchInfo = new ArrayList<Long>();
for (int i = 0; i < aiPinCount; i++) {
    aiLWatchInfo.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var diPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var diLevels = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diLevels.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var diCurrLevelMsec = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diCurrLevelMsec.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diCWatchInfo = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diCWatchInfo.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var diLWatchInfo = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diLWatchInfo.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var diRWatchInfo = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diRWatchInfo.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var doPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var doLevels = new ArrayList<Long>();
for (int i = 0; i < doPinCount; i++) {
    doLevels.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var lifetimeMs = beUInt(rspBody, pos, 8);
pos += 8;
(async () => {
  // Send the request (opcode 0x0A, no body)
  port.write(buildRequest(123456789012, 0x0A));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Read 1 failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const aiPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const aiValues = [];
  for (let i = 0; i < aiPinCount; i++) {
      aiValues.push(beUInt(rspBody, pos, 2));
      pos += 2;
  }
  const aiLWatchInfo = [];
  for (let i = 0; i < aiPinCount; i++) {
      aiLWatchInfo.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const diPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const diLevels = [];
  for (let i = 0; i < diPinCount; i++) {
      diLevels.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const diCurrLevelMsec = [];
  for (let i = 0; i < diPinCount; i++) {
      diCurrLevelMsec.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diCWatchInfo = [];
  for (let i = 0; i < diPinCount; i++) {
      diCWatchInfo.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const diLWatchInfo = [];
  for (let i = 0; i < diPinCount; i++) {
      diLWatchInfo.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const diRWatchInfo = [];
  for (let i = 0; i < diPinCount; i++) {
      diRWatchInfo.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const doPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const doLevels = [];
  for (let i = 0; i < doPinCount; i++) {
      doLevels.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const lifetimeMs = beUInt(rspBody, pos, 8);
  pos += 8;
})();

Read 1

Returns the analog inputs, the digital inputs (levels, time at level, and watch state), and the digital outputs.

Opcode: 0x0A. Body length: 0.

Request body: none.

Response body

Field Bytes Description
Ai_pin_count 1 Number of analog inputs.
Ai_values[] 2 Analog value per input, 0-4095. Repeated Ai_pin_count times.
Ai_lWatchInfo[] 1 Level-watch state per analog input. Repeated Ai_pin_count times.
Di_pin_count 1 Number of digital inputs.
Di_levels[] 1 Level of each digital input, 0 or 1. Repeated Di_pin_count times.
Di_currLevelMsec[] 8 Milliseconds at the current level. Repeated Di_pin_count times.
Di_cWatchInfo[] 1 Count-watch state per digital input. 1 if a watch is set, 2 if triggered. 0 if none. Repeated Di_pin_count times.
Di_lWatchInfo[] 1 Level-watch state per digital input. 1 if a watch is set, 2 if triggered. 0 if none. Repeated Di_pin_count times.
Di_rWatchInfo[] 1 Rate-watch state per digital input. 1 if a watch is set, 2 if triggered. 0 if none. Repeated Di_pin_count times.
Do_pin_count 1 Number of digital outputs.
Do_levels[] 1 Level of each digital output, 0 or 1. Repeated Do_pin_count times.
LifetimeMS 8 Milliseconds since start.

Example: Read 2

# Read 2 to serial number 123456789012 (opcode 0x0B)
printf '\x43\x1c\xbe\x99\x1a\x14\x0b\x00\x9e\xc1' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x0B, no body)
port.write(build_request(123456789012, 0x0B))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Read 2 failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = []
di_pin_count.times do
  di_levels << be_uint(rsp_body, pos, 1)
  pos += 1
end
di_prev_hi_ms = []
di_pin_count.times do
  di_prev_hi_ms << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_prev_lo_ms = []
di_pin_count.times do
  di_prev_lo_ms << be_uint(rsp_body, pos, 8)
  pos += 8
end
# Send the request (opcode 0x0B, no body)
port.write(build_request(123456789012, 0x0B))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Read 2 failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = []
for _ in range(di_pin_count):
    di_levels.append(be_uint(rsp_body, pos, 1))
    pos += 1
di_prev_hi_ms = []
for _ in range(di_pin_count):
    di_prev_hi_ms.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_prev_lo_ms = []
for _ in range(di_pin_count):
    di_prev_lo_ms.append(be_uint(rsp_body, pos, 8))
    pos += 8
// Send the request (opcode 0x0B, no body)
dio_write($port, build_request(123456789012, 0x0B));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Read 2 failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_levels = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_levels[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$di_prev_hi_ms = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_prev_hi_ms[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_prev_lo_ms = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_prev_lo_ms[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
# Send the request (opcode 0x0B, no body)
$port->write(build_request(123456789012, 0x0B));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Read 2 failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @di_levels;
for (1 .. $di_pin_count) {
    push @di_levels, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my @di_prev_hi_ms;
for (1 .. $di_pin_count) {
    push @di_prev_hi_ms, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_prev_lo_ms;
for (1 .. $di_pin_count) {
    push @di_prev_lo_ms, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
// Send the request (opcode 0x0B, no body)
port.writeBytes(buildRequest(123456789012L, 0x0B));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Read 2 failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var diPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var diLevels = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diLevels.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var diPrevHiMs = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diPrevHiMs.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diPrevLoMs = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diPrevLoMs.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
(async () => {
  // Send the request (opcode 0x0B, no body)
  port.write(buildRequest(123456789012, 0x0B));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Read 2 failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const diPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const diLevels = [];
  for (let i = 0; i < diPinCount; i++) {
      diLevels.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const diPrevHiMs = [];
  for (let i = 0; i < diPinCount; i++) {
      diPrevHiMs.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diPrevLoMs = [];
  for (let i = 0; i < diPinCount; i++) {
      diPrevLoMs.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
})();

Read 2

Returns the previous high and low pulse times for each digital input.

Opcode: 0x0B. Body length: 0.

Request body: none.

Response body

Field Bytes Description
Di_pin_count 1 Number of digital inputs.
Di_levels[] 1 Level of each digital input. Repeated Di_pin_count times.
Di_prevHiMs[] 8 High time of the previous pulse, in ms. Repeated Di_pin_count times.
Di_prevLoMs[] 8 Low time of the previous pulse, in ms. Repeated Di_pin_count times.

Example: Read 3

# Read 3 to serial number 123456789012 (opcode 0x0C)
printf '\x43\x1c\xbe\x99\x1a\x14\x0c\x00\x9c\xf1' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x0C, no body)
port.write(build_request(123456789012, 0x0C))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Read 3 failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = []
di_pin_count.times do
  di_levels << be_uint(rsp_body, pos, 1)
  pos += 1
end
di_resettable_pulse_counts = []
di_pin_count.times do
  di_resettable_pulse_counts << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_lifetime_pulse_counts = []
di_pin_count.times do
  di_lifetime_pulse_counts << be_uint(rsp_body, pos, 8)
  pos += 8
end
# Send the request (opcode 0x0C, no body)
port.write(build_request(123456789012, 0x0C))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Read 3 failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = []
for _ in range(di_pin_count):
    di_levels.append(be_uint(rsp_body, pos, 1))
    pos += 1
di_resettable_pulse_counts = []
for _ in range(di_pin_count):
    di_resettable_pulse_counts.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_lifetime_pulse_counts = []
for _ in range(di_pin_count):
    di_lifetime_pulse_counts.append(be_uint(rsp_body, pos, 8))
    pos += 8
// Send the request (opcode 0x0C, no body)
dio_write($port, build_request(123456789012, 0x0C));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Read 3 failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_levels = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_levels[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$di_resettable_pulse_counts = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_resettable_pulse_counts[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_lifetime_pulse_counts = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_lifetime_pulse_counts[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
# Send the request (opcode 0x0C, no body)
$port->write(build_request(123456789012, 0x0C));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Read 3 failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @di_levels;
for (1 .. $di_pin_count) {
    push @di_levels, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my @di_resettable_pulse_counts;
for (1 .. $di_pin_count) {
    push @di_resettable_pulse_counts, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_lifetime_pulse_counts;
for (1 .. $di_pin_count) {
    push @di_lifetime_pulse_counts, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
// Send the request (opcode 0x0C, no body)
port.writeBytes(buildRequest(123456789012L, 0x0C));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Read 3 failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var diPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var diLevels = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diLevels.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var diResettablePulseCounts = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diResettablePulseCounts.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diLifetimePulseCounts = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diLifetimePulseCounts.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
(async () => {
  // Send the request (opcode 0x0C, no body)
  port.write(buildRequest(123456789012, 0x0C));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Read 3 failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const diPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const diLevels = [];
  for (let i = 0; i < diPinCount; i++) {
      diLevels.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const diResettablePulseCounts = [];
  for (let i = 0; i < diPinCount; i++) {
      diResettablePulseCounts.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diLifetimePulseCounts = [];
  for (let i = 0; i < diPinCount; i++) {
      diLifetimePulseCounts.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
})();

Read 3

Returns the resettable and lifetime pulse counts for each digital input.

Opcode: 0x0C. Body length: 0.

Request body: none.

Response body

Field Bytes Description
Di_pin_count 1 Number of digital inputs.
Di_levels[] 1 Level of each digital input. Repeated Di_pin_count times.
Di_resettablePulseCounts[] 8 Pulse count since the last reset. Repeated Di_pin_count times.
Di_lifetimePulseCounts[] 8 Lifetime pulse count. Repeated Di_pin_count times.

Example: Read 4

# Read 4 to serial number 123456789012 (opcode 0x0D)
printf '\x43\x1c\xbe\x99\x1a\x14\x0d\x00\x9d\x61' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x0D, no body)
port.write(build_request(123456789012, 0x0D))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Read 4 failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = []
di_pin_count.times do
  di_levels << be_uint(rsp_body, pos, 1)
  pos += 1
end
di_total_hi_seconds = []
di_pin_count.times do
  di_total_hi_seconds << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_total_low_seconds = []
di_pin_count.times do
  di_total_low_seconds << be_uint(rsp_body, pos, 8)
  pos += 8
end
# Send the request (opcode 0x0D, no body)
port.write(build_request(123456789012, 0x0D))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Read 4 failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = []
for _ in range(di_pin_count):
    di_levels.append(be_uint(rsp_body, pos, 1))
    pos += 1
di_total_hi_seconds = []
for _ in range(di_pin_count):
    di_total_hi_seconds.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_total_low_seconds = []
for _ in range(di_pin_count):
    di_total_low_seconds.append(be_uint(rsp_body, pos, 8))
    pos += 8
// Send the request (opcode 0x0D, no body)
dio_write($port, build_request(123456789012, 0x0D));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Read 4 failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_levels = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_levels[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$di_total_hi_seconds = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_total_hi_seconds[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_total_low_seconds = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_total_low_seconds[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
# Send the request (opcode 0x0D, no body)
$port->write(build_request(123456789012, 0x0D));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Read 4 failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @di_levels;
for (1 .. $di_pin_count) {
    push @di_levels, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my @di_total_hi_seconds;
for (1 .. $di_pin_count) {
    push @di_total_hi_seconds, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_total_low_seconds;
for (1 .. $di_pin_count) {
    push @di_total_low_seconds, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
// Send the request (opcode 0x0D, no body)
port.writeBytes(buildRequest(123456789012L, 0x0D));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Read 4 failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var diPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var diLevels = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diLevels.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var diTotalHiSeconds = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diTotalHiSeconds.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diTotalLowSeconds = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diTotalLowSeconds.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
(async () => {
  // Send the request (opcode 0x0D, no body)
  port.write(buildRequest(123456789012, 0x0D));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Read 4 failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const diPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const diLevels = [];
  for (let i = 0; i < diPinCount; i++) {
      diLevels.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const diTotalHiSeconds = [];
  for (let i = 0; i < diPinCount; i++) {
      diTotalHiSeconds.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diTotalLowSeconds = [];
  for (let i = 0; i < diPinCount; i++) {
      diTotalLowSeconds.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
})();

Read 4

Returns the total high and low time, in seconds, for each digital input.

Opcode: 0x0D. Body length: 0.

Request body: none.

Response body

Field Bytes Description
Di_pin_count 1 Number of digital inputs.
Di_levels[] 1 Level of each digital input. Repeated Di_pin_count times.
Di_totalHiSeconds[] 8 Total high time, in seconds. Repeated Di_pin_count times.
Di_totalLowSeconds[] 8 Total low time, in seconds. Repeated Di_pin_count times.

Example: Read 5

# Read 5 to serial number 123456789012 (opcode 0x0E)
printf '\x43\x1c\xbe\x99\x1a\x14\x0e\x00\x9d\x91' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x0E, no body)
port.write(build_request(123456789012, 0x0E))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Read 5 failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = []
di_pin_count.times do
  di_levels << be_uint(rsp_body, pos, 1)
  pos += 1
end
di_prev_hi_ms = []
di_pin_count.times do
  di_prev_hi_ms << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_prev_lo_ms = []
di_pin_count.times do
  di_prev_lo_ms << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_resettable_pulse_counts = []
di_pin_count.times do
  di_resettable_pulse_counts << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_lifetime_pulse_counts = []
di_pin_count.times do
  di_lifetime_pulse_counts << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_total_hi_seconds = []
di_pin_count.times do
  di_total_hi_seconds << be_uint(rsp_body, pos, 8)
  pos += 8
end
di_total_low_seconds = []
di_pin_count.times do
  di_total_low_seconds << be_uint(rsp_body, pos, 8)
  pos += 8
end
# Send the request (opcode 0x0E, no body)
port.write(build_request(123456789012, 0x0E))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Read 5 failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
di_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
di_levels = []
for _ in range(di_pin_count):
    di_levels.append(be_uint(rsp_body, pos, 1))
    pos += 1
di_prev_hi_ms = []
for _ in range(di_pin_count):
    di_prev_hi_ms.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_prev_lo_ms = []
for _ in range(di_pin_count):
    di_prev_lo_ms.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_resettable_pulse_counts = []
for _ in range(di_pin_count):
    di_resettable_pulse_counts.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_lifetime_pulse_counts = []
for _ in range(di_pin_count):
    di_lifetime_pulse_counts.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_total_hi_seconds = []
for _ in range(di_pin_count):
    di_total_hi_seconds.append(be_uint(rsp_body, pos, 8))
    pos += 8
di_total_low_seconds = []
for _ in range(di_pin_count):
    di_total_low_seconds.append(be_uint(rsp_body, pos, 8))
    pos += 8
// Send the request (opcode 0x0E, no body)
dio_write($port, build_request(123456789012, 0x0E));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Read 5 failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_levels = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_levels[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
$di_prev_hi_ms = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_prev_hi_ms[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_prev_lo_ms = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_prev_lo_ms[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_resettable_pulse_counts = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_resettable_pulse_counts[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_lifetime_pulse_counts = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_lifetime_pulse_counts[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_total_hi_seconds = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_total_hi_seconds[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
$di_total_low_seconds = [];
for ($i = 0; $i < $di_pin_count; $i++) {
    $di_total_low_seconds[] = be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
# Send the request (opcode 0x0E, no body)
$port->write(build_request(123456789012, 0x0E));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Read 5 failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $di_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @di_levels;
for (1 .. $di_pin_count) {
    push @di_levels, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
my @di_prev_hi_ms;
for (1 .. $di_pin_count) {
    push @di_prev_hi_ms, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_prev_lo_ms;
for (1 .. $di_pin_count) {
    push @di_prev_lo_ms, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_resettable_pulse_counts;
for (1 .. $di_pin_count) {
    push @di_resettable_pulse_counts, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_lifetime_pulse_counts;
for (1 .. $di_pin_count) {
    push @di_lifetime_pulse_counts, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_total_hi_seconds;
for (1 .. $di_pin_count) {
    push @di_total_hi_seconds, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
my @di_total_low_seconds;
for (1 .. $di_pin_count) {
    push @di_total_low_seconds, be_uint($rsp_body, $pos, 8);
    $pos += 8;
}
// Send the request (opcode 0x0E, no body)
port.writeBytes(buildRequest(123456789012L, 0x0E));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Read 5 failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var diPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var diLevels = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diLevels.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
var diPrevHiMs = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diPrevHiMs.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diPrevLoMs = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diPrevLoMs.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diResettablePulseCounts = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diResettablePulseCounts.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diLifetimePulseCounts = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diLifetimePulseCounts.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diTotalHiSeconds = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diTotalHiSeconds.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
var diTotalLowSeconds = new ArrayList<Long>();
for (int i = 0; i < diPinCount; i++) {
    diTotalLowSeconds.add(beUInt(rspBody, pos, 8));
    pos += 8;
}
(async () => {
  // Send the request (opcode 0x0E, no body)
  port.write(buildRequest(123456789012, 0x0E));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Read 5 failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const diPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const diLevels = [];
  for (let i = 0; i < diPinCount; i++) {
      diLevels.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
  const diPrevHiMs = [];
  for (let i = 0; i < diPinCount; i++) {
      diPrevHiMs.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diPrevLoMs = [];
  for (let i = 0; i < diPinCount; i++) {
      diPrevLoMs.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diResettablePulseCounts = [];
  for (let i = 0; i < diPinCount; i++) {
      diResettablePulseCounts.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diLifetimePulseCounts = [];
  for (let i = 0; i < diPinCount; i++) {
      diLifetimePulseCounts.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diTotalHiSeconds = [];
  for (let i = 0; i < diPinCount; i++) {
      diTotalHiSeconds.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
  const diTotalLowSeconds = [];
  for (let i = 0; i < diPinCount; i++) {
      diTotalLowSeconds.push(beUInt(rspBody, pos, 8));
      pos += 8;
  }
})();

Read 5

Returns all the pulse and time data for digital inputs 0 to 4. Available only when the device has five or fewer digital inputs. Otherwise the device returns RC_CMD_UNAVAILABLE.

Opcode: 0x0E. Body length: 0.

Request body: none.

Response body

Field Bytes Description
Di_pin_count 1 Number of digital inputs in this group.
Di_levels[] 1 Level of each digital input. Repeated Di_pin_count times.
Di_prevHiMs[] 8 High time of the previous pulse, in ms. Repeated Di_pin_count times.
Di_prevLoMs[] 8 Low time of the previous pulse, in ms. Repeated Di_pin_count times.
Di_resettablePulseCounts[] 8 Pulse count since the last reset. Repeated Di_pin_count times.
Di_lifetimePulseCounts[] 8 Lifetime pulse count. Repeated Di_pin_count times.
Di_totalHiSeconds[] 8 Total high time, in seconds. Repeated Di_pin_count times.
Di_totalLowSeconds[] 8 Total low time, in seconds. Repeated Di_pin_count times.

Analog Input Requests

Example: AI Get Values

# AI Get Values to serial number 123456789012 (opcode 0x11)
printf '\x43\x1c\xbe\x99\x1a\x14\x11\x00\x95\xa1' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x11, no body)
port.write(build_request(123456789012, 0x11))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('AI Get Values failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
ai_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
ai_value = []
ai_pin_count.times do
  ai_value << be_uint(rsp_body, pos, 2)
  pos += 2
end
# Send the request (opcode 0x11, no body)
port.write(build_request(123456789012, 0x11))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'AI Get Values failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
ai_pin_count = be_uint(rsp_body, pos, 1)
pos += 1
ai_value = []
for _ in range(ai_pin_count):
    ai_value.append(be_uint(rsp_body, pos, 2))
    pos += 2
// Send the request (opcode 0x11, no body)
dio_write($port, build_request(123456789012, 0x11));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('AI Get Values failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$ai_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$ai_value = [];
for ($i = 0; $i < $ai_pin_count; $i++) {
    $ai_value[] = be_uint($rsp_body, $pos, 2);
    $pos += 2;
}
# Send the request (opcode 0x11, no body)
$port->write(build_request(123456789012, 0x11));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("AI Get Values failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $ai_pin_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @ai_value;
for (1 .. $ai_pin_count) {
    push @ai_value, be_uint($rsp_body, $pos, 2);
    $pos += 2;
}
// Send the request (opcode 0x11, no body)
port.writeBytes(buildRequest(123456789012L, 0x11));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("AI Get Values failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var aiPinCount = beUInt(rspBody, pos, 1);
pos += 1;
var aiValue = new ArrayList<Long>();
for (int i = 0; i < aiPinCount; i++) {
    aiValue.add(beUInt(rspBody, pos, 2));
    pos += 2;
}
(async () => {
  // Send the request (opcode 0x11, no body)
  port.write(buildRequest(123456789012, 0x11));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('AI Get Values failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const aiPinCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const aiValue = [];
  for (let i = 0; i < aiPinCount; i++) {
      aiValue.push(beUInt(rspBody, pos, 2));
      pos += 2;
  }
})();

AI Get Values

Returns the current value of every analog input. Each value is 0-4095. To convert to volts, use volts = value * 3.331 / 4095.

Opcode: 0x11. Body length: 0.

Request body: none.

Response body

Field Bytes Description
Ai_pin_count 1 Number of analog inputs.
Ai_value[] 2 Value of each analog input, 0-4095. 0xFFFF means error. Repeated Ai_pin_count times.

Example: AI Set Level Watch

# AI Set Level Watch to serial number 123456789012 (opcode 0x12)
printf '\x43\x1c\xbe\x99\x1a\x14\x12\x1c\x00\x00\x00\x00\x00\x08\x00\x03\xe8\x00\x0a\x00\x05\x01\x02\x00\x00\x00\x05\x00\x00\x00\x05\x00\x03\x00\x00\x01\x76\xe6' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 4),
  be(0, 1),
  be(2048, 2),
  be(1000, 2),
  be(10, 2),
  be(5, 2),
  be(1, 1),
  be(2, 1),
  be(5, 4),
  be(5, 4),
  be(3, 2),
  be(0, 1),
  be(0, 1),
  be(1, 1),
].join

# Send the request (opcode 0x12)
port.write(build_request(123456789012, 0x12, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('AI Set Level Watch failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
was_cleared = be_uint(rsp_body, pos, 1)
pos += 1
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 4),
    be(0, 1),
    be(2048, 2),
    be(1000, 2),
    be(10, 2),
    be(5, 2),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
])

# Send the request (opcode 0x12)
port.write(build_request(123456789012, 0x12, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'AI Set Level Watch failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
was_cleared = be_uint(rsp_body, pos, 1)
pos += 1
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 4),
    be(0, 1),
    be(2048, 2),
    be(1000, 2),
    be(10, 2),
    be(5, 2),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
]);

// Send the request (opcode 0x12)
dio_write($port, build_request(123456789012, 0x12, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('AI Set Level Watch failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$was_cleared = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 4),
  be(0, 1),
  be(2048, 2),
  be(1000, 2),
  be(10, 2),
  be(5, 2),
  be(1, 1),
  be(2, 1),
  be(5, 4),
  be(5, 4),
  be(3, 2),
  be(0, 1),
  be(0, 1),
  be(1, 1),
);

# Send the request (opcode 0x12)
$port->write(build_request(123456789012, 0x12, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("AI Set Level Watch failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $was_cleared = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 4),
    be(0, 1),
    be(2048, 2),
    be(1000, 2),
    be(10, 2),
    be(5, 2),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1)
);

// Send the request (opcode 0x12)
port.writeBytes(buildRequest(123456789012L, 0x12, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("AI Set Level Watch failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var wasCleared = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 4),
    be(0, 1),
    be(2048, 2),
    be(1000, 2),
    be(10, 2),
    be(5, 2),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
  ]);

  // Send the request (opcode 0x12)
  port.write(buildRequest(123456789012, 0x12, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('AI Set Level Watch failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const wasCleared = beUInt(rspBody, pos, 1);
  pos += 1;
})();

AI Set Level Watch

Sets a level watch on an analog input. When the value stays above GreaterThan or below LessThan for the minimum time, the watch drives a digital output with a waveform. Set both GreaterThan to 0xFFF and LessThan to 0 to clear the watch.

Opcode: 0x12. Body length: 28.

Request body

Field Bytes Description
Password 4 Password, 4 bytes. Always use the factory password 00000000.
Ai_pin 1 Analog input index.
GreaterThan 2 Upper threshold, 0-4095.
LessThan 2 Lower threshold, 0-4095.
MinTrueSec 2 Seconds the condition must be true before the watch fires.
MinFalseSec 2 Seconds the condition must be false before the watch clears.
Restart 1 0 clears the watch after it triggers. 1 restarts it after it triggers. 2 restarts it after it triggers and after a chip reset.
Do_pin 1 Digital output to drive. 0xFF means no output.
Hi_sec 4 Seconds the output stays high in each cycle.
Low_sec 4 Seconds the output stays low in each cycle.
Wave_cycles 2 Number of cycles. 0 means repeat forever.
Initial_level 1 Output level before the first cycle.
Interim_level 1 Output level between cycles.
Final_level 1 Output level after the last cycle.

Response body

Field Bytes Description
WasCleared 1 1 if an existing watch was replaced, 0 if not. For RC_DO_BUSY_ERR see the note below.
  • If the status is RC_DO_BUSY_ERR (0x93), the body holds the owner ID of the waveform that is using the output instead.

Example: AI Get Level Watch

# AI Get Level Watch to serial number 123456789012 (opcode 0x13)
printf '\x43\x1c\xbe\x99\x1a\x14\x13\x01\x00\xc1\x3f' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
].join

# Send the request (opcode 0x13)
port.write(build_request(123456789012, 0x13, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('AI Get Level Watch failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
ai_current_value = be_uint(rsp_body, pos, 2)
pos += 2
greater_than = be_uint(rsp_body, pos, 2)
pos += 2
less_than = be_uint(rsp_body, pos, 2)
pos += 2
min_true_sec = be_uint(rsp_body, pos, 2)
pos += 2
min_false_sec = be_uint(rsp_body, pos, 2)
pos += 2
restart = be_uint(rsp_body, pos, 1)
pos += 1
do_pin = be_uint(rsp_body, pos, 1)
pos += 1
hi_sec = be_uint(rsp_body, pos, 4)
pos += 4
low_sec = be_uint(rsp_body, pos, 4)
pos += 4
wave_cycles = be_uint(rsp_body, pos, 2)
pos += 2
initial_level = be_uint(rsp_body, pos, 1)
pos += 1
interim_level = be_uint(rsp_body, pos, 1)
pos += 1
final_level = be_uint(rsp_body, pos, 1)
pos += 1
hit_count = be_uint(rsp_body, pos, 2)
pos += 2
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
])

# Send the request (opcode 0x13)
port.write(build_request(123456789012, 0x13, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'AI Get Level Watch failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
ai_current_value = be_uint(rsp_body, pos, 2)
pos += 2
greater_than = be_uint(rsp_body, pos, 2)
pos += 2
less_than = be_uint(rsp_body, pos, 2)
pos += 2
min_true_sec = be_uint(rsp_body, pos, 2)
pos += 2
min_false_sec = be_uint(rsp_body, pos, 2)
pos += 2
restart = be_uint(rsp_body, pos, 1)
pos += 1
do_pin = be_uint(rsp_body, pos, 1)
pos += 1
hi_sec = be_uint(rsp_body, pos, 4)
pos += 4
low_sec = be_uint(rsp_body, pos, 4)
pos += 4
wave_cycles = be_uint(rsp_body, pos, 2)
pos += 2
initial_level = be_uint(rsp_body, pos, 1)
pos += 1
interim_level = be_uint(rsp_body, pos, 1)
pos += 1
final_level = be_uint(rsp_body, pos, 1)
pos += 1
hit_count = be_uint(rsp_body, pos, 2)
pos += 2
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
]);

// Send the request (opcode 0x13)
dio_write($port, build_request(123456789012, 0x13, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('AI Get Level Watch failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$ai_current_value = be_uint($rsp_body, $pos, 2);
$pos += 2;
$greater_than = be_uint($rsp_body, $pos, 2);
$pos += 2;
$less_than = be_uint($rsp_body, $pos, 2);
$pos += 2;
$min_true_sec = be_uint($rsp_body, $pos, 2);
$pos += 2;
$min_false_sec = be_uint($rsp_body, $pos, 2);
$pos += 2;
$restart = be_uint($rsp_body, $pos, 1);
$pos += 1;
$do_pin = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hi_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
$low_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
$wave_cycles = be_uint($rsp_body, $pos, 2);
$pos += 2;
$initial_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$interim_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$final_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hit_count = be_uint($rsp_body, $pos, 2);
$pos += 2;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
);

# Send the request (opcode 0x13)
$port->write(build_request(123456789012, 0x13, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("AI Get Level Watch failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $ai_current_value = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $greater_than = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $less_than = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $min_true_sec = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $min_false_sec = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $restart = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $do_pin = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hi_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $low_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $wave_cycles = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $initial_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $interim_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $final_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hit_count = be_uint($rsp_body, $pos, 2);
$pos += 2;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1)
);

// Send the request (opcode 0x13)
port.writeBytes(buildRequest(123456789012L, 0x13, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("AI Get Level Watch failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var aiCurrentValue = beUInt(rspBody, pos, 2);
pos += 2;
var greaterThan = beUInt(rspBody, pos, 2);
pos += 2;
var lessThan = beUInt(rspBody, pos, 2);
pos += 2;
var minTrueSec = beUInt(rspBody, pos, 2);
pos += 2;
var minFalseSec = beUInt(rspBody, pos, 2);
pos += 2;
var restart = beUInt(rspBody, pos, 1);
pos += 1;
var doPin = beUInt(rspBody, pos, 1);
pos += 1;
var hiSec = beUInt(rspBody, pos, 4);
pos += 4;
var lowSec = beUInt(rspBody, pos, 4);
pos += 4;
var waveCycles = beUInt(rspBody, pos, 2);
pos += 2;
var initialLevel = beUInt(rspBody, pos, 1);
pos += 1;
var interimLevel = beUInt(rspBody, pos, 1);
pos += 1;
var finalLevel = beUInt(rspBody, pos, 1);
pos += 1;
var hitCount = beUInt(rspBody, pos, 2);
pos += 2;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
  ]);

  // Send the request (opcode 0x13)
  port.write(buildRequest(123456789012, 0x13, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('AI Get Level Watch failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const aiCurrentValue = beUInt(rspBody, pos, 2);
  pos += 2;
  const greaterThan = beUInt(rspBody, pos, 2);
  pos += 2;
  const lessThan = beUInt(rspBody, pos, 2);
  pos += 2;
  const minTrueSec = beUInt(rspBody, pos, 2);
  pos += 2;
  const minFalseSec = beUInt(rspBody, pos, 2);
  pos += 2;
  const restart = beUInt(rspBody, pos, 1);
  pos += 1;
  const doPin = beUInt(rspBody, pos, 1);
  pos += 1;
  const hiSec = beUInt(rspBody, pos, 4);
  pos += 4;
  const lowSec = beUInt(rspBody, pos, 4);
  pos += 4;
  const waveCycles = beUInt(rspBody, pos, 2);
  pos += 2;
  const initialLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const interimLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const finalLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const hitCount = beUInt(rspBody, pos, 2);
  pos += 2;
})();

AI Get Level Watch

Returns the level watch settings and state for one analog input.

Opcode: 0x13. Body length: 1.

Request body

Field Bytes Description
Ai_pin 1 Analog input index.

Response body

Field Bytes Description
Ai_currentValue 2 Current analog value.
GreaterThan 2 Upper threshold.
LessThan 2 Lower threshold.
MinTrueSec 2 Seconds the condition must be true.
MinFalseSec 2 Seconds the condition must be false.
Restart 1 Restart flag.
Do_pin 1 Digital output driven by the watch.
Hi_sec 4 High seconds per cycle.
Low_sec 4 Low seconds per cycle.
Wave_cycles 2 Number of cycles.
Initial_level 1 Initial output level.
Interim_level 1 Interim output level.
Final_level 1 Final output level.
HitCount 2 Number of times the watch has fired.
  • Returns RC_NO_WATCH_FOUND_ERR if no watch is set on that input.

Date and Time Requests

Example: Get Date and Time

# Get Date and Time to serial number 123456789012 (opcode 0x16)
printf '\x43\x1c\xbe\x99\x1a\x14\x16\x00\x97\x91' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x16, no body)
port.write(build_request(123456789012, 0x16))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Get Date and Time failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
second = be_uint(rsp_body, pos, 1)
pos += 1
minute = be_uint(rsp_body, pos, 1)
pos += 1
hour = be_uint(rsp_body, pos, 1)
pos += 1
day = be_uint(rsp_body, pos, 1)
pos += 1
month = be_uint(rsp_body, pos, 1)
pos += 1
year = be_uint(rsp_body, pos, 2)
pos += 2
# Send the request (opcode 0x16, no body)
port.write(build_request(123456789012, 0x16))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Get Date and Time failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
second = be_uint(rsp_body, pos, 1)
pos += 1
minute = be_uint(rsp_body, pos, 1)
pos += 1
hour = be_uint(rsp_body, pos, 1)
pos += 1
day = be_uint(rsp_body, pos, 1)
pos += 1
month = be_uint(rsp_body, pos, 1)
pos += 1
year = be_uint(rsp_body, pos, 2)
pos += 2
// Send the request (opcode 0x16, no body)
dio_write($port, build_request(123456789012, 0x16));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Get Date and Time failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$second = be_uint($rsp_body, $pos, 1);
$pos += 1;
$minute = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hour = be_uint($rsp_body, $pos, 1);
$pos += 1;
$day = be_uint($rsp_body, $pos, 1);
$pos += 1;
$month = be_uint($rsp_body, $pos, 1);
$pos += 1;
$year = be_uint($rsp_body, $pos, 2);
$pos += 2;
# Send the request (opcode 0x16, no body)
$port->write(build_request(123456789012, 0x16));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Get Date and Time failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $second = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $minute = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hour = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $day = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $month = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $year = be_uint($rsp_body, $pos, 2);
$pos += 2;
// Send the request (opcode 0x16, no body)
port.writeBytes(buildRequest(123456789012L, 0x16));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Get Date and Time failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var second = beUInt(rspBody, pos, 1);
pos += 1;
var minute = beUInt(rspBody, pos, 1);
pos += 1;
var hour = beUInt(rspBody, pos, 1);
pos += 1;
var day = beUInt(rspBody, pos, 1);
pos += 1;
var month = beUInt(rspBody, pos, 1);
pos += 1;
var year = beUInt(rspBody, pos, 2);
pos += 2;
(async () => {
  // Send the request (opcode 0x16, no body)
  port.write(buildRequest(123456789012, 0x16));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Get Date and Time failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const second = beUInt(rspBody, pos, 1);
  pos += 1;
  const minute = beUInt(rspBody, pos, 1);
  pos += 1;
  const hour = beUInt(rspBody, pos, 1);
  pos += 1;
  const day = beUInt(rspBody, pos, 1);
  pos += 1;
  const month = beUInt(rspBody, pos, 1);
  pos += 1;
  const year = beUInt(rspBody, pos, 2);
  pos += 2;
})();

Get Date and Time

Returns the device’s real-time clock.

Opcode: 0x16. Body length: 0.

Request body: none.

Response body

Field Bytes Description
Second 1 Seconds, 0-59.
Minute 1 Minutes, 0-59.
Hour 1 Hours, 0-23.
Day 1 Day of month, 1-31.
Month 1 Month, 1-12.
Year 2 Year.

Example: Set Date and Time

# Set Date and Time to serial number 123456789012 (opcode 0x17)
printf '\x43\x1c\xbe\x99\x1a\x14\x17\x07\x1e\x0f\x0c\x1b\x0b\x07\xea\xac\x58' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(30, 1),
  be(15, 1),
  be(12, 1),
  be(27, 1),
  be(11, 1),
  be(2026, 2),
].join

# Send the request (opcode 0x17)
port.write(build_request(123456789012, 0x17, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Set Date and Time failed: 0x%02X', rc) unless rc == 0x00
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(30, 1),
    be(15, 1),
    be(12, 1),
    be(27, 1),
    be(11, 1),
    be(2026, 2),
])

# Send the request (opcode 0x17)
port.write(build_request(123456789012, 0x17, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Set Date and Time failed: {rc:#04x}')
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(30, 1),
    be(15, 1),
    be(12, 1),
    be(27, 1),
    be(11, 1),
    be(2026, 2),
]);

// Send the request (opcode 0x17)
dio_write($port, build_request(123456789012, 0x17, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Set Date and Time failed: 0x%02X', $rc));
}
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(30, 1),
  be(15, 1),
  be(12, 1),
  be(27, 1),
  be(11, 1),
  be(2026, 2),
);

# Send the request (opcode 0x17)
$port->write(build_request(123456789012, 0x17, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Set Date and Time failed: 0x%02X\n", $rc) unless $rc == 0x00;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(30, 1),
    be(15, 1),
    be(12, 1),
    be(27, 1),
    be(11, 1),
    be(2026, 2)
);

// Send the request (opcode 0x17)
port.writeBytes(buildRequest(123456789012L, 0x17, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Set Date and Time failed: 0x%02X", rc));
}
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(30, 1),
    be(15, 1),
    be(12, 1),
    be(27, 1),
    be(11, 1),
    be(2026, 2),
  ]);

  // Send the request (opcode 0x17)
  port.write(buildRequest(123456789012, 0x17, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Set Date and Time failed: 0x' + rc.toString(16));
})();

Set Date and Time

Sets the real-time clock.

Opcode: 0x17. Body length: 7.

Request body

Field Bytes Description
Second 1 Seconds, 0-59.
Minute 1 Minutes, 0-59.
Hour 1 Hours, 0-23.
Day 1 Day of month, 1-31.
Month 1 Month, 1-12.
Year 2 Year. Must be 1970 or later.

Response body: status only.

  • Returns RC_CMD_PARAM_ERR if a value is out of range.

Example: Adjust Date and Time

# Adjust Date and Time to serial number 123456789012 (opcode 0x15)
printf '\x43\x1c\xbe\x99\x1a\x14\x15\x03\x00\x00\x00\x98\x38' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
  be(0, 2),
].join

# Send the request (opcode 0x15)
port.write(build_request(123456789012, 0x15, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('Adjust Date and Time failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
adjustment_values = be_uint(rsp_body, pos, 2)
pos += 2
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
    be(0, 2),
])

# Send the request (opcode 0x15)
port.write(build_request(123456789012, 0x15, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'Adjust Date and Time failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
adjustment_values = be_uint(rsp_body, pos, 2)
pos += 2
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
    be(0, 2),
]);

// Send the request (opcode 0x15)
dio_write($port, build_request(123456789012, 0x15, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('Adjust Date and Time failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$adjustment_values = be_uint($rsp_body, $pos, 2);
$pos += 2;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
  be(0, 2),
);

# Send the request (opcode 0x15)
$port->write(build_request(123456789012, 0x15, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("Adjust Date and Time failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $adjustment_values = be_uint($rsp_body, $pos, 2);
$pos += 2;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1),
    be(0, 2)
);

// Send the request (opcode 0x15)
port.writeBytes(buildRequest(123456789012L, 0x15, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("Adjust Date and Time failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var adjustmentValues = beUInt(rspBody, pos, 2);
pos += 2;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
    be(0, 2),
  ]);

  // Send the request (opcode 0x15)
  port.write(buildRequest(123456789012, 0x15, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('Adjust Date and Time failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const adjustmentValues = beUInt(rspBody, pos, 2);
  pos += 2;
})();

Adjust Date and Time

Reads or changes the clock speed correction. AdjustmentValues is 2 bytes: the high byte is Skips and the low byte is a signed Amount. Each second, the clock is adjusted by (Amount / Skips) * 30.51758 microseconds, so Skips 0 applies the full Amount every second. Send WriteFlag 0 to read the current value without changing it. Examples: Skips 0 and Amount 24 speeds the clock up by 24 * 30.51758 us each second. Skips 0 and Amount -1 slows it by 30.51758 us.

Opcode: 0x15. Body length: 3.

Request body

Field Bytes Description
WriteFlag 1 1 to write the adjustment, 0 to read only.
AdjustmentValues 2 Skips (high byte) and Amount (low byte, signed). 0x0000 means no adjustment.

Response body

Field Bytes Description
AdjustmentValues 2 The adjustment that is in effect.

Digital Input Requests

Example: DI Get Levels

# DI Get Levels to serial number 123456789012 (opcode 0x20)
printf '\x43\x1c\xbe\x99\x1a\x14\x20\x00\x80\x31' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x20, no body)
port.write(build_request(123456789012, 0x20))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DI Get Levels failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
curr_levels_map = be_uint(rsp_body, pos, 1)
pos += 1
# Send the request (opcode 0x20, no body)
port.write(build_request(123456789012, 0x20))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DI Get Levels failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
curr_levels_map = be_uint(rsp_body, pos, 1)
pos += 1
// Send the request (opcode 0x20, no body)
dio_write($port, build_request(123456789012, 0x20));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DI Get Levels failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$curr_levels_map = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Send the request (opcode 0x20, no body)
$port->write(build_request(123456789012, 0x20));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DI Get Levels failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $curr_levels_map = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Send the request (opcode 0x20, no body)
port.writeBytes(buildRequest(123456789012L, 0x20));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DI Get Levels failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var currLevelsMap = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Send the request (opcode 0x20, no body)
  port.write(buildRequest(123456789012, 0x20));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DI Get Levels failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const currLevelsMap = beUInt(rspBody, pos, 1);
  pos += 1;
})();

DI Get Levels

Returns the current level of every digital input as a bitmap. Bit 0 is DI 0.

Opcode: 0x20. Body length: 0.

Request body: none.

Response body

Field Bytes Description
CurrLevelsMap 1 Bitmap of levels. Bit 0 is DI 0.

Example: DI Get Pulse Info

# DI Get Pulse Info to serial number 123456789012 (opcode 0x21)
printf '\x43\x1c\xbe\x99\x1a\x14\x21\x01\x00\x60\xf0' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
].join

# Send the request (opcode 0x21)
port.write(build_request(123456789012, 0x21, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DI Get Pulse Info failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
current_state = be_uint(rsp_body, pos, 1)
pos += 1
current_level_ms = be_uint(rsp_body, pos, 8)
pos += 8
prev_hi_ms = be_uint(rsp_body, pos, 8)
pos += 8
prev_low_ms = be_uint(rsp_body, pos, 8)
pos += 8
life_hi_sec = be_uint(rsp_body, pos, 8)
pos += 8
life_low_sec = be_uint(rsp_body, pos, 8)
pos += 8
resettable_count = be_uint(rsp_body, pos, 8)
pos += 8
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
])

# Send the request (opcode 0x21)
port.write(build_request(123456789012, 0x21, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DI Get Pulse Info failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
current_state = be_uint(rsp_body, pos, 1)
pos += 1
current_level_ms = be_uint(rsp_body, pos, 8)
pos += 8
prev_hi_ms = be_uint(rsp_body, pos, 8)
pos += 8
prev_low_ms = be_uint(rsp_body, pos, 8)
pos += 8
life_hi_sec = be_uint(rsp_body, pos, 8)
pos += 8
life_low_sec = be_uint(rsp_body, pos, 8)
pos += 8
resettable_count = be_uint(rsp_body, pos, 8)
pos += 8
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
]);

// Send the request (opcode 0x21)
dio_write($port, build_request(123456789012, 0x21, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DI Get Pulse Info failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$current_state = be_uint($rsp_body, $pos, 1);
$pos += 1;
$current_level_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
$prev_hi_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
$prev_low_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
$life_hi_sec = be_uint($rsp_body, $pos, 8);
$pos += 8;
$life_low_sec = be_uint($rsp_body, $pos, 8);
$pos += 8;
$resettable_count = be_uint($rsp_body, $pos, 8);
$pos += 8;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
);

# Send the request (opcode 0x21)
$port->write(build_request(123456789012, 0x21, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DI Get Pulse Info failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $current_state = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $current_level_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
my $prev_hi_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
my $prev_low_ms = be_uint($rsp_body, $pos, 8);
$pos += 8;
my $life_hi_sec = be_uint($rsp_body, $pos, 8);
$pos += 8;
my $life_low_sec = be_uint($rsp_body, $pos, 8);
$pos += 8;
my $resettable_count = be_uint($rsp_body, $pos, 8);
$pos += 8;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1)
);

// Send the request (opcode 0x21)
port.writeBytes(buildRequest(123456789012L, 0x21, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DI Get Pulse Info failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var currentState = beUInt(rspBody, pos, 1);
pos += 1;
var currentLevelMs = beUInt(rspBody, pos, 8);
pos += 8;
var prevHiMs = beUInt(rspBody, pos, 8);
pos += 8;
var prevLowMs = beUInt(rspBody, pos, 8);
pos += 8;
var lifeHiSec = beUInt(rspBody, pos, 8);
pos += 8;
var lifeLowSec = beUInt(rspBody, pos, 8);
pos += 8;
var resettableCount = beUInt(rspBody, pos, 8);
pos += 8;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
  ]);

  // Send the request (opcode 0x21)
  port.write(buildRequest(123456789012, 0x21, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DI Get Pulse Info failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const currentState = beUInt(rspBody, pos, 1);
  pos += 1;
  const currentLevelMs = beUInt(rspBody, pos, 8);
  pos += 8;
  const prevHiMs = beUInt(rspBody, pos, 8);
  pos += 8;
  const prevLowMs = beUInt(rspBody, pos, 8);
  pos += 8;
  const lifeHiSec = beUInt(rspBody, pos, 8);
  pos += 8;
  const lifeLowSec = beUInt(rspBody, pos, 8);
  pos += 8;
  const resettableCount = beUInt(rspBody, pos, 8);
  pos += 8;
})();

DI Get Pulse Info

Returns the pulse and time data for one digital input.

Opcode: 0x21. Body length: 1.

Request body

Field Bytes Description
Di_pin 1 Digital input index.

Response body

Field Bytes Description
Current_state 1 Current level, 0 or 1.
Current_level_ms 8 Milliseconds at the current level.
Prev_hi_ms 8 High time of the previous pulse, in ms.
Prev_low_ms 8 Low time of the previous pulse, in ms.
Life_hi_sec 8 Lifetime high time, in seconds.
Life_low_sec 8 Lifetime low time, in seconds.
Resettable_count 8 Pulse count since the last reset.

Example: DI Get Counts

# DI Get Counts to serial number 123456789012 (opcode 0x22)
printf '\x43\x1c\xbe\x99\x1a\x14\x22\x01\x00\x90\xf0' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
].join

# Send the request (opcode 0x22)
port.write(build_request(123456789012, 0x22, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DI Get Counts failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
current_state = be_uint(rsp_body, pos, 1)
pos += 1
lifetime_count = be_uint(rsp_body, pos, 8)
pos += 8
resettable_count = be_uint(rsp_body, pos, 8)
pos += 8
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
])

# Send the request (opcode 0x22)
port.write(build_request(123456789012, 0x22, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DI Get Counts failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
current_state = be_uint(rsp_body, pos, 1)
pos += 1
lifetime_count = be_uint(rsp_body, pos, 8)
pos += 8
resettable_count = be_uint(rsp_body, pos, 8)
pos += 8
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
]);

// Send the request (opcode 0x22)
dio_write($port, build_request(123456789012, 0x22, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DI Get Counts failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$current_state = be_uint($rsp_body, $pos, 1);
$pos += 1;
$lifetime_count = be_uint($rsp_body, $pos, 8);
$pos += 8;
$resettable_count = be_uint($rsp_body, $pos, 8);
$pos += 8;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
);

# Send the request (opcode 0x22)
$port->write(build_request(123456789012, 0x22, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DI Get Counts failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $current_state = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $lifetime_count = be_uint($rsp_body, $pos, 8);
$pos += 8;
my $resettable_count = be_uint($rsp_body, $pos, 8);
$pos += 8;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1)
);

// Send the request (opcode 0x22)
port.writeBytes(buildRequest(123456789012L, 0x22, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DI Get Counts failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var currentState = beUInt(rspBody, pos, 1);
pos += 1;
var lifetimeCount = beUInt(rspBody, pos, 8);
pos += 8;
var resettableCount = beUInt(rspBody, pos, 8);
pos += 8;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
  ]);

  // Send the request (opcode 0x22)
  port.write(buildRequest(123456789012, 0x22, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DI Get Counts failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const currentState = beUInt(rspBody, pos, 1);
  pos += 1;
  const lifetimeCount = beUInt(rspBody, pos, 8);
  pos += 8;
  const resettableCount = beUInt(rspBody, pos, 8);
  pos += 8;
})();

DI Get Counts

Returns the lifetime and resettable pulse counts for one digital input.

Opcode: 0x22. Body length: 1.

Request body

Field Bytes Description
Di_pin 1 Digital input index.

Response body

Field Bytes Description
Current_state 1 Current level, 0 or 1.
Lifetime_count 8 Lifetime pulse count.
Resettable_count 8 Pulse count since the last reset.

Example: DI Zero Reset Count

# DI Zero Reset Count to serial number 123456789012 (opcode 0x23)
printf '\x43\x1c\xbe\x99\x1a\x14\x23\x05\x00\x00\x00\x00\x00\x3c\x77' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 4),
  be(0, 1),
].join

# Send the request (opcode 0x23)
port.write(build_request(123456789012, 0x23, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DI Zero Reset Count failed: 0x%02X', rc) unless rc == 0x00
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 4),
    be(0, 1),
])

# Send the request (opcode 0x23)
port.write(build_request(123456789012, 0x23, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DI Zero Reset Count failed: {rc:#04x}')
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 4),
    be(0, 1),
]);

// Send the request (opcode 0x23)
dio_write($port, build_request(123456789012, 0x23, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DI Zero Reset Count failed: 0x%02X', $rc));
}
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 4),
  be(0, 1),
);

# Send the request (opcode 0x23)
$port->write(build_request(123456789012, 0x23, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DI Zero Reset Count failed: 0x%02X\n", $rc) unless $rc == 0x00;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 4),
    be(0, 1)
);

// Send the request (opcode 0x23)
port.writeBytes(buildRequest(123456789012L, 0x23, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DI Zero Reset Count failed: 0x%02X", rc));
}
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 4),
    be(0, 1),
  ]);

  // Send the request (opcode 0x23)
  port.write(buildRequest(123456789012, 0x23, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DI Zero Reset Count failed: 0x' + rc.toString(16));
})();

DI Zero Reset Count

Sets the resettable pulse count for one digital input to zero.

Opcode: 0x23. Body length: 5.

Request body

Field Bytes Description
Password 4 Password, 4 bytes. Always use the factory password 00000000.
Di_pin 1 Digital input index.

Response body: status only.

Example: DI Set Count Watch

# DI Set Count Watch to serial number 123456789012 (opcode 0x24)
printf '\x43\x1c\xbe\x99\x1a\x14\x24\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x64\x00\x00\x00\x02\x00\x00\x00\x05\x00\x00\x00\x05\x00\x03\x00\x00\x01\x4f\x37' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 4),
  be(0, 1),
  be(100, 8),
  be(0, 2),
  be(0, 1),
  be(2, 1),
  be(5, 4),
  be(5, 4),
  be(3, 2),
  be(0, 1),
  be(0, 1),
  be(1, 1),
].join

# Send the request (opcode 0x24)
port.write(build_request(123456789012, 0x24, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DI Set Count Watch failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
was_cleared = be_uint(rsp_body, pos, 1)
pos += 1
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 4),
    be(0, 1),
    be(100, 8),
    be(0, 2),
    be(0, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
])

# Send the request (opcode 0x24)
port.write(build_request(123456789012, 0x24, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DI Set Count Watch failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
was_cleared = be_uint(rsp_body, pos, 1)
pos += 1
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 4),
    be(0, 1),
    be(100, 8),
    be(0, 2),
    be(0, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
]);

// Send the request (opcode 0x24)
dio_write($port, build_request(123456789012, 0x24, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DI Set Count Watch failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$was_cleared = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 4),
  be(0, 1),
  be(100, 8),
  be(0, 2),
  be(0, 1),
  be(2, 1),
  be(5, 4),
  be(5, 4),
  be(3, 2),
  be(0, 1),
  be(0, 1),
  be(1, 1),
);

# Send the request (opcode 0x24)
$port->write(build_request(123456789012, 0x24, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DI Set Count Watch failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $was_cleared = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 4),
    be(0, 1),
    be(100, 8),
    be(0, 2),
    be(0, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1)
);

// Send the request (opcode 0x24)
port.writeBytes(buildRequest(123456789012L, 0x24, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DI Set Count Watch failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var wasCleared = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 4),
    be(0, 1),
    be(100, 8),
    be(0, 2),
    be(0, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
  ]);

  // Send the request (opcode 0x24)
  port.write(buildRequest(123456789012, 0x24, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DI Set Count Watch failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const wasCleared = beUInt(rspBody, pos, 1);
  pos += 1;
})();

DI Set Count Watch

Sets a count watch on a digital input. Each time Di_countIncrement pulses have been counted, the watch drives a digital output with a waveform. Set Di_countIncrement to 0 to clear the watch.

Opcode: 0x24. Body length: 30.

Request body

Field Bytes Description
Password 4 Password, 4 bytes. Always use the factory password 00000000.
Di_pin 1 Digital input index.
Di_countIncrement 8 Number of pulses that triggers the watch.
Reload 2 Number of times the watch reloads after it fires. 0 means it stops. 0xFFFF means it reloads forever.
Restart 1 1 restarts the watch after a chip reset. 0 does not.
Do_pin 1 Digital output to drive. 0xFF means no output.
Hi_sec 4 Seconds the output stays high in each cycle.
Low_sec 4 Seconds the output stays low in each cycle.
Wave_cycles 2 Number of cycles. 0 means repeat forever.
Initial_level 1 Output level before the first cycle.
Interim_level 1 Output level between cycles.
Final_level 1 Output level after the last cycle.

Response body

Field Bytes Description
WasCleared 1 1 if an existing watch was replaced, 0 if not.
  • If the status is RC_DO_BUSY_ERR (0x93), the body holds the owner ID of the waveform that is using the output instead.
  • Returns RC_CMD_DI_INCREMENT_ERR if the lifetime count plus Di_countIncrement is too large.

Example: DI Get Count Watch

# DI Get Count Watch to serial number 123456789012 (opcode 0x25)
printf '\x43\x1c\xbe\x99\x1a\x14\x25\x01\x00\x21\x31' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
].join

# Send the request (opcode 0x25)
port.write(build_request(123456789012, 0x25, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DI Get Count Watch failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
di_count_increment = be_uint(rsp_body, pos, 8)
pos += 8
reload = be_uint(rsp_body, pos, 2)
pos += 2
restart = be_uint(rsp_body, pos, 1)
pos += 1
do_pin = be_uint(rsp_body, pos, 1)
pos += 1
hi_sec = be_uint(rsp_body, pos, 4)
pos += 4
low_sec = be_uint(rsp_body, pos, 4)
pos += 4
wave_cycles = be_uint(rsp_body, pos, 2)
pos += 2
initial_level = be_uint(rsp_body, pos, 1)
pos += 1
interim_level = be_uint(rsp_body, pos, 1)
pos += 1
final_level = be_uint(rsp_body, pos, 1)
pos += 1
di_curr_level = be_uint(rsp_body, pos, 1)
pos += 1
hit_count = be_uint(rsp_body, pos, 2)
pos += 2
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
])

# Send the request (opcode 0x25)
port.write(build_request(123456789012, 0x25, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DI Get Count Watch failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
di_count_increment = be_uint(rsp_body, pos, 8)
pos += 8
reload = be_uint(rsp_body, pos, 2)
pos += 2
restart = be_uint(rsp_body, pos, 1)
pos += 1
do_pin = be_uint(rsp_body, pos, 1)
pos += 1
hi_sec = be_uint(rsp_body, pos, 4)
pos += 4
low_sec = be_uint(rsp_body, pos, 4)
pos += 4
wave_cycles = be_uint(rsp_body, pos, 2)
pos += 2
initial_level = be_uint(rsp_body, pos, 1)
pos += 1
interim_level = be_uint(rsp_body, pos, 1)
pos += 1
final_level = be_uint(rsp_body, pos, 1)
pos += 1
di_curr_level = be_uint(rsp_body, pos, 1)
pos += 1
hit_count = be_uint(rsp_body, pos, 2)
pos += 2
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
]);

// Send the request (opcode 0x25)
dio_write($port, build_request(123456789012, 0x25, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DI Get Count Watch failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$di_count_increment = be_uint($rsp_body, $pos, 8);
$pos += 8;
$reload = be_uint($rsp_body, $pos, 2);
$pos += 2;
$restart = be_uint($rsp_body, $pos, 1);
$pos += 1;
$do_pin = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hi_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
$low_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
$wave_cycles = be_uint($rsp_body, $pos, 2);
$pos += 2;
$initial_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$interim_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$final_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_curr_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hit_count = be_uint($rsp_body, $pos, 2);
$pos += 2;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
);

# Send the request (opcode 0x25)
$port->write(build_request(123456789012, 0x25, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DI Get Count Watch failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $di_count_increment = be_uint($rsp_body, $pos, 8);
$pos += 8;
my $reload = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $restart = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $do_pin = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hi_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $low_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $wave_cycles = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $initial_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $interim_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $final_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $di_curr_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hit_count = be_uint($rsp_body, $pos, 2);
$pos += 2;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1)
);

// Send the request (opcode 0x25)
port.writeBytes(buildRequest(123456789012L, 0x25, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DI Get Count Watch failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var diCountIncrement = beUInt(rspBody, pos, 8);
pos += 8;
var reload = beUInt(rspBody, pos, 2);
pos += 2;
var restart = beUInt(rspBody, pos, 1);
pos += 1;
var doPin = beUInt(rspBody, pos, 1);
pos += 1;
var hiSec = beUInt(rspBody, pos, 4);
pos += 4;
var lowSec = beUInt(rspBody, pos, 4);
pos += 4;
var waveCycles = beUInt(rspBody, pos, 2);
pos += 2;
var initialLevel = beUInt(rspBody, pos, 1);
pos += 1;
var interimLevel = beUInt(rspBody, pos, 1);
pos += 1;
var finalLevel = beUInt(rspBody, pos, 1);
pos += 1;
var diCurrLevel = beUInt(rspBody, pos, 1);
pos += 1;
var hitCount = beUInt(rspBody, pos, 2);
pos += 2;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
  ]);

  // Send the request (opcode 0x25)
  port.write(buildRequest(123456789012, 0x25, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DI Get Count Watch failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const diCountIncrement = beUInt(rspBody, pos, 8);
  pos += 8;
  const reload = beUInt(rspBody, pos, 2);
  pos += 2;
  const restart = beUInt(rspBody, pos, 1);
  pos += 1;
  const doPin = beUInt(rspBody, pos, 1);
  pos += 1;
  const hiSec = beUInt(rspBody, pos, 4);
  pos += 4;
  const lowSec = beUInt(rspBody, pos, 4);
  pos += 4;
  const waveCycles = beUInt(rspBody, pos, 2);
  pos += 2;
  const initialLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const interimLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const finalLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const diCurrLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const hitCount = beUInt(rspBody, pos, 2);
  pos += 2;
})();

DI Get Count Watch

Returns the count watch settings and state for one digital input.

Opcode: 0x25. Body length: 1.

Request body

Field Bytes Description
Di_pin 1 Digital input index.

Response body

Field Bytes Description
Di_countIncrement 8 Pulse count that triggers the watch.
Reload 2 Pulses to count after each trigger.
Restart 1 Restart flag.
Do_pin 1 Digital output driven by the watch.
Hi_sec 4 High seconds per cycle.
Low_sec 4 Low seconds per cycle.
Wave_cycles 2 Number of cycles.
Initial_level 1 Initial output level.
Interim_level 1 Interim output level.
Final_level 1 Final output level.
Di_currLevel 1 Current level of the input.
HitCount 2 Number of times the watch has fired.
  • Returns RC_NO_WATCH_FOUND_ERR if no watch is set on that input.

Example: DI Set Level Watch

# DI Set Level Watch to serial number 123456789012 (opcode 0x26)
printf '\x43\x1c\xbe\x99\x1a\x14\x26\x19\x00\x00\x00\x00\x00\x01\x00\x0a\x00\x05\x01\x02\x00\x00\x00\x05\x00\x00\x00\x05\x00\x03\x00\x00\x01\xcf\x6b' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 4),
  be(0, 1),
  be(1, 1),
  be(10, 2),
  be(5, 2),
  be(1, 1),
  be(2, 1),
  be(5, 4),
  be(5, 4),
  be(3, 2),
  be(0, 1),
  be(0, 1),
  be(1, 1),
].join

# Send the request (opcode 0x26)
port.write(build_request(123456789012, 0x26, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DI Set Level Watch failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
was_cleared = be_uint(rsp_body, pos, 1)
pos += 1
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 4),
    be(0, 1),
    be(1, 1),
    be(10, 2),
    be(5, 2),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
])

# Send the request (opcode 0x26)
port.write(build_request(123456789012, 0x26, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DI Set Level Watch failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
was_cleared = be_uint(rsp_body, pos, 1)
pos += 1
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 4),
    be(0, 1),
    be(1, 1),
    be(10, 2),
    be(5, 2),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
]);

// Send the request (opcode 0x26)
dio_write($port, build_request(123456789012, 0x26, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DI Set Level Watch failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$was_cleared = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 4),
  be(0, 1),
  be(1, 1),
  be(10, 2),
  be(5, 2),
  be(1, 1),
  be(2, 1),
  be(5, 4),
  be(5, 4),
  be(3, 2),
  be(0, 1),
  be(0, 1),
  be(1, 1),
);

# Send the request (opcode 0x26)
$port->write(build_request(123456789012, 0x26, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DI Set Level Watch failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $was_cleared = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 4),
    be(0, 1),
    be(1, 1),
    be(10, 2),
    be(5, 2),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1)
);

// Send the request (opcode 0x26)
port.writeBytes(buildRequest(123456789012L, 0x26, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DI Set Level Watch failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var wasCleared = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 4),
    be(0, 1),
    be(1, 1),
    be(10, 2),
    be(5, 2),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
  ]);

  // Send the request (opcode 0x26)
  port.write(buildRequest(123456789012, 0x26, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DI Set Level Watch failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const wasCleared = beUInt(rspBody, pos, 1);
  pos += 1;
})();

DI Set Level Watch

Sets a level watch on a digital input. When the input stays at Di_level for the minimum time, the watch drives a digital output with a waveform. Set both MinTrueSec and MinFalseSec to 0 to clear the watch.

Opcode: 0x26. Body length: 25.

Request body

Field Bytes Description
Password 4 Password, 4 bytes. Always use the factory password 00000000.
Di_pin 1 Digital input index.
Di_level 1 Level to watch for, 0 or 1.
MinTrueSec 2 Seconds the level must hold before the watch fires.
MinFalseSec 2 Seconds the level must not hold before the watch clears.
Restart 1 0 clears the watch after it triggers. 1 restarts it after it triggers. 2 restarts it after it triggers and after a chip reset.
Do_pin 1 Digital output to drive. 0xFF means no output.
Hi_sec 4 Seconds the output stays high in each cycle.
Low_sec 4 Seconds the output stays low in each cycle.
Wave_cycles 2 Number of cycles. 0 means repeat forever.
Initial_level 1 Output level before the first cycle.
Interim_level 1 Output level between cycles.
Final_level 1 Output level after the last cycle.

Response body

Field Bytes Description
WasCleared 1 1 if an existing watch was replaced, 0 if not.
  • If the status is RC_DO_BUSY_ERR (0x93), the body holds the owner ID of the waveform that is using the output instead.

Example: DI Get Level Watch

# DI Get Level Watch to serial number 123456789012 (opcode 0x27)
printf '\x43\x1c\xbe\x99\x1a\x14\x27\x01\x00\x80\xf1' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
].join

# Send the request (opcode 0x27)
port.write(build_request(123456789012, 0x27, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DI Get Level Watch failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
di_current_level = be_uint(rsp_body, pos, 1)
pos += 1
di_level = be_uint(rsp_body, pos, 1)
pos += 1
min_true_sec = be_uint(rsp_body, pos, 2)
pos += 2
min_false_sec = be_uint(rsp_body, pos, 2)
pos += 2
restart = be_uint(rsp_body, pos, 1)
pos += 1
do_pin = be_uint(rsp_body, pos, 1)
pos += 1
hi_sec = be_uint(rsp_body, pos, 4)
pos += 4
low_sec = be_uint(rsp_body, pos, 4)
pos += 4
wave_cycles = be_uint(rsp_body, pos, 2)
pos += 2
initial_level = be_uint(rsp_body, pos, 1)
pos += 1
interim_level = be_uint(rsp_body, pos, 1)
pos += 1
final_level = be_uint(rsp_body, pos, 1)
pos += 1
hit_count = be_uint(rsp_body, pos, 2)
pos += 2
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
])

# Send the request (opcode 0x27)
port.write(build_request(123456789012, 0x27, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DI Get Level Watch failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
di_current_level = be_uint(rsp_body, pos, 1)
pos += 1
di_level = be_uint(rsp_body, pos, 1)
pos += 1
min_true_sec = be_uint(rsp_body, pos, 2)
pos += 2
min_false_sec = be_uint(rsp_body, pos, 2)
pos += 2
restart = be_uint(rsp_body, pos, 1)
pos += 1
do_pin = be_uint(rsp_body, pos, 1)
pos += 1
hi_sec = be_uint(rsp_body, pos, 4)
pos += 4
low_sec = be_uint(rsp_body, pos, 4)
pos += 4
wave_cycles = be_uint(rsp_body, pos, 2)
pos += 2
initial_level = be_uint(rsp_body, pos, 1)
pos += 1
interim_level = be_uint(rsp_body, pos, 1)
pos += 1
final_level = be_uint(rsp_body, pos, 1)
pos += 1
hit_count = be_uint(rsp_body, pos, 2)
pos += 2
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
]);

// Send the request (opcode 0x27)
dio_write($port, build_request(123456789012, 0x27, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DI Get Level Watch failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$di_current_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$di_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$min_true_sec = be_uint($rsp_body, $pos, 2);
$pos += 2;
$min_false_sec = be_uint($rsp_body, $pos, 2);
$pos += 2;
$restart = be_uint($rsp_body, $pos, 1);
$pos += 1;
$do_pin = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hi_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
$low_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
$wave_cycles = be_uint($rsp_body, $pos, 2);
$pos += 2;
$initial_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$interim_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$final_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hit_count = be_uint($rsp_body, $pos, 2);
$pos += 2;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
);

# Send the request (opcode 0x27)
$port->write(build_request(123456789012, 0x27, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DI Get Level Watch failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $di_current_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $di_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $min_true_sec = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $min_false_sec = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $restart = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $do_pin = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hi_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $low_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $wave_cycles = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $initial_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $interim_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $final_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hit_count = be_uint($rsp_body, $pos, 2);
$pos += 2;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1)
);

// Send the request (opcode 0x27)
port.writeBytes(buildRequest(123456789012L, 0x27, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DI Get Level Watch failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var diCurrentLevel = beUInt(rspBody, pos, 1);
pos += 1;
var diLevel = beUInt(rspBody, pos, 1);
pos += 1;
var minTrueSec = beUInt(rspBody, pos, 2);
pos += 2;
var minFalseSec = beUInt(rspBody, pos, 2);
pos += 2;
var restart = beUInt(rspBody, pos, 1);
pos += 1;
var doPin = beUInt(rspBody, pos, 1);
pos += 1;
var hiSec = beUInt(rspBody, pos, 4);
pos += 4;
var lowSec = beUInt(rspBody, pos, 4);
pos += 4;
var waveCycles = beUInt(rspBody, pos, 2);
pos += 2;
var initialLevel = beUInt(rspBody, pos, 1);
pos += 1;
var interimLevel = beUInt(rspBody, pos, 1);
pos += 1;
var finalLevel = beUInt(rspBody, pos, 1);
pos += 1;
var hitCount = beUInt(rspBody, pos, 2);
pos += 2;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
  ]);

  // Send the request (opcode 0x27)
  port.write(buildRequest(123456789012, 0x27, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DI Get Level Watch failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const diCurrentLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const diLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const minTrueSec = beUInt(rspBody, pos, 2);
  pos += 2;
  const minFalseSec = beUInt(rspBody, pos, 2);
  pos += 2;
  const restart = beUInt(rspBody, pos, 1);
  pos += 1;
  const doPin = beUInt(rspBody, pos, 1);
  pos += 1;
  const hiSec = beUInt(rspBody, pos, 4);
  pos += 4;
  const lowSec = beUInt(rspBody, pos, 4);
  pos += 4;
  const waveCycles = beUInt(rspBody, pos, 2);
  pos += 2;
  const initialLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const interimLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const finalLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const hitCount = beUInt(rspBody, pos, 2);
  pos += 2;
})();

DI Get Level Watch

Returns the level watch settings and state for one digital input.

Opcode: 0x27. Body length: 1.

Request body

Field Bytes Description
Di_pin 1 Digital input index.

Response body

Field Bytes Description
Di_currentLevel 1 Current level of the input.
Di_level 1 Level being watched.
MinTrueSec 2 Seconds the level must hold.
MinFalseSec 2 Seconds the level must not hold.
Restart 1 Restart flag.
Do_pin 1 Digital output driven by the watch.
Hi_sec 4 High seconds per cycle.
Low_sec 4 Low seconds per cycle.
Wave_cycles 2 Number of cycles.
Initial_level 1 Initial output level.
Interim_level 1 Interim output level.
Final_level 1 Final output level.
HitCount 2 Number of times the watch has fired.
  • Returns RC_NO_WATCH_FOUND_ERR if no watch is set on that input.

Example: DI Set Rate Watch

# DI Set Rate Watch to serial number 123456789012 (opcode 0x28)
printf '\x43\x1c\xbe\x99\x1a\x14\x28\x1d\x00\x00\x00\x00\x00\x00\x00\x03\xe8\x00\x00\x00\x64\x05\x01\x02\x00\x00\x00\x05\x00\x00\x00\x05\x00\x03\x00\x00\x01\x51\x88' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 4),
  be(0, 1),
  be(1000, 4),
  be(100, 4),
  be(5, 1),
  be(1, 1),
  be(2, 1),
  be(5, 4),
  be(5, 4),
  be(3, 2),
  be(0, 1),
  be(0, 1),
  be(1, 1),
].join

# Send the request (opcode 0x28)
port.write(build_request(123456789012, 0x28, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DI Set Rate Watch failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
was_cleared = be_uint(rsp_body, pos, 1)
pos += 1
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 4),
    be(0, 1),
    be(1000, 4),
    be(100, 4),
    be(5, 1),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
])

# Send the request (opcode 0x28)
port.write(build_request(123456789012, 0x28, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DI Set Rate Watch failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
was_cleared = be_uint(rsp_body, pos, 1)
pos += 1
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 4),
    be(0, 1),
    be(1000, 4),
    be(100, 4),
    be(5, 1),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
]);

// Send the request (opcode 0x28)
dio_write($port, build_request(123456789012, 0x28, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DI Set Rate Watch failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$was_cleared = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 4),
  be(0, 1),
  be(1000, 4),
  be(100, 4),
  be(5, 1),
  be(1, 1),
  be(2, 1),
  be(5, 4),
  be(5, 4),
  be(3, 2),
  be(0, 1),
  be(0, 1),
  be(1, 1),
);

# Send the request (opcode 0x28)
$port->write(build_request(123456789012, 0x28, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DI Set Rate Watch failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $was_cleared = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 4),
    be(0, 1),
    be(1000, 4),
    be(100, 4),
    be(5, 1),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1)
);

// Send the request (opcode 0x28)
port.writeBytes(buildRequest(123456789012L, 0x28, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DI Set Rate Watch failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var wasCleared = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 4),
    be(0, 1),
    be(1000, 4),
    be(100, 4),
    be(5, 1),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
  ]);

  // Send the request (opcode 0x28)
  port.write(buildRequest(123456789012, 0x28, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DI Set Rate Watch failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const wasCleared = beUInt(rspBody, pos, 1);
  pos += 1;
})();

DI Set Rate Watch

Sets a rate watch on a digital input. The time between rising edges is checked against Min_ms and Max_ms. Each edge that is further apart than Max_ms, or closer than Min_ms, adds to a count. Once per second, if the count is above AllowedHits, the watch registers a hit and drives a digital output with a waveform. Set both Max_ms and Min_ms to 0 to clear the watch.

Opcode: 0x28. Body length: 29.

Request body

Field Bytes Description
Password 4 Password, 4 bytes. Always use the factory password 00000000.
Di_pin 1 Digital input index.
Max_ms 4 Longest time allowed between rising edges, in ms. Must be at least 9 and greater than Min_ms + 1.
Min_ms 4 Shortest time allowed between rising edges, in ms. Must be 7 or more.
AllowedHits 1 Number of out-of-range edges per second that counts as a hit. 254 or less.
Restart 1 0 clears the watch after it triggers. 1 restarts it after it triggers. 2 restarts it after it triggers and after a chip reset.
Do_pin 1 Digital output to drive. 0xFF means no output.
Hi_sec 4 Seconds the output stays high in each cycle.
Low_sec 4 Seconds the output stays low in each cycle.
Wave_cycles 2 Number of cycles. 0 means repeat forever.
Initial_level 1 Output level before the first cycle.
Interim_level 1 Output level between cycles.
Final_level 1 Output level after the last cycle.

Response body

Field Bytes Description
WasCleared 1 1 if an existing watch was replaced, 0 if not.
  • If the status is RC_DO_BUSY_ERR (0x93), the body holds the owner ID of the waveform that is using the output instead.

Example: DI Get Rate Watch

# DI Get Rate Watch to serial number 123456789012 (opcode 0x29)
printf '\x43\x1c\xbe\x99\x1a\x14\x29\x01\x00\xe1\x32' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
].join

# Send the request (opcode 0x29)
port.write(build_request(123456789012, 0x29, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DI Get Rate Watch failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
max_ms = be_uint(rsp_body, pos, 4)
pos += 4
min_ms = be_uint(rsp_body, pos, 4)
pos += 4
allowed_hits = be_uint(rsp_body, pos, 1)
pos += 1
restart = be_uint(rsp_body, pos, 1)
pos += 1
do_pin = be_uint(rsp_body, pos, 1)
pos += 1
hi_sec = be_uint(rsp_body, pos, 4)
pos += 4
low_sec = be_uint(rsp_body, pos, 4)
pos += 4
wave_cycles = be_uint(rsp_body, pos, 2)
pos += 2
initial_level = be_uint(rsp_body, pos, 1)
pos += 1
interim_level = be_uint(rsp_body, pos, 1)
pos += 1
final_level = be_uint(rsp_body, pos, 1)
pos += 1
current_max_hits = be_uint(rsp_body, pos, 1)
pos += 1
current_min_hits = be_uint(rsp_body, pos, 1)
pos += 1
hit_count = be_uint(rsp_body, pos, 2)
pos += 2
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
])

# Send the request (opcode 0x29)
port.write(build_request(123456789012, 0x29, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DI Get Rate Watch failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
max_ms = be_uint(rsp_body, pos, 4)
pos += 4
min_ms = be_uint(rsp_body, pos, 4)
pos += 4
allowed_hits = be_uint(rsp_body, pos, 1)
pos += 1
restart = be_uint(rsp_body, pos, 1)
pos += 1
do_pin = be_uint(rsp_body, pos, 1)
pos += 1
hi_sec = be_uint(rsp_body, pos, 4)
pos += 4
low_sec = be_uint(rsp_body, pos, 4)
pos += 4
wave_cycles = be_uint(rsp_body, pos, 2)
pos += 2
initial_level = be_uint(rsp_body, pos, 1)
pos += 1
interim_level = be_uint(rsp_body, pos, 1)
pos += 1
final_level = be_uint(rsp_body, pos, 1)
pos += 1
current_max_hits = be_uint(rsp_body, pos, 1)
pos += 1
current_min_hits = be_uint(rsp_body, pos, 1)
pos += 1
hit_count = be_uint(rsp_body, pos, 2)
pos += 2
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
]);

// Send the request (opcode 0x29)
dio_write($port, build_request(123456789012, 0x29, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DI Get Rate Watch failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$max_ms = be_uint($rsp_body, $pos, 4);
$pos += 4;
$min_ms = be_uint($rsp_body, $pos, 4);
$pos += 4;
$allowed_hits = be_uint($rsp_body, $pos, 1);
$pos += 1;
$restart = be_uint($rsp_body, $pos, 1);
$pos += 1;
$do_pin = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hi_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
$low_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
$wave_cycles = be_uint($rsp_body, $pos, 2);
$pos += 2;
$initial_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$interim_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$final_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$current_max_hits = be_uint($rsp_body, $pos, 1);
$pos += 1;
$current_min_hits = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hit_count = be_uint($rsp_body, $pos, 2);
$pos += 2;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
);

# Send the request (opcode 0x29)
$port->write(build_request(123456789012, 0x29, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DI Get Rate Watch failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $max_ms = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $min_ms = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $allowed_hits = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $restart = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $do_pin = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hi_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $low_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $wave_cycles = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $initial_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $interim_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $final_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $current_max_hits = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $current_min_hits = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hit_count = be_uint($rsp_body, $pos, 2);
$pos += 2;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1)
);

// Send the request (opcode 0x29)
port.writeBytes(buildRequest(123456789012L, 0x29, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DI Get Rate Watch failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var maxMs = beUInt(rspBody, pos, 4);
pos += 4;
var minMs = beUInt(rspBody, pos, 4);
pos += 4;
var allowedHits = beUInt(rspBody, pos, 1);
pos += 1;
var restart = beUInt(rspBody, pos, 1);
pos += 1;
var doPin = beUInt(rspBody, pos, 1);
pos += 1;
var hiSec = beUInt(rspBody, pos, 4);
pos += 4;
var lowSec = beUInt(rspBody, pos, 4);
pos += 4;
var waveCycles = beUInt(rspBody, pos, 2);
pos += 2;
var initialLevel = beUInt(rspBody, pos, 1);
pos += 1;
var interimLevel = beUInt(rspBody, pos, 1);
pos += 1;
var finalLevel = beUInt(rspBody, pos, 1);
pos += 1;
var currentMaxHits = beUInt(rspBody, pos, 1);
pos += 1;
var currentMinHits = beUInt(rspBody, pos, 1);
pos += 1;
var hitCount = beUInt(rspBody, pos, 2);
pos += 2;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
  ]);

  // Send the request (opcode 0x29)
  port.write(buildRequest(123456789012, 0x29, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DI Get Rate Watch failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const maxMs = beUInt(rspBody, pos, 4);
  pos += 4;
  const minMs = beUInt(rspBody, pos, 4);
  pos += 4;
  const allowedHits = beUInt(rspBody, pos, 1);
  pos += 1;
  const restart = beUInt(rspBody, pos, 1);
  pos += 1;
  const doPin = beUInt(rspBody, pos, 1);
  pos += 1;
  const hiSec = beUInt(rspBody, pos, 4);
  pos += 4;
  const lowSec = beUInt(rspBody, pos, 4);
  pos += 4;
  const waveCycles = beUInt(rspBody, pos, 2);
  pos += 2;
  const initialLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const interimLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const finalLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const currentMaxHits = beUInt(rspBody, pos, 1);
  pos += 1;
  const currentMinHits = beUInt(rspBody, pos, 1);
  pos += 1;
  const hitCount = beUInt(rspBody, pos, 2);
  pos += 2;
})();

DI Get Rate Watch

Returns the rate watch settings and state for one digital input.

Opcode: 0x29. Body length: 1.

Request body

Field Bytes Description
Di_pin 1 Digital input index.

Response body

Field Bytes Description
Max_ms 4 Longest time allowed between rising edges, in ms.
Min_ms 4 Shortest time allowed between rising edges, in ms.
AllowedHits 1 Out-of-range edges per second needed to register a hit.
Restart 1 Restart flag.
Do_pin 1 Digital output driven by the watch.
Hi_sec 4 High seconds per cycle.
Low_sec 4 Low seconds per cycle.
Wave_cycles 2 Number of cycles.
Initial_level 1 Initial output level.
Interim_level 1 Interim output level.
Final_level 1 Final output level.
CurrentMaxHits 1 Current count of pulses that were too long (above Max_ms), toward AllowedHits.
CurrentMinHits 1 Current count of pulses that were too short (below Min_ms), toward AllowedHits.
HitCount 2 Number of times the watch has fired.
  • Returns RC_NO_WATCH_FOUND_ERR if no watch is set on that input.

Digital Output Requests

Example: DO Set Level

# DO Set Level to serial number 123456789012 (opcode 0x30)
printf '\x43\x1c\xbe\x99\x1a\x14\x30\x07\x00\x00\x00\x00\x00\x01\x00\x08\x5f' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 4),
  be(0, 1),
  be(1, 1),
  be(0, 1),
].join

# Send the request (opcode 0x30)
port.write(build_request(123456789012, 0x30, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DO Set Level failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
cleared_id = be_uint(rsp_body, pos, 1)
pos += 1
curr_levels_map = be_uint(rsp_body, pos, 1)
pos += 1
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 4),
    be(0, 1),
    be(1, 1),
    be(0, 1),
])

# Send the request (opcode 0x30)
port.write(build_request(123456789012, 0x30, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DO Set Level failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
cleared_id = be_uint(rsp_body, pos, 1)
pos += 1
curr_levels_map = be_uint(rsp_body, pos, 1)
pos += 1
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 4),
    be(0, 1),
    be(1, 1),
    be(0, 1),
]);

// Send the request (opcode 0x30)
dio_write($port, build_request(123456789012, 0x30, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DO Set Level failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$cleared_id = be_uint($rsp_body, $pos, 1);
$pos += 1;
$curr_levels_map = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 4),
  be(0, 1),
  be(1, 1),
  be(0, 1),
);

# Send the request (opcode 0x30)
$port->write(build_request(123456789012, 0x30, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DO Set Level failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $cleared_id = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $curr_levels_map = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 4),
    be(0, 1),
    be(1, 1),
    be(0, 1)
);

// Send the request (opcode 0x30)
port.writeBytes(buildRequest(123456789012L, 0x30, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DO Set Level failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var clearedId = beUInt(rspBody, pos, 1);
pos += 1;
var currLevelsMap = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 4),
    be(0, 1),
    be(1, 1),
    be(0, 1),
  ]);

  // Send the request (opcode 0x30)
  port.write(buildRequest(123456789012, 0x30, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DO Set Level failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const clearedId = beUInt(rspBody, pos, 1);
  pos += 1;
  const currLevelsMap = beUInt(rspBody, pos, 1);
  pos += 1;
})();

DO Set Level

Sets one digital output to a level. If the output is running a waveform, it is stopped when ClearWatch is 1.

Opcode: 0x30. Body length: 7.

Request body

Field Bytes Description
Password 4 Password, 4 bytes. Always use the factory password 00000000.
Do_pin 1 Digital output index.
Level 1 Level to set, 0 or 1.
ClearWatch 1 1 to stop any waveform on the output, 0 to leave it running.

Response body

Field Bytes Description
ClearedId 1 Owner ID of the waveform that was stopped, 0 if none.
CurrLevelsMap 1 Bitmap of output levels after the change.
  • If the status is RC_DO_BUSY_ERR (0x93), the body holds the owner ID of the waveform that is using the output instead.

Example: DO Get Level

# DO Get Level to serial number 123456789012 (opcode 0x31)
printf '\x43\x1c\xbe\x99\x1a\x14\x31\x01\x00\x61\x35' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
].join

# Send the request (opcode 0x31)
port.write(build_request(123456789012, 0x31, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DO Get Level failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
curr_level = be_uint(rsp_body, pos, 1)
pos += 1
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
])

# Send the request (opcode 0x31)
port.write(build_request(123456789012, 0x31, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DO Get Level failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
curr_level = be_uint(rsp_body, pos, 1)
pos += 1
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
]);

// Send the request (opcode 0x31)
dio_write($port, build_request(123456789012, 0x31, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DO Get Level failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$curr_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
);

# Send the request (opcode 0x31)
$port->write(build_request(123456789012, 0x31, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DO Get Level failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $curr_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1)
);

// Send the request (opcode 0x31)
port.writeBytes(buildRequest(123456789012L, 0x31, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DO Get Level failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var currLevel = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
  ]);

  // Send the request (opcode 0x31)
  port.write(buildRequest(123456789012, 0x31, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DO Get Level failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const currLevel = beUInt(rspBody, pos, 1);
  pos += 1;
})();

DO Get Level

Returns the level of one digital output.

Opcode: 0x31. Body length: 1.

Request body

Field Bytes Description
Do_pin 1 Digital output index.

Response body

Field Bytes Description
CurrLevel 1 Current level, 0 or 1.

Example: DO Set Levels

# DO Set Levels to serial number 123456789012 (opcode 0x32)
printf '\x43\x1c\xbe\x99\x1a\x14\x32\x06\x00\x00\x00\x00\x06\x04\x86\xb2' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 4),
  be(6, 1),
  be(4, 1),
].join

# Send the request (opcode 0x32)
port.write(build_request(123456789012, 0x32, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DO Set Levels failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
curr_levels_map = be_uint(rsp_body, pos, 1)
pos += 1
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 4),
    be(6, 1),
    be(4, 1),
])

# Send the request (opcode 0x32)
port.write(build_request(123456789012, 0x32, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DO Set Levels failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
curr_levels_map = be_uint(rsp_body, pos, 1)
pos += 1
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 4),
    be(6, 1),
    be(4, 1),
]);

// Send the request (opcode 0x32)
dio_write($port, build_request(123456789012, 0x32, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DO Set Levels failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$curr_levels_map = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 4),
  be(6, 1),
  be(4, 1),
);

# Send the request (opcode 0x32)
$port->write(build_request(123456789012, 0x32, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DO Set Levels failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $curr_levels_map = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 4),
    be(6, 1),
    be(4, 1)
);

// Send the request (opcode 0x32)
port.writeBytes(buildRequest(123456789012L, 0x32, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DO Set Levels failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var currLevelsMap = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 4),
    be(6, 1),
    be(4, 1),
  ]);

  // Send the request (opcode 0x32)
  port.write(buildRequest(123456789012, 0x32, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DO Set Levels failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const currLevelsMap = beUInt(rspBody, pos, 1);
  pos += 1;
})();

DO Set Levels

Sets several digital outputs at once. SelectMap chooses which outputs to change, and LevelMap gives the new level for each. Bit 0 is DO 0.

Opcode: 0x32. Body length: 6.

Request body

Field Bytes Description
Password 4 Password, 4 bytes. Always use the factory password 00000000.
SelectMap 1 Bitmap of outputs to change. Bit 0 is DO 0.
LevelMap 1 Bitmap of new levels. Bit 0 is DO 0.

Response body

Field Bytes Description
CurrLevelsMap 1 Bitmap of output levels after the change.
  • If a selected output is busy, the status is RC_DO_BUSY_ERR. The body then holds CurrLevelsMap[1] followed by a 2-byte BusyInfo entry for each busy output.

Example: DO Get Levels

# DO Get Levels to serial number 123456789012 (opcode 0x33)
printf '\x43\x1c\xbe\x99\x1a\x14\x33\x00\x8d\x01' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x33, no body)
port.write(build_request(123456789012, 0x33))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DO Get Levels failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
curr_levels_map = be_uint(rsp_body, pos, 1)
pos += 1
# Send the request (opcode 0x33, no body)
port.write(build_request(123456789012, 0x33))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DO Get Levels failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
curr_levels_map = be_uint(rsp_body, pos, 1)
pos += 1
// Send the request (opcode 0x33, no body)
dio_write($port, build_request(123456789012, 0x33));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DO Get Levels failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$curr_levels_map = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Send the request (opcode 0x33, no body)
$port->write(build_request(123456789012, 0x33));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DO Get Levels failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $curr_levels_map = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Send the request (opcode 0x33, no body)
port.writeBytes(buildRequest(123456789012L, 0x33));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DO Get Levels failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var currLevelsMap = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Send the request (opcode 0x33, no body)
  port.write(buildRequest(123456789012, 0x33));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DO Get Levels failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const currLevelsMap = beUInt(rspBody, pos, 1);
  pos += 1;
})();

DO Get Levels

Returns the levels of all digital outputs as a bitmap. Bit 0 is DO 0.

Opcode: 0x33. Body length: 0.

Request body: none.

Response body

Field Bytes Description
CurrLevelsMap 1 Bitmap of output levels.

Example: DO Set Waveform

# DO Set Waveform to serial number 123456789012 (opcode 0x34)
printf '\x43\x1c\xbe\x99\x1a\x14\x34\x10\x00\x00\x00\x00\x02\x00\x00\x00\x05\x00\x00\x00\x05\x00\x03\x01\x20\x81' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 4),
  be(2, 1),
  be(5, 4),
  be(5, 4),
  be(3, 2),
  be(1, 1),
].join

# Send the request (opcode 0x34)
port.write(build_request(123456789012, 0x34, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DO Set Waveform failed: 0x%02X', rc) unless rc == 0x00
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 4),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(1, 1),
])

# Send the request (opcode 0x34)
port.write(build_request(123456789012, 0x34, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DO Set Waveform failed: {rc:#04x}')
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 4),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(1, 1),
]);

// Send the request (opcode 0x34)
dio_write($port, build_request(123456789012, 0x34, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DO Set Waveform failed: 0x%02X', $rc));
}
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 4),
  be(2, 1),
  be(5, 4),
  be(5, 4),
  be(3, 2),
  be(1, 1),
);

# Send the request (opcode 0x34)
$port->write(build_request(123456789012, 0x34, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DO Set Waveform failed: 0x%02X\n", $rc) unless $rc == 0x00;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 4),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(1, 1)
);

// Send the request (opcode 0x34)
port.writeBytes(buildRequest(123456789012L, 0x34, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DO Set Waveform failed: 0x%02X", rc));
}
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 4),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(1, 1),
  ]);

  // Send the request (opcode 0x34)
  port.write(buildRequest(123456789012, 0x34, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DO Set Waveform failed: 0x' + rc.toString(16));
})();

DO Set Waveform

Starts a waveform on a digital output. The output alternates between high and low for the given times and cycle count, then ends at Final_level.

Opcode: 0x34. Body length: 16.

Request body

Field Bytes Description
Password 4 Password, 4 bytes. Always use the factory password 00000000.
Do_pin 1 Digital output index.
Hi_sec 4 Seconds the output stays high in each cycle.
Low_sec 4 Seconds the output stays low in each cycle.
Wave_cycles 2 Number of cycles. 0 means repeat forever.
Final_level 1 Output level after the last cycle.

Response body: status only.

  • If the status is RC_DO_BUSY_ERR (0x93), the body holds the owner ID of the waveform that is using the output instead.

Example: DO Get Waveform

# DO Get Waveform to serial number 123456789012 (opcode 0x35)
printf '\x43\x1c\xbe\x99\x1a\x14\x35\x01\x02\xa1\x35' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(2, 1),
].join

# Send the request (opcode 0x35)
port.write(build_request(123456789012, 0x35, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('DO Get Waveform failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
owner_id = be_uint(rsp_body, pos, 1)
pos += 1
hi_sec = be_uint(rsp_body, pos, 4)
pos += 4
low_sec = be_uint(rsp_body, pos, 4)
pos += 4
wave_cycles = be_uint(rsp_body, pos, 2)
pos += 2
final_level = be_uint(rsp_body, pos, 1)
pos += 1
active = be_uint(rsp_body, pos, 1)
pos += 1
count = be_uint(rsp_body, pos, 2)
pos += 2
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(2, 1),
])

# Send the request (opcode 0x35)
port.write(build_request(123456789012, 0x35, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'DO Get Waveform failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
owner_id = be_uint(rsp_body, pos, 1)
pos += 1
hi_sec = be_uint(rsp_body, pos, 4)
pos += 4
low_sec = be_uint(rsp_body, pos, 4)
pos += 4
wave_cycles = be_uint(rsp_body, pos, 2)
pos += 2
final_level = be_uint(rsp_body, pos, 1)
pos += 1
active = be_uint(rsp_body, pos, 1)
pos += 1
count = be_uint(rsp_body, pos, 2)
pos += 2
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(2, 1),
]);

// Send the request (opcode 0x35)
dio_write($port, build_request(123456789012, 0x35, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('DO Get Waveform failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$owner_id = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hi_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
$low_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
$wave_cycles = be_uint($rsp_body, $pos, 2);
$pos += 2;
$final_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$active = be_uint($rsp_body, $pos, 1);
$pos += 1;
$count = be_uint($rsp_body, $pos, 2);
$pos += 2;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(2, 1),
);

# Send the request (opcode 0x35)
$port->write(build_request(123456789012, 0x35, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("DO Get Waveform failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $owner_id = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hi_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $low_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $wave_cycles = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $final_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $active = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $count = be_uint($rsp_body, $pos, 2);
$pos += 2;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(2, 1)
);

// Send the request (opcode 0x35)
port.writeBytes(buildRequest(123456789012L, 0x35, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("DO Get Waveform failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var ownerId = beUInt(rspBody, pos, 1);
pos += 1;
var hiSec = beUInt(rspBody, pos, 4);
pos += 4;
var lowSec = beUInt(rspBody, pos, 4);
pos += 4;
var waveCycles = beUInt(rspBody, pos, 2);
pos += 2;
var finalLevel = beUInt(rspBody, pos, 1);
pos += 1;
var active = beUInt(rspBody, pos, 1);
pos += 1;
var count = beUInt(rspBody, pos, 2);
pos += 2;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(2, 1),
  ]);

  // Send the request (opcode 0x35)
  port.write(buildRequest(123456789012, 0x35, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('DO Get Waveform failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const ownerId = beUInt(rspBody, pos, 1);
  pos += 1;
  const hiSec = beUInt(rspBody, pos, 4);
  pos += 4;
  const lowSec = beUInt(rspBody, pos, 4);
  pos += 4;
  const waveCycles = beUInt(rspBody, pos, 2);
  pos += 2;
  const finalLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const active = beUInt(rspBody, pos, 1);
  pos += 1;
  const count = beUInt(rspBody, pos, 2);
  pos += 2;
})();

DO Get Waveform

Returns the waveform settings and state for one digital output.

Opcode: 0x35. Body length: 1.

Request body

Field Bytes Description
Do_pin 1 Digital output index.

Response body

Field Bytes Description
OwnerId 1 Owner ID of the waveform.
Hi_sec 4 High seconds per cycle.
Low_sec 4 Low seconds per cycle.
Wave_cycles 2 Number of cycles.
Final_level 1 Output level after the last cycle.
Active 1 1 once the waveform is active. For a watch-driven waveform this is 0 until the watch triggers.
Count 2 Wave cycles completed for the current activation. 0xFFFF may mean overflow.
  • Returns RC_NO_WAVE_FOUND_ERR if there is no waveform on that output.

1-Wire Requests

Example: 1-Wire Scan

# 1-Wire Scan to serial number 123456789012 (opcode 0x18)
printf '\x43\x1c\xbe\x99\x1a\x14\x18\x00\x93\xf1' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x18, no body)
port.write(build_request(123456789012, 0x18))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('1-Wire Scan failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
responding_device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
responding_device_count.times do
  rec = {}
  rec['SlotId'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['FamilyCode'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['AssociatedName'] = be_str(rsp_body, pos, 11)
  pos += 11
  devices << rec
end
# Send the request (opcode 0x18, no body)
port.write(build_request(123456789012, 0x18))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'1-Wire Scan failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
responding_device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
for _ in range(responding_device_count):
    rec = {}
    rec['SlotId'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['FamilyCode'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['AssociatedName'] = be_str(rsp_body, pos, 11)
    pos += 11
    devices.append(rec)
// Send the request (opcode 0x18, no body)
dio_write($port, build_request(123456789012, 0x18));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('1-Wire Scan failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$responding_device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$devices = [];
for ($i = 0; $i < $responding_device_count; $i++) {
    $rec = [];
    $rec['SlotId'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['FamilyCode'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['AssociatedName'] = be_str($rsp_body, $pos, 11);
    $pos += 11;
    $devices[] = $rec;
}
# Send the request (opcode 0x18, no body)
$port->write(build_request(123456789012, 0x18));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("1-Wire Scan failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $responding_device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @devices;
for (1 .. $responding_device_count) {
    my %rec;
    $rec{'SlotId'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'FamilyCode'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'AssociatedName'} = be_str($rsp_body, $pos, 11);
    $pos += 11;
    push @devices, \%rec;
}
// Send the request (opcode 0x18, no body)
port.writeBytes(buildRequest(123456789012L, 0x18));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("1-Wire Scan failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var respondingDeviceCount = beUInt(rspBody, pos, 1);
pos += 1;
var devices = new ArrayList<Map<String, Object>>();
for (int i = 0; i < respondingDeviceCount; i++) {
    var rec = new HashMap<String, Object>();
    rec.put("SlotId", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("FamilyCode", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("AssociatedName", beStr(rspBody, pos, 11));
    pos += 11;
    devices.add(rec);
}
(async () => {
  // Send the request (opcode 0x18, no body)
  port.write(buildRequest(123456789012, 0x18));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('1-Wire Scan failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const respondingDeviceCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const devices = [];
  for (let i = 0; i < respondingDeviceCount; i++) {
      const rec = {};
      rec['SlotId'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['FamilyCode'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['AssociatedName'] = beStr(rspBody, pos, 11);
      pos += 11;
      devices.push(rec);
  }
})();

1-Wire Scan

Scans the 1-Wire bus and returns the devices that were found, with their slot IDs and names.

Opcode: 0x18. Body length: 0.

Request body: none.

Response body

Field Bytes Description
RespondingDeviceCount 1 Number of devices found.
Devices[] 13 One entry per device. Repeated RespondingDeviceCount times. Each entry is 13 bytes.
Devices[].SlotId 1 Slot ID from 1-Wire Scan.
Devices[].FamilyCode 1 Family code the device returns for a Search ROM command.
Devices[].AssociatedName 11 Name for this entry. Defaults to the family or device type name.
  • Returns RC_OW_SLOTIDS_FULL (0x02) if a new device was found but no slot ID is free. The devices are still returned.

Example: 1-Wire Read

# 1-Wire Read to serial number 123456789012 (opcode 0x19)
printf '\x43\x1c\xbe\x99\x1a\x14\x19\x00\x92\x61' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x19, no body)
port.write(build_request(123456789012, 0x19))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('1-Wire Read failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
responding_device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
responding_device_count.times do
  rec = {}
  rec['SlotId'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['Temperature'] = be_int(rsp_body, pos, 2)
  pos += 2
  rec['Humidity'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['Lux'] = be_uint(rsp_body, pos, 2)
  pos += 2
  devices << rec
end
# Send the request (opcode 0x19, no body)
port.write(build_request(123456789012, 0x19))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'1-Wire Read failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
responding_device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
for _ in range(responding_device_count):
    rec = {}
    rec['SlotId'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['Temperature'] = be_int(rsp_body, pos, 2)
    pos += 2
    rec['Humidity'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['Lux'] = be_uint(rsp_body, pos, 2)
    pos += 2
    devices.append(rec)
// Send the request (opcode 0x19, no body)
dio_write($port, build_request(123456789012, 0x19));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('1-Wire Read failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$responding_device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$devices = [];
for ($i = 0; $i < $responding_device_count; $i++) {
    $rec = [];
    $rec['SlotId'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['Temperature'] = be_int($rsp_body, $pos, 2);
    $pos += 2;
    $rec['Humidity'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['Lux'] = be_uint($rsp_body, $pos, 2);
    $pos += 2;
    $devices[] = $rec;
}
# Send the request (opcode 0x19, no body)
$port->write(build_request(123456789012, 0x19));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("1-Wire Read failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $responding_device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @devices;
for (1 .. $responding_device_count) {
    my %rec;
    $rec{'SlotId'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'Temperature'} = be_int($rsp_body, $pos, 2);
    $pos += 2;
    $rec{'Humidity'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'Lux'} = be_uint($rsp_body, $pos, 2);
    $pos += 2;
    push @devices, \%rec;
}
// Send the request (opcode 0x19, no body)
port.writeBytes(buildRequest(123456789012L, 0x19));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("1-Wire Read failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var respondingDeviceCount = beUInt(rspBody, pos, 1);
pos += 1;
var devices = new ArrayList<Map<String, Object>>();
for (int i = 0; i < respondingDeviceCount; i++) {
    var rec = new HashMap<String, Object>();
    rec.put("SlotId", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("Temperature", beInt(rspBody, pos, 2));
    pos += 2;
    rec.put("Humidity", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("Lux", beUInt(rspBody, pos, 2));
    pos += 2;
    devices.add(rec);
}
(async () => {
  // Send the request (opcode 0x19, no body)
  port.write(buildRequest(123456789012, 0x19));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('1-Wire Read failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const respondingDeviceCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const devices = [];
  for (let i = 0; i < respondingDeviceCount; i++) {
      const rec = {};
      rec['SlotId'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['Temperature'] = beInt(rspBody, pos, 2);
      pos += 2;
      rec['Humidity'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['Lux'] = beUInt(rspBody, pos, 2);
      pos += 2;
      devices.push(rec);
  }
})();

1-Wire Read

Reads the sensors on the 1-Wire bus. Temperature is in tenths of a degree Celsius. Humidity 0xFF and Lux 0xFFFF mean the value is not available. A dead device reports 0xEE in all fields.

Opcode: 0x19. Body length: 0.

Request body: none.

Response body

Field Bytes Description
RespondingDeviceCount 1 Number of devices read.
Devices[] 6 One entry per device. Repeated RespondingDeviceCount times. Each entry is 6 bytes.
Devices[].SlotId 1 Slot ID from 1-Wire Scan.
Devices[].Temperature 2 Temperature in tenths of a degree Celsius, signed. 0xEE in every field means the device did not respond.
Devices[].Humidity 1 Relative humidity in percent. 0xFF means not available.
Devices[].Lux 2 Light level in lumens per square meter. 0xFFFF means not available.

Example: 1-Wire Set Name

# 1-Wire Set Name to serial number 123456789012 (opcode 0x1A)
printf '\x43\x1c\xbe\x99\x1a\x14\x1a\x0c\x00\x54\x61\x6e\x6b\x00\x00\x00\x00\x00\x00\x00\x37\xc7' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
  padded('Tank', 11),
].join

# Send the request (opcode 0x1A)
port.write(build_request(123456789012, 0x1A, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('1-Wire Set Name failed: 0x%02X', rc) unless rc == 0x00
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
    padded('Tank', 11),
])

# Send the request (opcode 0x1A)
port.write(build_request(123456789012, 0x1A, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'1-Wire Set Name failed: {rc:#04x}')
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
    padded('Tank', 11),
]);

// Send the request (opcode 0x1A)
dio_write($port, build_request(123456789012, 0x1A, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('1-Wire Set Name failed: 0x%02X', $rc));
}
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
  padded('Tank', 11),
);

# Send the request (opcode 0x1A)
$port->write(build_request(123456789012, 0x1A, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("1-Wire Set Name failed: 0x%02X\n", $rc) unless $rc == 0x00;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1),
    padded("Tank", 11)
);

// Send the request (opcode 0x1A)
port.writeBytes(buildRequest(123456789012L, 0x1A, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("1-Wire Set Name failed: 0x%02X", rc));
}
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
    padded('Tank', 11),
  ]);

  // Send the request (opcode 0x1A)
  port.write(buildRequest(123456789012, 0x1A, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('1-Wire Set Name failed: 0x' + rc.toString(16));
})();

1-Wire Set Name

Sets a name for a 1-Wire slot. The name stays with the device if it is moved to another bus. If the first byte of the name is 0, the name is deleted.

Opcode: 0x1A. Body length: 12.

Request body

Field Bytes Description
SlotId 1 Slot ID from 1-Wire Scan.
NameString 11 Name, up to 10 characters.

Response body: status only.

Example: 1-Wire Get Names

# 1-Wire Get Names to serial number 123456789012 (opcode 0x1B)
printf '\x43\x1c\xbe\x99\x1a\x14\x1b\x00\x93\x01' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x1B, no body)
port.write(build_request(123456789012, 0x1B))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('1-Wire Get Names failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
pair_count = be_uint(rsp_body, pos, 1)
pos += 1
names = []
pair_count.times do
  rec = {}
  rec['SlotId'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['AssociatedName'] = be_str(rsp_body, pos, 11)
  pos += 11
  names << rec
end
# Send the request (opcode 0x1B, no body)
port.write(build_request(123456789012, 0x1B))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'1-Wire Get Names failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
pair_count = be_uint(rsp_body, pos, 1)
pos += 1
names = []
for _ in range(pair_count):
    rec = {}
    rec['SlotId'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['AssociatedName'] = be_str(rsp_body, pos, 11)
    pos += 11
    names.append(rec)
// Send the request (opcode 0x1B, no body)
dio_write($port, build_request(123456789012, 0x1B));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('1-Wire Get Names failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$pair_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$names = [];
for ($i = 0; $i < $pair_count; $i++) {
    $rec = [];
    $rec['SlotId'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['AssociatedName'] = be_str($rsp_body, $pos, 11);
    $pos += 11;
    $names[] = $rec;
}
# Send the request (opcode 0x1B, no body)
$port->write(build_request(123456789012, 0x1B));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("1-Wire Get Names failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $pair_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @names;
for (1 .. $pair_count) {
    my %rec;
    $rec{'SlotId'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'AssociatedName'} = be_str($rsp_body, $pos, 11);
    $pos += 11;
    push @names, \%rec;
}
// Send the request (opcode 0x1B, no body)
port.writeBytes(buildRequest(123456789012L, 0x1B));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("1-Wire Get Names failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var pairCount = beUInt(rspBody, pos, 1);
pos += 1;
var names = new ArrayList<Map<String, Object>>();
for (int i = 0; i < pairCount; i++) {
    var rec = new HashMap<String, Object>();
    rec.put("SlotId", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("AssociatedName", beStr(rspBody, pos, 11));
    pos += 11;
    names.add(rec);
}
(async () => {
  // Send the request (opcode 0x1B, no body)
  port.write(buildRequest(123456789012, 0x1B));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('1-Wire Get Names failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const pairCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const names = [];
  for (let i = 0; i < pairCount; i++) {
      const rec = {};
      rec['SlotId'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['AssociatedName'] = beStr(rspBody, pos, 11);
      pos += 11;
      names.push(rec);
  }
})();

1-Wire Get Names

Returns the name for each 1-Wire slot that has one.

Opcode: 0x1B. Body length: 0.

Request body: none.

Response body

Field Bytes Description
PairCount 1 Number of slot and name pairs.
Names[] 12 One entry per name. Repeated PairCount times. Each entry is 12 bytes.
Names[].SlotId 1 Slot ID from 1-Wire Scan.
Names[].AssociatedName 11 Name for this entry. Defaults to the family or device type name.

Example: 1-Wire Reset Names

# 1-Wire Reset Names to serial number 123456789012 (opcode 0x1C)
printf '\x43\x1c\xbe\x99\x1a\x14\x1c\x00\x91\x31' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x1C, no body)
port.write(build_request(123456789012, 0x1C))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('1-Wire Reset Names failed: 0x%02X', rc) unless rc == 0x00
# Send the request (opcode 0x1C, no body)
port.write(build_request(123456789012, 0x1C))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'1-Wire Reset Names failed: {rc:#04x}')
// Send the request (opcode 0x1C, no body)
dio_write($port, build_request(123456789012, 0x1C));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('1-Wire Reset Names failed: 0x%02X', $rc));
}
# Send the request (opcode 0x1C, no body)
$port->write(build_request(123456789012, 0x1C));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("1-Wire Reset Names failed: 0x%02X\n", $rc) unless $rc == 0x00;
// Send the request (opcode 0x1C, no body)
port.writeBytes(buildRequest(123456789012L, 0x1C));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("1-Wire Reset Names failed: 0x%02X", rc));
}
(async () => {
  // Send the request (opcode 0x1C, no body)
  port.write(buildRequest(123456789012, 0x1C));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('1-Wire Reset Names failed: 0x' + rc.toString(16));
})();

1-Wire Reset Names

Clears all the names set with 1-Wire Set Name and restores the default names.

Opcode: 0x1C. Body length: 0.

Request body: none.

Response body: status only.

Example: 1-Wire Read I/O

# 1-Wire Read I/O to serial number 123456789012 (opcode 0x3D)
printf '\x43\x1c\xbe\x99\x1a\x14\x3d\x00\x89\x61' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x3D, no body)
port.write(build_request(123456789012, 0x3D))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('1-Wire Read I/O failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
responding_device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
responding_device_count.times do
  rec = {}
  rec['SlotId'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['StatePIOA'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['StatePIOB'] = be_uint(rsp_body, pos, 1)
  pos += 1
  devices << rec
end
# Send the request (opcode 0x3D, no body)
port.write(build_request(123456789012, 0x3D))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'1-Wire Read I/O failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
responding_device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
for _ in range(responding_device_count):
    rec = {}
    rec['SlotId'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['StatePIOA'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['StatePIOB'] = be_uint(rsp_body, pos, 1)
    pos += 1
    devices.append(rec)
// Send the request (opcode 0x3D, no body)
dio_write($port, build_request(123456789012, 0x3D));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('1-Wire Read I/O failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$responding_device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$devices = [];
for ($i = 0; $i < $responding_device_count; $i++) {
    $rec = [];
    $rec['SlotId'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['StatePIOA'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['StatePIOB'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $devices[] = $rec;
}
# Send the request (opcode 0x3D, no body)
$port->write(build_request(123456789012, 0x3D));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("1-Wire Read I/O failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $responding_device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @devices;
for (1 .. $responding_device_count) {
    my %rec;
    $rec{'SlotId'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'StatePIOA'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'StatePIOB'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    push @devices, \%rec;
}
// Send the request (opcode 0x3D, no body)
port.writeBytes(buildRequest(123456789012L, 0x3D));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("1-Wire Read I/O failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var respondingDeviceCount = beUInt(rspBody, pos, 1);
pos += 1;
var devices = new ArrayList<Map<String, Object>>();
for (int i = 0; i < respondingDeviceCount; i++) {
    var rec = new HashMap<String, Object>();
    rec.put("SlotId", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("StatePIOA", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("StatePIOB", beUInt(rspBody, pos, 1));
    pos += 1;
    devices.add(rec);
}
(async () => {
  // Send the request (opcode 0x3D, no body)
  port.write(buildRequest(123456789012, 0x3D));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('1-Wire Read I/O failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const respondingDeviceCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const devices = [];
  for (let i = 0; i < respondingDeviceCount; i++) {
      const rec = {};
      rec['SlotId'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['StatePIOA'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['StatePIOB'] = beUInt(rspBody, pos, 1);
      pos += 1;
      devices.push(rec);
  }
})();

1-Wire Read I/O

Reads the two I/O pins (PIOA and PIOB) on each DS2413 1-Wire I/O device. Each state byte has the drive level in bit 1 and the pin level in bit 0. A device that does not respond returns 0xEE.

Opcode: 0x3D. Body length: 0.

Request body: none.

Response body

Field Bytes Description
RespondingDeviceCount 1 Number of I/O devices.
Devices[] 3 One entry per device. Each state is 0 or 1. Repeated RespondingDeviceCount times. Each entry is 3 bytes.
Devices[].SlotId 1 Slot ID from 1-Wire Scan.
Devices[].StatePIOA 1 PIOA state, 0 or 1. Bit 1 is the drive level and bit 0 the pin level.
Devices[].StatePIOB 1 PIOB state, 0 or 1. Bit 1 is the drive level and bit 0 the pin level.

Example: 1-Wire Write I/O

# 1-Wire Write I/O to serial number 123456789012 (opcode 0x3E)
printf '\x43\x1c\xbe\x99\x1a\x14\x3e\x03\x00\x01\x00\xbd\xae' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
  be(1, 1),
  be(0, 1),
].join

# Send the request (opcode 0x3E)
port.write(build_request(123456789012, 0x3E, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('1-Wire Write I/O failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
state_pioa = be_uint(rsp_body, pos, 1)
pos += 1
state_piob = be_uint(rsp_body, pos, 1)
pos += 1
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
    be(1, 1),
    be(0, 1),
])

# Send the request (opcode 0x3E)
port.write(build_request(123456789012, 0x3E, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'1-Wire Write I/O failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
state_pioa = be_uint(rsp_body, pos, 1)
pos += 1
state_piob = be_uint(rsp_body, pos, 1)
pos += 1
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
    be(1, 1),
    be(0, 1),
]);

// Send the request (opcode 0x3E)
dio_write($port, build_request(123456789012, 0x3E, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('1-Wire Write I/O failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$state_pioa = be_uint($rsp_body, $pos, 1);
$pos += 1;
$state_piob = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
  be(1, 1),
  be(0, 1),
);

# Send the request (opcode 0x3E)
$port->write(build_request(123456789012, 0x3E, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("1-Wire Write I/O failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $state_pioa = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $state_piob = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1),
    be(1, 1),
    be(0, 1)
);

// Send the request (opcode 0x3E)
port.writeBytes(buildRequest(123456789012L, 0x3E, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("1-Wire Write I/O failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var statePioa = beUInt(rspBody, pos, 1);
pos += 1;
var statePiob = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
    be(1, 1),
    be(0, 1),
  ]);

  // Send the request (opcode 0x3E)
  port.write(buildRequest(123456789012, 0x3E, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('1-Wire Write I/O failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const statePioa = beUInt(rspBody, pos, 1);
  pos += 1;
  const statePiob = beUInt(rspBody, pos, 1);
  pos += 1;
})();

1-Wire Write I/O

Drives the PIOA and PIOB pins on a 1-Wire I/O device. Each pin is 0 or 1.

Opcode: 0x3E. Body length: 3.

Request body

Field Bytes Description
SlotId 1 Slot ID from 1-Wire Scan.
DriveLevelA 1 Level for PIOA, 0 or 1.
DriveLevelB 1 Level for PIOB, 0 or 1.

Response body

Field Bytes Description
StatePIOA 1 PIOA state after the change.
StatePIOB 1 PIOB state after the change.

Example: 1-Wire Set Watch

# 1-Wire Set Watch to serial number 123456789012 (opcode 0x36)
printf '\x43\x1c\xbe\x99\x1a\x14\x36\x1d\x00\x00\x00\x00\x00\x01\x00\xfa\x01\x2c\x00\x0a\x00\x05\x01\x02\x00\x00\x00\x05\x00\x00\x00\x05\x00\x03\x00\x00\x01\xfb\x6a' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 4),
  be(0, 1),
  be(1, 1),
  be(250, 2),
  be(300, 2),
  be(10, 2),
  be(5, 2),
  be(1, 1),
  be(2, 1),
  be(5, 4),
  be(5, 4),
  be(3, 2),
  be(0, 1),
  be(0, 1),
  be(1, 1),
].join

# Send the request (opcode 0x36)
port.write(build_request(123456789012, 0x36, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('1-Wire Set Watch failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
was_cleared = be_uint(rsp_body, pos, 1)
pos += 1
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 4),
    be(0, 1),
    be(1, 1),
    be(250, 2),
    be(300, 2),
    be(10, 2),
    be(5, 2),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
])

# Send the request (opcode 0x36)
port.write(build_request(123456789012, 0x36, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'1-Wire Set Watch failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
was_cleared = be_uint(rsp_body, pos, 1)
pos += 1
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 4),
    be(0, 1),
    be(1, 1),
    be(250, 2),
    be(300, 2),
    be(10, 2),
    be(5, 2),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
]);

// Send the request (opcode 0x36)
dio_write($port, build_request(123456789012, 0x36, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('1-Wire Set Watch failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$was_cleared = be_uint($rsp_body, $pos, 1);
$pos += 1;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 4),
  be(0, 1),
  be(1, 1),
  be(250, 2),
  be(300, 2),
  be(10, 2),
  be(5, 2),
  be(1, 1),
  be(2, 1),
  be(5, 4),
  be(5, 4),
  be(3, 2),
  be(0, 1),
  be(0, 1),
  be(1, 1),
);

# Send the request (opcode 0x36)
$port->write(build_request(123456789012, 0x36, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("1-Wire Set Watch failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $was_cleared = be_uint($rsp_body, $pos, 1);
$pos += 1;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 4),
    be(0, 1),
    be(1, 1),
    be(250, 2),
    be(300, 2),
    be(10, 2),
    be(5, 2),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1)
);

// Send the request (opcode 0x36)
port.writeBytes(buildRequest(123456789012L, 0x36, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("1-Wire Set Watch failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var wasCleared = beUInt(rspBody, pos, 1);
pos += 1;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 4),
    be(0, 1),
    be(1, 1),
    be(250, 2),
    be(300, 2),
    be(10, 2),
    be(5, 2),
    be(1, 1),
    be(2, 1),
    be(5, 4),
    be(5, 4),
    be(3, 2),
    be(0, 1),
    be(0, 1),
    be(1, 1),
  ]);

  // Send the request (opcode 0x36)
  port.write(buildRequest(123456789012, 0x36, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('1-Wire Set Watch failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const wasCleared = beUInt(rspBody, pos, 1);
  pos += 1;
})();

1-Wire Set Watch

Sets a watch on a 1-Wire sensor. The watch uses temperature (WatchType 1, in tenths of a degree) or humidity (WatchType 2, in percent). When the value stays above GreaterThan or below LessThan for the minimum time, the watch drives a digital output with a waveform. Set GreaterThan and LessThan to 0 to clear the watch.

Opcode: 0x36. Body length: 29.

Request body

Field Bytes Description
Password 4 Password, 4 bytes. Always use the factory password 00000000.
SlotId 1 Slot ID from 1-Wire Scan.
WatchType 1 1 for temperature, 2 for humidity.
GreaterThan 2 Upper threshold. Signed. For temperature, 250 is 25.0 C.
LessThan 2 Lower threshold. Signed.
MinTrueSec 2 Seconds the condition must be true before the watch fires.
MinFalseSec 2 Seconds the condition must be false before the watch clears.
Restart 1 0 clears the watch after it triggers. 1 restarts it after it triggers. 2 restarts it after it triggers and after a chip reset.
Do_pin 1 Digital output to drive. 0xFF means no output.
Hi_sec 4 Seconds the output stays high in each cycle.
Low_sec 4 Seconds the output stays low in each cycle.
Wave_cycles 2 Number of cycles. 0 means repeat forever.
Initial_level 1 Output level before the first cycle.
Interim_level 1 Output level between cycles.
Final_level 1 Output level after the last cycle.

Response body

Field Bytes Description
WasCleared 1 1 if an existing watch was replaced, 0 if not.
  • If the status is RC_DO_BUSY_ERR (0x93), the body holds the owner ID of the waveform that is using the output instead.

Example: 1-Wire Get Watch

# 1-Wire Get Watch to serial number 123456789012 (opcode 0x37)
printf '\x43\x1c\xbe\x99\x1a\x14\x37\x01\x00\x81\x34' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
].join

# Send the request (opcode 0x37)
port.write(build_request(123456789012, 0x37, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('1-Wire Get Watch failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
watch_type = be_uint(rsp_body, pos, 1)
pos += 1
current_value = be_int(rsp_body, pos, 2)
pos += 2
greater_than = be_int(rsp_body, pos, 2)
pos += 2
less_than = be_int(rsp_body, pos, 2)
pos += 2
min_true_sec = be_uint(rsp_body, pos, 2)
pos += 2
min_false_sec = be_uint(rsp_body, pos, 2)
pos += 2
restart = be_uint(rsp_body, pos, 1)
pos += 1
do_pin = be_uint(rsp_body, pos, 1)
pos += 1
hi_sec = be_uint(rsp_body, pos, 4)
pos += 4
low_sec = be_uint(rsp_body, pos, 4)
pos += 4
wave_cycles = be_uint(rsp_body, pos, 2)
pos += 2
initial_level = be_uint(rsp_body, pos, 1)
pos += 1
interim_level = be_uint(rsp_body, pos, 1)
pos += 1
final_level = be_uint(rsp_body, pos, 1)
pos += 1
hit_count = be_uint(rsp_body, pos, 2)
pos += 2
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
])

# Send the request (opcode 0x37)
port.write(build_request(123456789012, 0x37, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'1-Wire Get Watch failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
watch_type = be_uint(rsp_body, pos, 1)
pos += 1
current_value = be_int(rsp_body, pos, 2)
pos += 2
greater_than = be_int(rsp_body, pos, 2)
pos += 2
less_than = be_int(rsp_body, pos, 2)
pos += 2
min_true_sec = be_uint(rsp_body, pos, 2)
pos += 2
min_false_sec = be_uint(rsp_body, pos, 2)
pos += 2
restart = be_uint(rsp_body, pos, 1)
pos += 1
do_pin = be_uint(rsp_body, pos, 1)
pos += 1
hi_sec = be_uint(rsp_body, pos, 4)
pos += 4
low_sec = be_uint(rsp_body, pos, 4)
pos += 4
wave_cycles = be_uint(rsp_body, pos, 2)
pos += 2
initial_level = be_uint(rsp_body, pos, 1)
pos += 1
interim_level = be_uint(rsp_body, pos, 1)
pos += 1
final_level = be_uint(rsp_body, pos, 1)
pos += 1
hit_count = be_uint(rsp_body, pos, 2)
pos += 2
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
]);

// Send the request (opcode 0x37)
dio_write($port, build_request(123456789012, 0x37, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('1-Wire Get Watch failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$watch_type = be_uint($rsp_body, $pos, 1);
$pos += 1;
$current_value = be_int($rsp_body, $pos, 2);
$pos += 2;
$greater_than = be_int($rsp_body, $pos, 2);
$pos += 2;
$less_than = be_int($rsp_body, $pos, 2);
$pos += 2;
$min_true_sec = be_uint($rsp_body, $pos, 2);
$pos += 2;
$min_false_sec = be_uint($rsp_body, $pos, 2);
$pos += 2;
$restart = be_uint($rsp_body, $pos, 1);
$pos += 1;
$do_pin = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hi_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
$low_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
$wave_cycles = be_uint($rsp_body, $pos, 2);
$pos += 2;
$initial_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$interim_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$final_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
$hit_count = be_uint($rsp_body, $pos, 2);
$pos += 2;
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
);

# Send the request (opcode 0x37)
$port->write(build_request(123456789012, 0x37, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("1-Wire Get Watch failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $watch_type = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $current_value = be_int($rsp_body, $pos, 2);
$pos += 2;
my $greater_than = be_int($rsp_body, $pos, 2);
$pos += 2;
my $less_than = be_int($rsp_body, $pos, 2);
$pos += 2;
my $min_true_sec = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $min_false_sec = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $restart = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $do_pin = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hi_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $low_sec = be_uint($rsp_body, $pos, 4);
$pos += 4;
my $wave_cycles = be_uint($rsp_body, $pos, 2);
$pos += 2;
my $initial_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $interim_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $final_level = be_uint($rsp_body, $pos, 1);
$pos += 1;
my $hit_count = be_uint($rsp_body, $pos, 2);
$pos += 2;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1)
);

// Send the request (opcode 0x37)
port.writeBytes(buildRequest(123456789012L, 0x37, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("1-Wire Get Watch failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var watchType = beUInt(rspBody, pos, 1);
pos += 1;
var currentValue = beInt(rspBody, pos, 2);
pos += 2;
var greaterThan = beInt(rspBody, pos, 2);
pos += 2;
var lessThan = beInt(rspBody, pos, 2);
pos += 2;
var minTrueSec = beUInt(rspBody, pos, 2);
pos += 2;
var minFalseSec = beUInt(rspBody, pos, 2);
pos += 2;
var restart = beUInt(rspBody, pos, 1);
pos += 1;
var doPin = beUInt(rspBody, pos, 1);
pos += 1;
var hiSec = beUInt(rspBody, pos, 4);
pos += 4;
var lowSec = beUInt(rspBody, pos, 4);
pos += 4;
var waveCycles = beUInt(rspBody, pos, 2);
pos += 2;
var initialLevel = beUInt(rspBody, pos, 1);
pos += 1;
var interimLevel = beUInt(rspBody, pos, 1);
pos += 1;
var finalLevel = beUInt(rspBody, pos, 1);
pos += 1;
var hitCount = beUInt(rspBody, pos, 2);
pos += 2;
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
  ]);

  // Send the request (opcode 0x37)
  port.write(buildRequest(123456789012, 0x37, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('1-Wire Get Watch failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const watchType = beUInt(rspBody, pos, 1);
  pos += 1;
  const currentValue = beInt(rspBody, pos, 2);
  pos += 2;
  const greaterThan = beInt(rspBody, pos, 2);
  pos += 2;
  const lessThan = beInt(rspBody, pos, 2);
  pos += 2;
  const minTrueSec = beUInt(rspBody, pos, 2);
  pos += 2;
  const minFalseSec = beUInt(rspBody, pos, 2);
  pos += 2;
  const restart = beUInt(rspBody, pos, 1);
  pos += 1;
  const doPin = beUInt(rspBody, pos, 1);
  pos += 1;
  const hiSec = beUInt(rspBody, pos, 4);
  pos += 4;
  const lowSec = beUInt(rspBody, pos, 4);
  pos += 4;
  const waveCycles = beUInt(rspBody, pos, 2);
  pos += 2;
  const initialLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const interimLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const finalLevel = beUInt(rspBody, pos, 1);
  pos += 1;
  const hitCount = beUInt(rspBody, pos, 2);
  pos += 2;
})();

1-Wire Get Watch

Returns the watch settings and state for one 1-Wire slot.

Opcode: 0x37. Body length: 1.

Request body

Field Bytes Description
SlotId 1 Slot ID from 1-Wire Scan.

Response body

Field Bytes Description
WatchType 1 1 for temperature, 2 for humidity.
CurrentValue 2 Current sensor value.
GreaterThan 2 Upper threshold.
LessThan 2 Lower threshold.
MinTrueSec 2 Seconds the condition must be true.
MinFalseSec 2 Seconds the condition must be false.
Restart 1 Restart flag.
Do_pin 1 Digital output driven by the watch.
Hi_sec 4 High seconds per cycle.
Low_sec 4 Low seconds per cycle.
Wave_cycles 2 Number of cycles.
Initial_level 1 Initial output level.
Interim_level 1 Interim output level.
Final_level 1 Final output level.
HitCount 2 Number of times the watch has fired.
  • Returns RC_NO_WATCH_FOUND_ERR if no watch is set on that slot.

Example: 1-Wire Set ID Map

# 1-Wire Set ID Map to serial number 123456789012 (opcode 0x38)
printf '\x43\x1c\xbe\x99\x1a\x14\x38\x02\x02\x00\x06\x14' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(2, 1),
  be(0, 1),
].join

# Send the request (opcode 0x38)
port.write(build_request(123456789012, 0x38, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('1-Wire Set ID Map failed: 0x%02X', rc) unless rc == 0x00
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(2, 1),
    be(0, 1),
])

# Send the request (opcode 0x38)
port.write(build_request(123456789012, 0x38, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'1-Wire Set ID Map failed: {rc:#04x}')
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(2, 1),
    be(0, 1),
]);

// Send the request (opcode 0x38)
dio_write($port, build_request(123456789012, 0x38, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('1-Wire Set ID Map failed: 0x%02X', $rc));
}
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(2, 1),
  be(0, 1),
);

# Send the request (opcode 0x38)
$port->write(build_request(123456789012, 0x38, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("1-Wire Set ID Map failed: 0x%02X\n", $rc) unless $rc == 0x00;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(2, 1),
    be(0, 1)
);

// Send the request (opcode 0x38)
port.writeBytes(buildRequest(123456789012L, 0x38, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("1-Wire Set ID Map failed: 0x%02X", rc));
}
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(2, 1),
    be(0, 1),
  ]);

  // Send the request (opcode 0x38)
  port.write(buildRequest(123456789012, 0x38, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('1-Wire Set ID Map failed: 0x' + rc.toString(16));
})();

1-Wire Set ID Map

Clears slot ID assignments. Flags must have exactly one bit set: 0x01 clears all slots from SlotId to the end (with SlotId 0 it clears all of them), 0x02 clears only SlotId, and 0x04 holds SlotId for its device until the table is full.

Opcode: 0x38. Body length: 2.

Request body

Field Bytes Description
Flags 1 0x01 multiple clear, 0x02 single clear, 0x04 single hold.
SlotId 1 Slot ID to act on.

Response body: status only.

Example: 1-Wire Get ID Map

# 1-Wire Get ID Map to serial number 123456789012 (opcode 0x39)
printf '\x43\x1c\xbe\x99\x1a\x14\x39\x01\x00\xe0\xf7' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
].join

# Send the request (opcode 0x39)
port.write(build_request(123456789012, 0x39, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('1-Wire Get ID Map failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
pair_count = be_uint(rsp_body, pos, 1)
pos += 1
pairs = []
pair_count.times do
  rec = {}
  rec['SlotId'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['RomCode'] = be_hex(rsp_body, pos, 8)
  pos += 8
  pairs << rec
end
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
])

# Send the request (opcode 0x39)
port.write(build_request(123456789012, 0x39, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'1-Wire Get ID Map failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
pair_count = be_uint(rsp_body, pos, 1)
pos += 1
pairs = []
for _ in range(pair_count):
    rec = {}
    rec['SlotId'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['RomCode'] = be_hex(rsp_body, pos, 8)
    pos += 8
    pairs.append(rec)
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
]);

// Send the request (opcode 0x39)
dio_write($port, build_request(123456789012, 0x39, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('1-Wire Get ID Map failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$pair_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$pairs = [];
for ($i = 0; $i < $pair_count; $i++) {
    $rec = [];
    $rec['SlotId'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['RomCode'] = be_hex($rsp_body, $pos, 8);
    $pos += 8;
    $pairs[] = $rec;
}
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
);

# Send the request (opcode 0x39)
$port->write(build_request(123456789012, 0x39, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("1-Wire Get ID Map failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $pair_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @pairs;
for (1 .. $pair_count) {
    my %rec;
    $rec{'SlotId'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'RomCode'} = be_hex($rsp_body, $pos, 8);
    $pos += 8;
    push @pairs, \%rec;
}
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1)
);

// Send the request (opcode 0x39)
port.writeBytes(buildRequest(123456789012L, 0x39, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("1-Wire Get ID Map failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var pairCount = beUInt(rspBody, pos, 1);
pos += 1;
var pairs = new ArrayList<Map<String, Object>>();
for (int i = 0; i < pairCount; i++) {
    var rec = new HashMap<String, Object>();
    rec.put("SlotId", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("RomCode", beHex(rspBody, pos, 8));
    pos += 8;
    pairs.add(rec);
}
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
  ]);

  // Send the request (opcode 0x39)
  port.write(buildRequest(123456789012, 0x39, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('1-Wire Get ID Map failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const pairCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const pairs = [];
  for (let i = 0; i < pairCount; i++) {
      const rec = {};
      rec['SlotId'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['RomCode'] = beHex(rspBody, pos, 8);
      pos += 8;
      pairs.push(rec);
  }
})();

1-Wire Get ID Map

Returns the slot ID and device ROM code pairs stored in NVRAM. A pair does not mean the device is connected. Use 1-Wire Scan for the current state. Up to 19 pairs are returned.

Opcode: 0x39. Body length: 1.

Request body

Field Bytes Description
Starting_slotId 1 First slot ID to report. Normally 0.

Response body

Field Bytes Description
PairCount 1 Number of pairs returned.
Pairs[] 9 One entry per pair. The ROM code is FamilyCode, SerialId, and CRC. Repeated PairCount times. Each entry is 9 bytes.
Pairs[].SlotId 1 Slot ID from 1-Wire Scan.
Pairs[].RomCode 8 8-byte ROM code: family code, 6-byte serial ID, and CRC.

Example: 1-Wire Get Buses

# 1-Wire Get Buses to serial number 123456789012 (opcode 0x3A)
printf '\x43\x1c\xbe\x99\x1a\x14\x3a\x00\x8b\x51' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x3A, no body)
port.write(build_request(123456789012, 0x3A))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('1-Wire Get Buses failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
scanned_device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
scanned_device_count.times do
  rec = {}
  rec['BusId'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['SlotId'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['RomCode'] = be_hex(rsp_body, pos, 8)
  pos += 8
  devices << rec
end
# Send the request (opcode 0x3A, no body)
port.write(build_request(123456789012, 0x3A))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'1-Wire Get Buses failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
scanned_device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
for _ in range(scanned_device_count):
    rec = {}
    rec['BusId'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['SlotId'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['RomCode'] = be_hex(rsp_body, pos, 8)
    pos += 8
    devices.append(rec)
// Send the request (opcode 0x3A, no body)
dio_write($port, build_request(123456789012, 0x3A));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('1-Wire Get Buses failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$scanned_device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$devices = [];
for ($i = 0; $i < $scanned_device_count; $i++) {
    $rec = [];
    $rec['BusId'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['SlotId'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['RomCode'] = be_hex($rsp_body, $pos, 8);
    $pos += 8;
    $devices[] = $rec;
}
# Send the request (opcode 0x3A, no body)
$port->write(build_request(123456789012, 0x3A));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("1-Wire Get Buses failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $scanned_device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @devices;
for (1 .. $scanned_device_count) {
    my %rec;
    $rec{'BusId'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'SlotId'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'RomCode'} = be_hex($rsp_body, $pos, 8);
    $pos += 8;
    push @devices, \%rec;
}
// Send the request (opcode 0x3A, no body)
port.writeBytes(buildRequest(123456789012L, 0x3A));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("1-Wire Get Buses failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var scannedDeviceCount = beUInt(rspBody, pos, 1);
pos += 1;
var devices = new ArrayList<Map<String, Object>>();
for (int i = 0; i < scannedDeviceCount; i++) {
    var rec = new HashMap<String, Object>();
    rec.put("BusId", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("SlotId", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("RomCode", beHex(rspBody, pos, 8));
    pos += 8;
    devices.add(rec);
}
(async () => {
  // Send the request (opcode 0x3A, no body)
  port.write(buildRequest(123456789012, 0x3A));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('1-Wire Get Buses failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const scannedDeviceCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const devices = [];
  for (let i = 0; i < scannedDeviceCount; i++) {
      const rec = {};
      rec['BusId'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['SlotId'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['RomCode'] = beHex(rspBody, pos, 8);
      pos += 8;
      devices.push(rec);
  }
})();

1-Wire Get Buses

Returns the bus, slot ID, and ROM code for each device that the last scan found.

Opcode: 0x3A. Body length: 0.

Request body: none.

Response body

Field Bytes Description
ScannedDeviceCount 1 Number of devices found by the last scan.
Devices[] 10 One entry per device. Repeated ScannedDeviceCount times. Each entry is 10 bytes.
Devices[].BusId 1 1-Wire bus number, 0 to 3.
Devices[].SlotId 1 Slot ID from 1-Wire Scan.
Devices[].RomCode 8 8-byte ROM code: family code, 6-byte serial ID, and CRC.

TWI Requests

Example: TWI List

# TWI List to serial number 123456789012 (opcode 0x2A)
printf '\x43\x1c\xbe\x99\x1a\x14\x2a\x01\x00\x11\x32' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
].join

# Send the request (opcode 0x2A)
port.write(build_request(123456789012, 0x2A, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('TWI List failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
device_count = be_uint(rsp_body, pos, 1)
pos += 1
device_address = []
device_count.times do
  device_address << be_uint(rsp_body, pos, 1)
  pos += 1
end
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
])

# Send the request (opcode 0x2A)
port.write(build_request(123456789012, 0x2A, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'TWI List failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
device_count = be_uint(rsp_body, pos, 1)
pos += 1
device_address = []
for _ in range(device_count):
    device_address.append(be_uint(rsp_body, pos, 1))
    pos += 1
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
]);

// Send the request (opcode 0x2A)
dio_write($port, build_request(123456789012, 0x2A, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('TWI List failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$device_address = [];
for ($i = 0; $i < $device_count; $i++) {
    $device_address[] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
);

# Send the request (opcode 0x2A)
$port->write(build_request(123456789012, 0x2A, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("TWI List failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @device_address;
for (1 .. $device_count) {
    push @device_address, be_uint($rsp_body, $pos, 1);
    $pos += 1;
}
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1)
);

// Send the request (opcode 0x2A)
port.writeBytes(buildRequest(123456789012L, 0x2A, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("TWI List failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var deviceCount = beUInt(rspBody, pos, 1);
pos += 1;
var deviceAddress = new ArrayList<Long>();
for (int i = 0; i < deviceCount; i++) {
    deviceAddress.add(beUInt(rspBody, pos, 1));
    pos += 1;
}
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
  ]);

  // Send the request (opcode 0x2A)
  port.write(buildRequest(123456789012, 0x2A, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('TWI List failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const deviceCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const deviceAddress = [];
  for (let i = 0; i < deviceCount; i++) {
      deviceAddress.push(beUInt(rspBody, pos, 1));
      pos += 1;
  }
})();

TWI List

Lists every 7-bit address that answers on a TWI/I2C bus. Multiply an address by 2 to get the 8-bit address. Functionality is not checked.

Opcode: 0x2A. Body length: 1.

Request body

Field Bytes Description
BusIndex 1 TWI/I2C bus index.

Response body

Field Bytes Description
DeviceCount 1 Number of addresses that answered.
DeviceAddress[] 1 7-bit address of each device. Repeated DeviceCount times.

Example: TWI Scan

# TWI Scan to serial number 123456789012 (opcode 0x2B)
printf '\x43\x1c\xbe\x99\x1a\x14\x2b\x01\x00\x40\xf2' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
].join

# Send the request (opcode 0x2B)
port.write(build_request(123456789012, 0x2B, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('TWI Scan failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
device_count.times do
  rec = {}
  rec['DeviceAddress'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['TypeCode'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['AssociatedName'] = be_str(rsp_body, pos, 11)
  pos += 11
  devices << rec
end
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
])

# Send the request (opcode 0x2B)
port.write(build_request(123456789012, 0x2B, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'TWI Scan failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
for _ in range(device_count):
    rec = {}
    rec['DeviceAddress'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['TypeCode'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['AssociatedName'] = be_str(rsp_body, pos, 11)
    pos += 11
    devices.append(rec)
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
]);

// Send the request (opcode 0x2B)
dio_write($port, build_request(123456789012, 0x2B, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('TWI Scan failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$devices = [];
for ($i = 0; $i < $device_count; $i++) {
    $rec = [];
    $rec['DeviceAddress'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['TypeCode'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['AssociatedName'] = be_str($rsp_body, $pos, 11);
    $pos += 11;
    $devices[] = $rec;
}
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
);

# Send the request (opcode 0x2B)
$port->write(build_request(123456789012, 0x2B, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("TWI Scan failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @devices;
for (1 .. $device_count) {
    my %rec;
    $rec{'DeviceAddress'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'TypeCode'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'AssociatedName'} = be_str($rsp_body, $pos, 11);
    $pos += 11;
    push @devices, \%rec;
}
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1)
);

// Send the request (opcode 0x2B)
port.writeBytes(buildRequest(123456789012L, 0x2B, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("TWI Scan failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var deviceCount = beUInt(rspBody, pos, 1);
pos += 1;
var devices = new ArrayList<Map<String, Object>>();
for (int i = 0; i < deviceCount; i++) {
    var rec = new HashMap<String, Object>();
    rec.put("DeviceAddress", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("TypeCode", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("AssociatedName", beStr(rspBody, pos, 11));
    pos += 11;
    devices.add(rec);
}
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
  ]);

  // Send the request (opcode 0x2B)
  port.write(buildRequest(123456789012, 0x2B, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('TWI Scan failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const deviceCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const devices = [];
  for (let i = 0; i < deviceCount; i++) {
      const rec = {};
      rec['DeviceAddress'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['TypeCode'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['AssociatedName'] = beStr(rspBody, pos, 11);
      pos += 11;
      devices.push(rec);
  }
})();

TWI Scan

Scans a TWI/I2C bus and recognizes the devices it supports. TypeCode 0x00 is an unknown device, 0x01 is an MCP9808 temperature sensor, and 0x02 is an INA219 current and power monitor.

Opcode: 0x2B. Body length: 1.

Request body

Field Bytes Description
BusIndex 1 TWI/I2C bus index.

Response body

Field Bytes Description
DeviceCount 1 Number of devices found.
Devices[] 13 One entry per device. Addresses are 7-bit. Repeated DeviceCount times. Each entry is 13 bytes.
Devices[].DeviceAddress 1 7-bit TWI/I2C address.
Devices[].TypeCode 1 0x00 unknown, 0x01 MCP9808 temperature, 0x02 INA219 current and power.
Devices[].AssociatedName 11 Name for this entry. Defaults to the family or device type name.

Example: TWI Read

# TWI Read to serial number 123456789012 (opcode 0x2C)
printf '\x43\x1c\xbe\x99\x1a\x14\x2c\x01\x00\xf1\x33' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
].join

# Send the request (opcode 0x2C)
port.write(build_request(123456789012, 0x2C, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('TWI Read failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
device_count.times do
  rec = {}
  rec['DeviceAddress'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['TypeCode'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['Value1'] = be_int(rsp_body, pos, 2)
  pos += 2
  rec['Value2'] = be_uint(rsp_body, pos, 2)
  pos += 2
  rec['Value3'] = be_uint(rsp_body, pos, 2)
  pos += 2
  devices << rec
end
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
])

# Send the request (opcode 0x2C)
port.write(build_request(123456789012, 0x2C, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'TWI Read failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
for _ in range(device_count):
    rec = {}
    rec['DeviceAddress'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['TypeCode'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['Value1'] = be_int(rsp_body, pos, 2)
    pos += 2
    rec['Value2'] = be_uint(rsp_body, pos, 2)
    pos += 2
    rec['Value3'] = be_uint(rsp_body, pos, 2)
    pos += 2
    devices.append(rec)
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
]);

// Send the request (opcode 0x2C)
dio_write($port, build_request(123456789012, 0x2C, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('TWI Read failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$devices = [];
for ($i = 0; $i < $device_count; $i++) {
    $rec = [];
    $rec['DeviceAddress'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['TypeCode'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['Value1'] = be_int($rsp_body, $pos, 2);
    $pos += 2;
    $rec['Value2'] = be_uint($rsp_body, $pos, 2);
    $pos += 2;
    $rec['Value3'] = be_uint($rsp_body, $pos, 2);
    $pos += 2;
    $devices[] = $rec;
}
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
);

# Send the request (opcode 0x2C)
$port->write(build_request(123456789012, 0x2C, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("TWI Read failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @devices;
for (1 .. $device_count) {
    my %rec;
    $rec{'DeviceAddress'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'TypeCode'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'Value1'} = be_int($rsp_body, $pos, 2);
    $pos += 2;
    $rec{'Value2'} = be_uint($rsp_body, $pos, 2);
    $pos += 2;
    $rec{'Value3'} = be_uint($rsp_body, $pos, 2);
    $pos += 2;
    push @devices, \%rec;
}
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1)
);

// Send the request (opcode 0x2C)
port.writeBytes(buildRequest(123456789012L, 0x2C, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("TWI Read failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var deviceCount = beUInt(rspBody, pos, 1);
pos += 1;
var devices = new ArrayList<Map<String, Object>>();
for (int i = 0; i < deviceCount; i++) {
    var rec = new HashMap<String, Object>();
    rec.put("DeviceAddress", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("TypeCode", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("Value1", beInt(rspBody, pos, 2));
    pos += 2;
    rec.put("Value2", beUInt(rspBody, pos, 2));
    pos += 2;
    rec.put("Value3", beUInt(rspBody, pos, 2));
    pos += 2;
    devices.add(rec);
}
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
  ]);

  // Send the request (opcode 0x2C)
  port.write(buildRequest(123456789012, 0x2C, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('TWI Read failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const deviceCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const devices = [];
  for (let i = 0; i < deviceCount; i++) {
      const rec = {};
      rec['DeviceAddress'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['TypeCode'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['Value1'] = beInt(rspBody, pos, 2);
      pos += 2;
      rec['Value2'] = beUInt(rspBody, pos, 2);
      pos += 2;
      rec['Value3'] = beUInt(rspBody, pos, 2);
      pos += 2;
      devices.push(rec);
  }
})();

TWI Read

Reads the devices on a TWI/I2C bus. For TypeCode 1 (MCP9808), Value1 is the temperature in hundredths of a degree Celsius, signed. For TypeCode 2 (INA219), Value1 is the voltage in mV, signed, Value2 is the power in mW, and Value3 is the current in mA.

Opcode: 0x2C. Body length: 1.

Request body

Field Bytes Description
BusIndex 1 TWI/I2C bus index.

Response body

Field Bytes Description
DeviceCount 1 Number of devices read.
Devices[] 8 One entry per device. Repeated DeviceCount times. Each entry is 8 bytes.
Devices[].DeviceAddress 1 7-bit TWI/I2C address.
Devices[].TypeCode 1 0x00 unknown, 0x01 MCP9808 temperature, 0x02 INA219 current and power.
Devices[].Value1 2 MCP9808: temperature in hundredths of a degree C, signed. INA219: voltage in mV, signed.
Devices[].Value2 2 INA219: power in mW, unsigned. 0 for MCP9808.
Devices[].Value3 2 INA219: current in mA, unsigned. 0 for MCP9808.

Example: TWI Set Name

# TWI Set Name to serial number 123456789012 (opcode 0x2D)
printf '\x43\x1c\xbe\x99\x1a\x14\x2d\x0d\x00\x18\x52\x6f\x6f\x6d\x00\x00\x00\x00\x00\x00\x00\xb4\xde' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Build the request body. Each field is big-endian, in the order of the table
req_body = [
  be(0, 1),
  be(24, 1),
  padded('Room', 11),
].join

# Send the request (opcode 0x2D)
port.write(build_request(123456789012, 0x2D, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('TWI Set Name failed: 0x%02X', rc) unless rc == 0x00
# Build the request body. Each field is big-endian, in the order of the table
req_body = b''.join([
    be(0, 1),
    be(24, 1),
    padded('Room', 11),
])

# Send the request (opcode 0x2D)
port.write(build_request(123456789012, 0x2D, req_body))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'TWI Set Name failed: {rc:#04x}')
// Build the request body. Each field is big-endian, in the order of the table
$req_body = implode('', [
    be(0, 1),
    be(24, 1),
    padded('Room', 11),
]);

// Send the request (opcode 0x2D)
dio_write($port, build_request(123456789012, 0x2D, $req_body));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('TWI Set Name failed: 0x%02X', $rc));
}
# Build the request body. Each field is big-endian, in the order of the table
my $req_body = join '', (
  be(0, 1),
  be(24, 1),
  padded('Room', 11),
);

# Send the request (opcode 0x2D)
$port->write(build_request(123456789012, 0x2D, $req_body));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("TWI Set Name failed: 0x%02X\n", $rc) unless $rc == 0x00;
// Build the request body. Each field is big-endian, in the order of the table
var reqBody = concat(
    be(0, 1),
    be(24, 1),
    padded("Room", 11)
);

// Send the request (opcode 0x2D)
port.writeBytes(buildRequest(123456789012L, 0x2D, reqBody));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("TWI Set Name failed: 0x%02X", rc));
}
(async () => {
  // Build the request body. Each field is big-endian, in the order of the table
  const reqBody = Buffer.concat([
    be(0, 1),
    be(24, 1),
    padded('Room', 11),
  ]);

  // Send the request (opcode 0x2D)
  port.write(buildRequest(123456789012, 0x2D, reqBody));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('TWI Set Name failed: 0x' + rc.toString(16));
})();

TWI Set Name

Sets a name for a TWI/I2C device. Run TWI Scan first, so the bus and address pair is known. The name stays with the device if it is moved to another bus. If the first byte of the name is 0, the name is deleted.

Opcode: 0x2D. Body length: 13.

Request body

Field Bytes Description
BusIndex 1 TWI/I2C bus index.
DeviceAddress 1 7-bit address from TWI Scan.
NameString 11 Name, up to 10 characters.

Response body: status only.

  • Returns RC_CMD_PARAM_ERR if the bus and address pair is not known.

Example: TWI Get Names

# TWI Get Names to serial number 123456789012 (opcode 0x2E)
printf '\x43\x1c\xbe\x99\x1a\x14\x2e\x00\x84\x51' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x2E, no body)
port.write(build_request(123456789012, 0x2E))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('TWI Get Names failed: 0x%02X', rc) unless rc == 0x00

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
device_count.times do
  rec = {}
  rec['BusIndex'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['DeviceAddress'] = be_uint(rsp_body, pos, 1)
  pos += 1
  rec['AssociatedName'] = be_str(rsp_body, pos, 11)
  pos += 11
  devices << rec
end
# Send the request (opcode 0x2E, no body)
port.write(build_request(123456789012, 0x2E))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'TWI Get Names failed: {rc:#04x}')

# Decode the response body, field by field. Move pos forward by each field's size
pos = 0
device_count = be_uint(rsp_body, pos, 1)
pos += 1
devices = []
for _ in range(device_count):
    rec = {}
    rec['BusIndex'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['DeviceAddress'] = be_uint(rsp_body, pos, 1)
    pos += 1
    rec['AssociatedName'] = be_str(rsp_body, pos, 11)
    pos += 11
    devices.append(rec)
// Send the request (opcode 0x2E, no body)
dio_write($port, build_request(123456789012, 0x2E));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('TWI Get Names failed: 0x%02X', $rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
$pos = 0;
$device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
$devices = [];
for ($i = 0; $i < $device_count; $i++) {
    $rec = [];
    $rec['BusIndex'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['DeviceAddress'] = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec['AssociatedName'] = be_str($rsp_body, $pos, 11);
    $pos += 11;
    $devices[] = $rec;
}
# Send the request (opcode 0x2E, no body)
$port->write(build_request(123456789012, 0x2E));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("TWI Get Names failed: 0x%02X\n", $rc) unless $rc == 0x00;

# Decode the response body, field by field. Move pos forward by each field's size
my $pos = 0;
my $device_count = be_uint($rsp_body, $pos, 1);
$pos += 1;
my @devices;
for (1 .. $device_count) {
    my %rec;
    $rec{'BusIndex'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'DeviceAddress'} = be_uint($rsp_body, $pos, 1);
    $pos += 1;
    $rec{'AssociatedName'} = be_str($rsp_body, $pos, 11);
    $pos += 11;
    push @devices, \%rec;
}
// Send the request (opcode 0x2E, no body)
port.writeBytes(buildRequest(123456789012L, 0x2E));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("TWI Get Names failed: 0x%02X", rc));
}

// Decode the response body, field by field. Move pos forward by each field's size
int pos = 0;
var deviceCount = beUInt(rspBody, pos, 1);
pos += 1;
var devices = new ArrayList<Map<String, Object>>();
for (int i = 0; i < deviceCount; i++) {
    var rec = new HashMap<String, Object>();
    rec.put("BusIndex", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("DeviceAddress", beUInt(rspBody, pos, 1));
    pos += 1;
    rec.put("AssociatedName", beStr(rspBody, pos, 11));
    pos += 11;
    devices.add(rec);
}
(async () => {
  // Send the request (opcode 0x2E, no body)
  port.write(buildRequest(123456789012, 0x2E));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('TWI Get Names failed: 0x' + rc.toString(16));

  // Decode the response body, field by field. Move pos forward by each field's size
  let pos = 0;
  const deviceCount = beUInt(rspBody, pos, 1);
  pos += 1;
  const devices = [];
  for (let i = 0; i < deviceCount; i++) {
      const rec = {};
      rec['BusIndex'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['DeviceAddress'] = beUInt(rspBody, pos, 1);
      pos += 1;
      rec['AssociatedName'] = beStr(rspBody, pos, 11);
      pos += 11;
      devices.push(rec);
  }
})();

TWI Get Names

Returns the bus, address, and name for each TWI/I2C device that has a name.

Opcode: 0x2E. Body length: 0.

Request body: none.

Response body

Field Bytes Description
DeviceCount 1 Number of devices.
Devices[] 13 One entry per device. Repeated DeviceCount times. Each entry is 13 bytes.
Devices[].BusIndex 1 TWI/I2C bus index.
Devices[].DeviceAddress 1 7-bit TWI/I2C address.
Devices[].AssociatedName 11 Name for this entry. Defaults to the family or device type name.

Example: TWI Reset Names

# TWI Reset Names to serial number 123456789012 (opcode 0x2F)
printf '\x43\x1c\xbe\x99\x1a\x14\x2f\x00\x85\xc1' > /dev/ttyUSB0
# Read the response. Press Ctrl-C to stop
timeout 1 cat /dev/ttyUSB0 | xxd
# Send the request (opcode 0x2F, no body)
port.write(build_request(123456789012, 0x2F))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp[:body]
rc = rsp[:rc]

# Check the status byte. 0x00 means the command ran
raise format('TWI Reset Names failed: 0x%02X', rc) unless rc == 0x00
# Send the request (opcode 0x2F, no body)
port.write(build_request(123456789012, 0x2F))

# Read the response. The helper checks the CRC of the response
rsp = read_response(port)
rsp_body = rsp['body']
rc = rsp['rc']

# Check the status byte. 0x00 means the command ran
if rc != 0x00:
    raise IOError(f'TWI Reset Names failed: {rc:#04x}')
// Send the request (opcode 0x2F, no body)
dio_write($port, build_request(123456789012, 0x2F));

// Read the response. The helper checks the CRC of the response
$rsp = read_response($port);
$rsp_body = $rsp['body'];
$rc = $rsp['rc'];

// Check the status byte. 0x00 means the command ran
if ($rc !== 0x00) {
    throw new RuntimeException(sprintf('TWI Reset Names failed: 0x%02X', $rc));
}
# Send the request (opcode 0x2F, no body)
$port->write(build_request(123456789012, 0x2F));

# Read the response. The helper checks the CRC of the response
my $rsp = read_response($port);
my $rsp_body = $rsp->{body};
my $rc = $rsp->{rc};

# Check the status byte. 0x00 means the command ran
die sprintf("TWI Reset Names failed: 0x%02X\n", $rc) unless $rc == 0x00;
// Send the request (opcode 0x2F, no body)
port.writeBytes(buildRequest(123456789012L, 0x2F));

// Read the response. The helper checks the CRC of the response
var frame = readResponse(port);
var rspBody = Arrays.copyOfRange(frame, 8, frame.length - 2);
var rc = frame[6] & 0xFF;

// Check the status byte. 0x00 means the command ran
if (rc != 0x00) {
    throw new IOException(String.format("TWI Reset Names failed: 0x%02X", rc));
}
(async () => {
  // Send the request (opcode 0x2F, no body)
  port.write(buildRequest(123456789012, 0x2F));

  // Read the response. The helper checks the CRC of the response
  const frame = await readResponse(port);
  const rspBody = frame.subarray(8, frame.length - 2);
  const rc = frame[6];

  // Check the status byte. 0x00 means the command ran
  if (rc !== 0x00) throw new Error('TWI Reset Names failed: 0x' + rc.toString(16));
})();

TWI Reset Names

Clears all names set with TWI Set Name and restores the default names.

Opcode: 0x2F. Body length: 0.

Request body: none.

Response body: status only.

Widget Documentation

Click here to go to Widget Documentation

Jump to: Required Parameters | Realtime Parameters | History Graph Parameters | Setting Parameters

Access free web-based real-time and historical graphs showcasing your EKM Push data, covering all your devices including meters and ioStacks. It’s quick, easy, and doesn’t require a login.

The EKM Widget offers a convenient means to gain visual insights into your systems’ performance. We utilize it to monitor our office’s current consumption and solar power generation in real-time. Additionally, the historical chart helps us track the impact of efficiency upgrades on our usage and monitor the energy consumption of our electric car over time.

Status Codes

EKM uses conventional HTTP response codes in addition to our API Status Codes to indicate the success or failure of an API request. In general, codes in the 2xx range indicate success, codes in the 4xx range indicate an error that failed given the information provided, and codes in the 5xx range indicate an error with EKM’s servers (these are rare).

The EKM API uses the following API specific Status codes:

API Status Code Meaning
1000 There is not data for: {meters}
1001 There is not data for: {meters} between ${startDate} and ${endDate}
1002 There is not data for: {meters} This meter first reported on:
1003 There is not data for: {meters} This meter last reported on:
1004 Timezone is not supported for this date range request
1100 All invalid query requests
1101 Invalid format
1102 Invalid value
1103 Invalid parameter
1200 Found invalid meter: {meter} for key: MTAxMDoyMDIw
1300 Oops! It looks like there was an unexpected error. Try checking your query for issues or hold tight while we see what we can do. This error has been reported.

The EKM API also uses the following HTTP Status codes:

HTTP Status Code Meaning
200 OK – The request succeeded.
400 Bad Request – The server could not understand the request due to invalid syntax.
401 Unauthorized – Although the HTTP standard specifies “unauthorized”, semantically this response means “unauthenticated”. That is, the client must authenticate itself to get the requested response.
403 Forbidden – The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client’s identity is known to the server.
404 Not Found – The server can not find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist. Servers may also send this response instead of 403 Forbidden to hide the existence of a resource from an unauthorized client. This response code is probably the most well known due to its frequent occurrence on the web.
429 Too Many Requests – The user has sent too many requests in a given amount of time (“rate limiting”).
500 Internal Server Error – The server has encountered a situation it does not know how to handle.
501 Not Implemented – The Vertical Bar otherwise known as “pipe” request method is not supported by the server and cannot be handled. The only methods that servers are required to support (and therefore that must not return this code) are GET and HEAD.
502 Bad Gateway – This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response.
503 Service Unavailable – The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded. Note that together with this response, a user-friendly page explaining the problem should be sent. This response should be used for temporary conditions and the Retry-After HTTP header should, if possible, contain the estimated time before the recovery of the service. The webmaster must also take care about the caching-related headers that are sent along with this response, as these temporary condition responses should usually not be cached.
504 Gateway Timeout – This error response is given when the server is acting as a gateway and cannot get a response in time.
505 HTTP Version Not Supported – The HTTP version used in the request is not supported by the server.
506 Variant Also Negotiates – The server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process.
510 Not Extended – Further extensions to the request are required for the server to fulfill it.
511 Network Authentication Required – Indicates that the client needs to authenticate to gain network access.