Communications#

Instruments talk to the computer in messages, over a link, using a protocol both ends agree on. The link decides how fast values arrive and where they’re timestamped.

Layers#

Every link has three layers, and problems can live in any of them:

  • The physical layer is the wires and the voltages on them: how many wires, how long they can be, and how a bit is signaled.

  • The protocol layer is how bits become messages: how a message starts and ends, how a device is addressed, and how errors are detected.

  • The application layer is what the messages mean: which message sets a speed, and which one reads a temperature.

On an e-axle dyno, for example, where a motor drives the e-axle under test and a load motor on each side brakes it, the power supply uses USB as its physical layer and SCPI as its application layer. The three motor controllers use CAN for both the physical and protocol layers, and each controller’s own set of messages for the application layer.

CAN#

A CAN bus connects the controllers in a vehicle or machine over one twisted pair. Every node can send, and every node hears every message.[2]

  • Arbitration. When two nodes start sending at once, the bus settles it bit by bit, by each message’s identifier. The identifier with the lower binary value has the higher priority, and wins.[2]

  • Identifiers. A classic CAN frame has an 11-bit message identifier, or a 29-bit extended one.[2]

  • Data. A classic frame carries 0 to 8 bytes of data.[2] CAN FD carries up to 64 bytes, and can switch to a faster bit rate for the data part of each frame.[3]

  • Speed and length. Classic CAN runs at up to 1 Mbit/s on a bus 40 m long, with up to 30 nodes. The bus is terminated at both ends with 120 Ω resistors.[2]

Classic CAN and CAN FD are both standardized in ISO 11898-1:2024.[3]

Example: the dyno’s CAN bus#

The dyno’s three motor controllers share one CAN bus, with node IDs 0, 1 and 2. The control software sends each controller a command about 16 times a second, and each controller reports its current, speed and temperature back.

If two controllers start a frame at the same moment, the frame with the lower message identifier wins arbitration and goes first. The other controller waits, and sends once the bus is free. Neither frame is lost.

Instrument control: SCPI and VISA#

SCPI, Standard Commands for Programmable Instruments, is a text command language for test instruments. It builds on IEEE 488.2, which set out how to send commands to instruments and responses back to a controller.[4]

SCPI commands are readable words in a tree, such as MEASure:VOLTage?. Each keyword has a long form and a short form, and the uppercase letters are the short form, so MEAS:VOLT? means the same.[4] A command that ends in ? is a query, and the instrument answers it.

This exchange sets a power supply to 48 V, turns its output on, and reads back the voltage and the error queue. Exact commands vary by instrument, so check its programming manual:

→ *IDN?
← <manufacturer>,<model>,<serial number>,<firmware version>
→ VOLT 48
→ OUTP ON
→ MEAS:VOLT?
← 47.98
→ SYST:ERR?
← 0,"No error"

*IDN? is a common command from IEEE 488.2, and its answer has four comma-separated fields.[4] SYST:ERR? reads the instrument’s error queue, one error at a time. The dyno’s software has a routine that clears errors left behind by a session that didn’t close cleanly: it sends SYST:ERR? until the answer starts with 0.

SCPI runs over many physical links, including GPIB, USB, Ethernet and serial. VISA is a standard software library that gives a program the same interface to an instrument whichever link it uses. The IVI Foundation maintains the VISA and SCPI standards, along with specifications for instruments on USB and on Ethernet.[5]

Modbus#

Modbus is a request-and-reply protocol: a client sends a request with a function code, and a server answers. It runs over TCP/IP on Ethernet, on port 502, or over serial links such as RS-232 and RS-485.[6]

A Modbus server presents its data as four tables:[6]

Table

Size of each item

Access

Discrete inputs

1 bit

Read only

Coils

1 bit

Read and write

Input registers

16 bits

Read only

Holding registers

16 bits

Read and write

To read a value, the client asks for a range of registers by function code, such as 03, Read Holding Registers. A 16-bit register can’t hold a 32-bit value, so a device spreads it over two registers. The device’s manual says which register holds which half.

Industrial Ethernet: EtherCAT and OPC UA#

EtherCAT is an industrial Ethernet standard, part of IEC 61158, for fast, tightly timed control. Each device reads the data addressed to it as the frame passes through. This allows cycle times of 100 µs or less, and clock jitter well under 1 µs. One segment can hold up to 65,535 devices.[7]

OPC UA is a platform-independent standard for exchanging data between industrial systems. It models data with its meaning, such as units and relationships, and supports both client-server requests and publish-subscribe for many-to-many data.[8]

Further reading#

References#