Pre-release SerialFlow 0.9.0 beta 2 works, but has rough edges. Tell us what you find.

Example · MDX-400 motor-drive bench · Wire

Catching broken frames on a noisy link

One CRC byte per line. Every broken frame listed, none of them drawn.

  • CRC-8, polynomial 0x07
  • A 10-line C function, no library
  • 23 rejects, sorted by category
  • Nothing to switch on

The MDX-400 is a simulated motor drive. A script printed the serial lines its firmware would send, and SerialFlow read them exactly as if they came from a COM port. Your own board works the same way.

The MDX-400 speed loop prints one graph line per 10 ms sample. On a long bench cable, one flipped bit turns a setpoint of 3000 rpm into 7000, and the graph shows a speed spike that never happened. So in this scene every speed frame carried a CRC-8, and a script added 23 single faults to the feed. SerialFlow had to keep every broken line off the graph and say what was wrong with each one.

What the firmware prints

Graph A (Speed Control) gets one line per sample with the CRC on the end. Graph B (Thermal & Battery) is a slow channel and sends its lines without one. Copied from showcase_rx_errors.txt:

~{A:1:3000:3004.9}*7E
~{A:1:3000:3004.1}*D6
~{A:1:3000:3004.0}*C3
~{B:0:40.1332:33.86:25.07:47.62:53.17}
PartMeaning
~{ … }One graph command
A, BThe graph id: A is Speed Control, B is Thermal & Battery
1Add data, with an X that counts up by one per line
0Add data with its own X value, here 40.1332 minutes
3000:3004.9The values in signal order: setpoint 3000 rpm, speed 3004.9 rpm
33.86:25.07:47.62:53.17Motor winding °C, MOSFET °C, pack voltage V, state of charge %
*7EThe optional CRC-8 of the line, as two uppercase hex digits

The CRC-8 check

SerialFlow checks the CRC on every graph line that ends in * and two hex digits. The rules:

  • Polynomial 0x07 (x⁸ + x² + x + 1), start value 0.
  • It covers every character from { to }, both braces included. The ~ and the *7E are not part of it.
  • The result is one byte, sent as two uppercase hex digits after *.
  • If the CRC does not match, the line is dropped: it never reaches the graph, and the RX Error Collector lists it.

For ~{A:1:3000:3004.9}*7E, the CRC runs over the 17 characters {A:1:3000:3004.9} and gives 0x7E. The checksum calculator uses the same CRC-8, so you can check any line by hand:

CRC calculator panel with the algorithm CRC-8, the input {A:1:2200:2187} and the result 0x7F, 127, 01111111.
CRC-8 of {A:1:2200:2187} is 0x7F, so the line goes out as ~{A:1:2200:2187}*7F.

What the noise did

One real line of each kind of fault:

Line as receivedWhat happenedError ReasonCategory
~{A:1:7000:3003.1}*B4One bit flipped: setpoint 3000 became 7000CRC mismatch (expected 0xB4, got 0xC7)CRC
~{A:1:3000:300Line cut off before the }Missing closing braceStructure
~{b:0:40.9324:33.00:…}B (0x42) became b (0x62)Invalid graph ID 'b' (not A-Z)Command
~{B:p:40.0999:33.88:…}0 (0x30) became p (0x70)Unknown command code 'p'Command
~{B:0z40.2997:33.80:…}: (0x3A) became z (0x7A)Format error: no colon after command codeFormat

Expected is the CRC that came with the line; got is the CRC computed from what arrived. The graph B faults were caught only because they broke the line’s structure. A flipped digit in a graph B value would reach the graph unchecked.

Set it up in SerialFlow

  1. Connect to the port as usual. There is nothing to switch on: SerialFlow checks every graph line that carries a CRC.
  2. Watch the status bar. Err: counts the rejected graph lines and turns red when it is above 0.
  3. ☰ → Tools → RX Error Collector… It has been collecting since SerialFlow started, so earlier errors are already in the list.
  4. Read the summary bar: Total, CRC, Structure, Command, Format and Other. Mostly CRC: bits change on the wire. Mostly Structure: lines are cut short.
  5. Copy All puts the list on the clipboard as tab-separated text, for a bug report or a spreadsheet. Clear empties the list and resets the counters.
  6. ☰ → View → CRC Calculator checks a single line by hand: pick CRC-8 and paste the line from { to }.
  7. ☰ → Tools → Port Details… shows which adapter and driver sit on which COM port.

The result

The RX Error Collector

RX Error Collector window: a summary bar with Total 23, CRC 13, Structure 7, Command 2, Format 1, Other 0, above a table of rejected lines with their category, reason and raw text.
The noisy-link feed: 23 rejected lines, sorted into CRC 13, Structure 7, Command 2 and Format 1.

The collector held 23 rejects, exactly the faults in the file: 13 CRC, 7 Structure, 2 Command, 1 Format, 0 Other. Of the 481 lines that arrived with a CRC, 468 matched. Each row gives the time, graph, category, reason and raw text; the Graph column shows ? when the graph letter itself was broken. No dropped line reached the Speed Control graph, so there was no false 7000 rpm spike to explain away.

Checksum calculator and Port Details

Port Details window, Port Detail tab, for COM4: STMicroelectronics STLink Virtual COM Port, USB Serial, VID:PID 0483:3754, driver version 2.2.0.
Port Details: VID:PID, manufacturer and driver of the adapter on each COM port.

The CRC Calculator takes text, or raw bytes with Hex Input, and shows Hex, Dec and Bin while you type. It has 12 algorithms: CRC-8, CRC-16-CCITT, CRC-16-Modbus, CRC-16-XMODEM, CRC-32, LRC, XOR, Sum8, Sum16, MD5, SHA-1 and SHA-256. Port Details shows which adapter sits on which COM port; in the picture, an STMicroelectronics ST-Link virtual COM port on COM4 with VID:PID 0483:3754 and driver 2.2.0.

In your own firmware

The same lines from your own firmware need one short function and no library:

#include <stdio.h>
#include <stdint.h>

/* CRC-8, polynomial 0x07, start value 0, over "{" ... "}" */
uint8_t sf_crc8(const char *s, int len)
{
    uint8_t crc = 0;
    while (len--) {
        crc ^= (uint8_t)*s++;
        for (int i = 0; i < 8; i++)
            crc = (crc & 0x80) ? (uint8_t)((crc << 1) ^ 0x07) : (uint8_t)(crc << 1);
    }
    return crc;
}

/* One sample of graph A (setpoint, speed), protected by CRC-8 */
void send_speed(int setpoint_rpm, float speed_rpm)
{
    char frame[40];
    int n = snprintf(frame, sizeof frame, "{A:1:%d:%.1f}", setpoint_rpm, speed_rpm);
    printf("~%s*%02X\n", frame, sf_crc8(frame, n));
}
/* send_speed(3000, 3004.9f) prints ~{A:1:3000:3004.9}*7E */

Compiled with gcc, this function gives the same CRC as all 468 good lines in showcase_rx_errors.txt. The CRC works on any graph command, not only data lines: the reference’s own example is ~{A:I:Sensors:500:S:T:F:Sample::0}*C1.

Good to know

  • The CRC is optional, per line. A line without *XX is accepted unchecked, so protect the lines that matter.
  • One command per line. SerialFlow reads only the first ~{…} on a line. Put the CRC straight after the }.
  • The collector is always on, from the moment SerialFlow starts, window open or not. It keeps the newest 200 rows by default; the counters keep counting.
  • CRC errors point at the link. Check the cable, or lower the baud rate. The Statistics pane counts them too: CRC Rejects, under RX HEALTH, which shows once something has been lost.
  • Packed binary mode ends every frame with a CRC-8 too, with the same polynomial.
  • Port Details has four tabs: All Ports, Port Detail, FTDI Devices and System Info. Auto-Refresh rescans the ports every 5 seconds. On FTDI Devices, Connect by Serial # connects to the selected adapter, and from then on SerialFlow finds it by its serial number, whatever COM number Windows gives it.

Try it yourself

  1. Start SerialFlow. You don’t need to connect a port.
  2. ☰ → Test → Load Test File → Demo → showcase_preload.txt. Graphs A to D appear.
  3. ☰ → Test → Delayed Playback → Demo → showcase_rx_errors.txt. Err: in the status bar climbs to 23.
  4. ☰ → Tools → RX Error Collector… shows Total 23: CRC 13, Structure 7, Command 2, Format 1.
  5. ☰ → View → CRC Calculator, pick CRC-8 and type {A:1:3000:3004.9}. The result is 0x7E, the CRC on the first good line. Now type {A:1:7000:3003.1}: it gives 0xC7, not the 0xB4 that the line carried.
  6. ☰ → Tools → Port Details… lists the COM ports on your own PC.