Offline Batch Execution
Offline batches store a group of CAN, CAN FD, or RS485 commands in the board and execute them in order. The batch can continue running after the computer is disconnected, which is useful for cyclic tests and fixed action sequences.
Batch execution is relatively complex. We recommend using the online SANPO Studio tool to configure offline commands quickly.
Batch commands are configured through USB serial ports. After connecting the
board, Windows shows two SANPO Studio Management Port serial ports, one for
each STM32 MCU. STM32 (1) controls CAN-1/2 and RS485-1/2; STM32 (2) controls
CAN-3/4 and RS485-3/4. Port numbering is not guaranteed to follow the board
silkscreen; initially connect only one device to verify the mapping.
Basic Rules
Send all commands through a management port and terminate each line with
CRLF.Batch IDs are
1to99. Names are 1 to 16 characters and may contain only letters, digits,_, and-.Item IDs must start at
1and increase continuously without gaps or duplicates.A single payload is limited to 80 bytes. An RS485 item may use at most 68 of those bytes.
The firmware allows more items internally, but we recommend no more than 64 items per batch to simplify maintenance and reduce storage pressure.
Channel=0sends to both same-type interfaces managed by the current MCU;1/3selects the first interface and2/4selects the second interface.
Create and Run a Batch
The following example creates a 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 status after execution:
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
Check especially 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 ID, continuously increasing from |
|
Bus and frame type; see the table below |
|
Target channel; |
|
Wait after this item succeeds and before the next starts, |
|
Hexadecimal data without spaces |
The proto and payload formats are:
|
Type |
|
|---|---|---|
|
Classic CAN standard frame |
|
|
Classic CAN extended frame |
|
|
RS485 |
Raw device command |
|
CAN FD standard frame |
|
|
CAN FD extended frame |
|
CAN IDs use big-endian byte order. Classic CAN Len is the actual byte count.
CAN FD uses the following length code:
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 |
|---|---|
|
Run once in order, then stop |
|
Run periodically |
|
Wait between rounds in periodic mode, |
|
Number of rounds; |
For example, run one round every 100 ms for 10 rounds:
AT+BATRUN=1,2,100,10
Stop the current batch:
AT+BATSTOP
Run Automatically at Power-On
After a batch has been tested, configure automatic execution at power-on:
AT+BATAUTOSET=<id>,<mode>,<period_ms>,<repeat>
Query or clear the setting:
AT+BATAUTO?
AT+BATAUTOCLR
This setting is saved to Flash. When mode=1, period_ms must be 0.
Query and Delete
Command |
Purpose |
|---|---|
|
List saved batches |
|
Read a specified item |
|
Read run status and transfer statistics |
|
Delete a specified batch |
|
Clear all batches |
AT+BATERASE does not clear device identity or communication parameters, but
saved batches cannot be recovered.
Upload a Long Command in Chunks
If a serial tool cannot reliably send a long AT command, upload one payload in chunks:
AT+BATADDX=<id>,<idx>,<proto>,<ch>,<delay_ms>,<total_len>,<seq>,<off>,<hex_part>
AT+BATADDEND=<id>,<idx>,<crc16>
Start the first chunk with
seq=1andoff=0.Increase
seqcontinuously. Setoffto the total number of bytes already uploaded.After all chunks are complete, calculate CRC16-CCITT over the complete payload with initial value
0x0000, then sendAT+BATADDEND.Complete one item before uploading the next item ID.
Error Responses
Failures return ERR,<code>:
Code |
Description |
Common action |
|---|---|---|
|
Invalid parameter format |
Check field count, hexadecimal data, and payload layout |
|
Current state does not allow the operation |
Check |
|
Parameter out of range |
Check batch, channel, delay, and length |
|
CRC mismatch |
Recalculate CRC16 over the complete payload |
|
Insufficient storage |
Delete unused batches; use |
|
Batch does not exist |
Confirm the ID with |
|
Transmit queue is busy |
Lower the task frequency or increase item intervals |
|
Flash read/write failure |
Power-cycle and test again; check the hardware if it persists |
See Communication Settings for CAN, CAN FD, SPI length-mode, and RS485 passthrough settings.