Offline Batch Execution

Batch execution stores a group of CAN, CAN FD, or RS485 commands on the board and runs them in sequence. A task can continue after the PC is disconnected, making it useful for factory initialization, cycle tests, and fixed motion sequences.

Batch tasks send control commands directly to external devices. For the first test, remove the load, reduce speed and current limits, and prepare an emergency stop or power disconnect.

Basic Rules

  • Send all commands through USB serial with a CRLF line ending.

  • Batch IDs are 1 to 99. Names are 1 to 16 characters and may contain letters, digits, _, and -.

  • Item indexes start at 1 and must increase continuously without gaps or duplicates.

  • One payload can contain up to 80 bytes; RS485 items use at most 68 of them.

  • Firmware permits many items, but for maintainability and storage margin, keep each batch to 64 items or fewer.

  • Channel=0 sends to both interfaces of the same type on the current MCU; 1/3 selects the first and 2/4 selects the second.

Create and Run a Batch

This example creates one CAN FD extended-frame task and runs it once:

AT+BATBEGIN=1,fd_test
AT+BATADD=1,1,5,1,10,000001230A01020304050607081112131415161718
AT+BATCOMMIT=1
AT+BATRUN=1,1,0,1

Each successful command returns:

OK

Query the result:

AT+BATSTAT?

Typical response:

BATSTAT:run=0,batch_id=1,mode=1,idx=2,count=1,repeat_cfg=1,repeat_done=0,last_err=0,tx_ok=1,tx_fail=0

Confirm that last_err=0, tx_ok increased, and tx_fail=0.

Item Format

AT+BATADD=<id>,<idx>,<proto>,<ch>,<delay_ms>,<hex_payload>

Field

Description

id

Batch ID, 1 to 99

idx

Item index, starting at 1 without gaps

proto

Bus and frame type, listed below

ch

Target Channel; 0 means both interfaces on the current MCU

delay_ms

Delay after successful transmission before the next item, 0 to 9999 ms

hex_payload

Hexadecimal data without spaces

CAN IDs use most significant byte first:

proto

Type

hex_payload

1

Classic CAN standard frame

CANID(2B) + Len(1B) + Data(0 to 8B)

2

Classic CAN extended frame

CANID(4B) + Len(1B) + Data(0 to 8B)

3

RS485

Raw device command Data(1 to 68B)

4

CAN FD standard frame

CANID(2B) + length-code(1B) + Data(0 to 64B)

5

CAN FD extended frame

CANID(4B) + length-code(1B) + Data(0 to 64B)

Classic CAN Len is the actual byte count. CAN FD uses these length codes:

Code

Bytes

Code

Bytes

00

0

08

8

01

1

09

12

02

2

0A

16

03

3

0B

20

04

4

0C

24

05

5

0D

32

06

6

0E

48

07

7

0F

64

Run Modes

AT+BATRUN=<id>,<mode>,<period_ms>,<repeat>

Field

Description

mode=1

Execute the sequence once and stop

mode=2

Execute periodically

period_ms

Delay between complete cycles in periodic mode, 0 to 65535 ms

repeat

Number of cycles; 0 continues until AT+BATSTOP

Run 10 cycles with 100 ms between cycles:

AT+BATRUN=1,2,100,10

Stop the current task:

AT+BATSTOP

Power-On Execution

After testing a batch, configure it to run after power-up:

AT+BATAUTOSET=<id>,<mode>,<period_ms>,<repeat>

Query or clear the setting:

AT+BATAUTO?
AT+BATAUTOCLR

The setting is saved to Flash. When mode=1, period_ms must be 0.

Query and Delete

Command

Purpose

AT+BATLIST?

List saved batches

AT+BATREAD=<id>,<idx>

Read a selected item

AT+BATSTAT?

Show runtime state and transmit statistics

AT+BATDEL=<id>

Delete one batch

AT+BATERASE

Delete all batches

AT+BATERASE does not remove device identity or communication settings, but deleted batches cannot be recovered.

Upload a Long Command in Chunks

If the serial application cannot send a long AT command reliably, upload one payload in chunks:

AT+BATADDX=<id>,<idx>,<proto>,<ch>,<delay_ms>,<total_len>,<seq>,<off>,<hex_part>
AT+BATADDEND=<id>,<idx>,<crc16>
  • The first chunk uses seq=1 and off=0.

  • Later seq values increase continuously and off equals the total number of previously uploaded bytes.

  • After all chunks, calculate CRC16-CCITT over the complete payload with initial value 0x0000, then send AT+BATADDEND.

  • Finish one item before uploading the next index.

Error Responses

Failures return ERR,<code>:

Code

Meaning

Common action

1

Invalid format

Check field count, hexadecimal data, and payload layout

2

Invalid state

Check BATBEGIN, continuous indexes, and chunk completion

3

Value out of range

Check batch ID, Channel, delay, and length

4

CRC mismatch

Recalculate CRC16 over the complete payload

5

Not enough storage

Delete unused batches; if configuration storage is full, use AT+CFGERASE

6

Batch not found

Confirm the ID with AT+BATLIST?

7

Transmit queue busy

Reduce the task rate or increase item delays

8

Flash read/write failure

Power-cycle and retest; inspect hardware if the error remains

See Communication Settings for bitrate, SPI length mode, and RS485 passthrough configuration.