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

Example · MDX-400 motor-drive bench · Automation

Command buttons, macros and auto-replies

One click: fault clear, wait 200 ms, status. Six rules answer the drive on their own.

  • 7 buttons, 2 with delay: steps
  • Macros: Send, Delay, WaitFor
  • Auto-reply by text, hex or regex
  • Rules import from one JSON file

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.

On the MDX-400 bench the same few commands go out all day: run 1500, stop, fault clear, status. The drive also asks the PC for things: a watchdog ping every 5 s, and a BMS? query when the pack wants a charge window. We put the commands on seven Quick Send buttons and four macros, and let six auto-reply rules answer the drive.

What the firmware prints

These lines come from the 60-second bench-run log behind the auto-reply picture. A rule or a macro reacts to each one:

[   6.233] [INFO] WDT ping #01 · host timeout 6 s
[   7.431] [ OK ] speed 1500 rpm reached · 7.4 A · 52.4 V
[  10.231] [BATT] BMS? charge window request · SoC 95 % · cell spread 10 mV
[  25.531] [TRIP] Overcurrent phase B 42.3 A > 40.0 A · PWM off · auto-restart in 200 ms
[  25.741] [ OK ] Fault cleared · restart OK · 1 trip in this session
[  33.031] [WARN] MOSFET 78.4 °C ≥ 78 °C · derate → 2 600 rpm
[  53.231] [BATT] Regenerative braking · +1.8 A into pack · Vbus 53.1 V
The line containsWho reactsTimes in the 60 s log
WDT pingrule Watchdog12
BMS?rule BMS query (hex)3
Overcurrent phase B or Crule Trip log (regex)2
restart OKrule Restart2
MOSFET 78.4 °C ≥ 78 °Crule Derate fan (regex)1
speed 1500 rpm, speed 3000 rpm, into packthe WaitFor steps of the macros1 each

The drive takes short text commands, one per line. This is everything the buttons, macros and rules send:

CommandWhat it doesSent by
drive enableenables the gate driverSTART
run 1500, run 2200, run 3000speed setpoint in rpmSTART, the RPM buttons, macros
stopramps down and switches PWM offSTOP, macros
fault clearclears a latched faultFAULT RESET
statusone-line drive statusSTATUS, FAULT RESET, Thermal soak, rule Restart
load 150, load 100load step, in %Hill climb
brake regenregenerative brakingRegen check
WDT ack, byte 06, log dump 200, fan 100answers to the lines abovethe rules

Set it up in SerialFlow

Quick Send buttons

  1. ☰ → View → Quick Send Buttons. Right-click an empty spot in the panel → Add Button, or click +.
  2. Right-click the new button → Edit… to open Edit Quick Send Button.
  3. Type the Label, a Tooltip and the Data. Each line of Data goes out as one command. A line delay:200 waits 200 ms before the next one; + Delay inserts delay:100 at the cursor.
  4. Set Line Ending to CRLF, pick a Text Color and a BG Color, tick Bold if you want it, then Close.

These are the seven MDX-400 buttons:

ButtonSends, one line eachBackground
STARTdrive enable, delay:50, run 1500#2E7D32 green
STOPstop#C62828 red
RPM 1500, RPM 2200, RPM 3000run 1500, run 2200, run 3000#1565C0 blue
FAULT RESETfault clear, delay:200, status#FF8F00 amber, text #1A1A1A
STATUSstatus#37474F grey

All seven end each line with CRLF, echo what they send into the log and use font size 12. START, STOP and FAULT RESET are bold.

Edit Quick Send Button dialog for FAULT RESET: three data lines, amber background, bold label.
FAULT RESET: three lines, with a 200 ms pause before status.

Macros

A macro runs a longer sequence, and can wait for the drive’s answer before it goes on.

  1. ☰ → View → Macros, then Add. Select the new macro and click Edit.
  2. In Edit Macro, fill in Name, Description, Shortcut and Repeat. Leave Line ending on Use TX setting to use the terminal’s TX line ending (CRLF in the bench profile).
  3. Add one step per row in the grid: Type (Send, Delay or WaitFor), Data, Delay / Timeout (ms) and Hex. Click OK.
  4. Select the macro and click Run. Stop cancels it.
MacroShortcutStepsRepeat
Bench cycleCtrl+F5Send run 1500 → WaitFor speed 1500 rpm → Delay 5000 → Send run 3000 → WaitFor speed 3000 rpm → Delay 10000 → Send stop → WaitFor PWM off1
Hill climbCtrl+F6Send run 3000 → WaitFor speed 3000 rpm → Send load 150 → Delay 8000 → Send load 1001
Thermal soakCtrl+F7Send status → Delay 6000030
Regen checkCtrl+F8Send run 3000 → WaitFor speed 3000 rpm → Send brake regen → WaitFor into pack → Send stop1

SerialFlow keeps macros in the profile as JSON. This is Thermal soak as stored; step type 0 is Send, 1 is Delay and 2 is WaitFor:

{
  "id": "00000000-0000-0000-0000-000000004103",
  "name": "Thermal soak",
  "description": "Status every 60 s for 30 min at 3 000 rpm",
  "keyboardShortcut": "Ctrl+F7",
  "steps": [
    { "type": 0, "data": "status", "delayMs": 0, "isHex": false },
    { "type": 1, "data": "", "delayMs": 60000, "isHex": false }
  ],
  "repeatCount": 30,
  "isEnabled": true
}

Export in the Macros panel saves every macro to a JSON file in this format, and Import adds the macros from such a file (a macro with the same id is replaced). Macros also travel inside an exported profile: see Customise.

Auto-reply rules

  1. ☰ → View → Auto-Reply and tick Enable Auto-Reply. No rule runs without it.
  2. Click Add to open the rule editor (Edit, or a double-click, opens it for an existing rule). Fill in Name, the Match text and its Type (PlainText, Regex or Hex), Case sensitive, the Reply (tick Hex to send bytes), its Line ending, a Delay before reply (ms) and One-shot. OK checks the rule first: a regex must compile, and hex is pairs of hex digits.
  3. Up and Dn set the order. Export saves the list as a JSON file, and Import replaces the list with the rules in such a file.

Three of the six rules, one per match type:

NameTypePatternResponseDelayOne-shot
WatchdogPlainTextWDT pingWDT ack0 msno
BMS queryHex42 4D 53 3F06, sent as hex0 msno
Trip logRegexOvercurrent phase [ABC]log dump 20050 msno

A hex pattern matches bytes in the received line: 42 4D 53 3F is BMS? in ASCII, and the response 06 goes out as the ACK byte. The other three rules are Restart (restart OK → status), Derate fan (regex MOSFET \d+\.\d °C ≥ \d+ °C → fan 100) and Low SoC (regex SoC ([0-9]|1[0-9]) % → run 0, switched off). All six ignore case.

To try two of the real rules, copy this into Notepad, save it as mdx400_rules.json and Import it:

[
  {
    "id": "00000000-0000-0000-0000-000000004202",
    "name": "Trip log",
    "pattern": "Overcurrent phase [ABC]",
    "patternType": "Regex",
    "response": "log dump 200",
    "responseIsHex": false,
    "delayMs": 50,
    "isEnabled": true,
    "isOneShot": false,
    "caseSensitive": false
  },
  {
    "id": "00000000-0000-0000-0000-000000004203",
    "name": "Restart",
    "pattern": "restart OK",
    "patternType": "PlainText",
    "response": "status",
    "responseIsHex": false,
    "delayMs": 0,
    "isEnabled": true,
    "isOneShot": false,
    "caseSensitive": false
  }
]

The result

Row of coloured buttons: START, STOP, RPM 1500, RPM 2200, RPM 3000, FAULT RESET, STATUS.
The seven buttons. Each shows its tooltip when you point at it.
SerialFlow window with the motor-drive log on top, seven coloured command buttons and a list of four macros with keyboard shortcuts below.
The compact window: the log on top, the buttons and the four macros docked under it.
SerialFlow log of a bench run with the Auto-Reply panel floating over it: six rules with match counts 12, 3, 2, 2, 1 and 0.
The six rules over the 60 s log. Matches counts the lines each rule caught; Low SoC is switched off.

In your own firmware

The buttons send each command as a text line ending in CR LF, and so does auto-reply: its text replies end with the TX line ending, CRLF in the bench profile. Beta 1 sent auto-replies with no line ending. This receive handler copes with both, and prints the ping that the Watchdog rule answers:

#include <stdio.h>
#include <string.h>
static char line[64];
static int  len, pings;

void every_5_s(void)                 /* the Watchdog rule answers this line */
{
    printf("[%8.3f] [INFO] WDT ping #%02d · host timeout 6 s\n", now_s(), ++pings);
}

void on_rx_byte(char c)              /* call for every received byte */
{
    if (c != '\r' && c != '\n') {    /* beta 1 sent auto-replies without one */
        if (len < (int)sizeof line - 1) { line[len++] = c; line[len] = '\0'; }
        if (strcmp(line, "WDT ack") == 0) { host_alive(); len = 0; }
        return;
    }
    if (len == 0) return;            /* the LF of CR LF */
    int rpm;
    if (sscanf(line, "run %d", &rpm) == 1)     set_speed(rpm);
    else if (strcmp(line, "stop") == 0)        ramp_down();
    else if (strcmp(line, "fault clear") == 0) clear_fault();
    else if (strcmp(line, "status") == 0)      print_status();
    len = 0;
}

Good to know

  • Line endings. A button uses its own Line Ending and a macro its Line ending setting. An auto-reply rule adds its Line ending to a text reply: Use TX setting at first, or None, CR, LF or CRLF. A hex reply goes out exactly as typed. Beta 1 sent every auto-reply with no line ending; a rule from then now gets the TX line ending, so set it to None if your firmware expects nothing after the reply.
  • Rule order. Each received line is checked from the top of the list down (Up and Dn move a rule), and every rule that matches replies, in that order. There is no priority: a priority in an older rule file is ignored. Import replaces the whole list.
  • Whole lines. A line is checked when its line end arrives, so a line that reaches the PC in two pieces is matched whole. A prompt without a line end, such as Password: , is checked once nothing has arrived for 200 ms.
  • WaitFor waits for a received line that contains its Data: plain text, case-sensitive, no regex, and only in the main terminal, not in status windows. The Delay / Timeout (ms) column is the timeout; 0 means 5 s. On a timeout the macro stops and the status bar says why, for example Macro failed: WaitFor step 2: no received line contained "speed 1500 rpm" within 5000 ms.
  • Shortcuts. Press a macro’s Shortcut to run it on the active port, also while you type in the Transmit box. The editor takes F1 to F24 with or without Ctrl, Shift and Alt, or Ctrl or Alt with a letter or digit (Shift optional). It refuses Ctrl and Alt together, Ctrl+A, C, V, X, Y and Z, Alt+F4, Ctrl+F4, the app’s own shortcuts and a shortcut that another macro has. Holding the keys down does not repeat the macro.
  • Matches counts as the lines arrive. A reply that could not go out, for example with no port open, is counted too, as 2 (2 failed); point at the number for the reason.

Try it yourself

  1. Save the two rules above as mdx400_rules.json.
  2. ☰ → View → Auto-Reply, click Import and pick the file. Trip log and Restart appear. Tick Enable Auto-Reply.
  3. ☰ → Test → Load Test File → Demo → showcase_preload.txt. The log holds one overcurrent trip and its restart.
  4. ☰ → Test → Delayed Playback → Demo → showcase_live.txt. About a minute in, a second trip and its restart scroll by, and Matches goes up by one for both rules as they arrive.
  5. With no port connected the replies can’t go out, so Matches shows them as failed, for example 1 (1 failed). On a connected port the reply is sent.
  6. Build FAULT RESET from the button table and check it in the editor’s Preview. It sends once a port is connected.