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
CRLFline ending.Batch IDs are
1to99. Names are 1 to 16 characters and may contain letters, digits,_, and-.Item indexes start at
1and 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=0sends to both interfaces of the same type on the current MCU;1/3selects the first and2/4selects 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 |
|---|---|
|
Batch ID, |
|
Item index, starting at |
|
Bus and frame type, listed below |
|
Target Channel; |
|
Delay after successful transmission before the next item, |
|
Hexadecimal data without spaces |
CAN IDs use most significant byte first:
|
Type |
|
|---|---|---|
|
Classic CAN standard frame |
|
|
Classic CAN extended frame |
|
|
RS485 |
Raw device command |
|
CAN FD standard frame |
|
|
CAN FD extended frame |
|
Classic CAN Len is the actual byte count. CAN FD uses these length codes:
Code |
Bytes |
Code |
Bytes |
|---|---|---|---|
|
0 |
|
8 |
|
1 |
|
12 |
|
2 |
|
16 |
|
3 |
|
20 |
|
4 |
|
24 |
|
5 |
|
32 |
|
6 |
|
48 |
|
7 |
|
64 |
Run Modes
AT+BATRUN=<id>,<mode>,<period_ms>,<repeat>
Field |
Description |
|---|---|
|
Execute the sequence once and stop |
|
Execute periodically |
|
Delay between complete cycles in periodic mode, |
|
Number of cycles; |
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 |
|---|---|
|
List saved batches |
|
Read a selected item |
|
Show runtime state and transmit statistics |
|
Delete one batch |
|
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=1andoff=0.Later
seqvalues increase continuously andoffequals the total number of previously uploaded bytes.After all chunks, calculate CRC16-CCITT over the complete payload with initial value
0x0000, then sendAT+BATADDEND.Finish one item before uploading the next index.
Error Responses
Failures return ERR,<code>:
Code |
Meaning |
Common action |
|---|---|---|
|
Invalid format |
Check field count, hexadecimal data, and payload layout |
|
Invalid state |
Check |
|
Value out of range |
Check batch ID, Channel, delay, and length |
|
CRC mismatch |
Recalculate CRC16 over the complete payload |
|
Not enough storage |
Delete unused batches; if configuration storage is full, use |
|
Batch not found |
Confirm the ID with |
|
Transmit queue busy |
Reduce the task rate or increase item delays |
|
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.