Offline Batch Execution

Offline batch execution stores a sequence of CAN or RS485 commands on the board and sends them automatically in the configured order, at the configured intervals, and for the configured number of cycles. After a batch is saved, it can run without continuous commands from a PC and can start automatically after power-up.

V47 or later V4 firmware is recommended. When using a serial terminal, open the board USB serial port, send commands as text, and set the line ending to CRLF. Each successful setup command returns OK.

You can also create and debug batches through SANPO Studio.

Before You Start

One USB serial port controls the two CAN and two RS485 channels managed by the current STM32. Select the local target with Channel:

Channel

Target controlled by the current USB serial port

1 or 3

First CAN or RS485 channel

2 or 4

Second CAN or RS485 channel

0

Both channels of the selected bus type

For the USB port controlling CAN-1/2 and RS485-1/2, use Channel 1 and 2. For the other STM32, use 3 and 4 so the host configuration matches board silkscreen.

First configure communication settings that match the devices:

AT+SETCAN=1000000
AT+SETRS485=4000000,1,0,8

Supported CAN bitrates are 100000, 125000, 250000, 500000, and 1000000 bit/s. See RS485 Raw Passthrough for RS485 parameters. These settings are saved across power cycles.

Create a Batch Quickly

This example creates batch 1 with one CAN extended frame followed by one RS485 command.

  1. Begin the batch:

    AT+BATBEGIN=1,motor_test
    
  2. Add item 1: send extended ID 0x123 with 8 data bytes on the first CAN channel, then wait 20 ms:

    AT+BATADD=1,1,2,1,20,00000123081122334455667788
    
  3. Add item 2: send 17 bytes on the second RS485 channel, then wait 10 ms:

    AT+BATADD=1,2,3,2,10,FEEE11000000000000000000000000187C
    
  4. Save the batch:

    AT+BATCOMMIT=1
    
  5. Run it once:

    AT+BATRUN=1,1,0,1
    

For the first test, use one-shot execution and keep people and obstacles away from the motor. Verify every command before enabling periodic or power-on execution.

BATADD Fields

AT+BATADD=<batch-id>,<index>,<protocol>,<Channel>,<delay>,<hex-data>

Field

Description

Batch ID

1 to 99

Index

Starts at 1 and must increase without gaps

Protocol

1: CAN standard; 2: CAN extended; 3: RS485

Channel

0 to 4; see “Before You Start”

Delay

Time from the end of this command to the start of the next, 0 to 9999 ms

Hex data

No spaces; two characters per byte; maximum 60 bytes

Batch names can contain letters, digits, underscores, and hyphens and must be 1 to 16 characters. Beginning and committing a new batch with the same ID replaces the existing valid batch.

CAN Data Format

CAN standard-frame data:

CAN_ID (2 bytes, most significant byte first) + DLC (1 byte) + DATA (0 to 8 bytes)

CAN extended-frame data:

CAN_ID (4 bytes, most significant byte first) + DLC (1 byte) + DATA (0 to 8 bytes)

DLC must match the number of DATA bytes. For RS485, enter the complete raw command defined by the device manufacturer, up to 60 bytes.

Run, Stop, and Query

AT+BATRUN=<batch-id>,<mode>,<period>,<repeat-count>

Parameter

Description

Mode 1

Execute the batch once; use period 0

Mode 2

Periodic execution; item delays apply, then the period is added between complete cycles

Period

0 to 65535 ms

Repeat count

Number of complete cycles in periodic mode; 0 runs until AT+BATSTOP or power-off

Run 10 cycles with an additional 100 ms between cycles:

AT+BATRUN=1,2,100,10

Stop the running batch:

AT+BATSTOP

Query status:

AT+BATSTAT?

Example response:

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

run=1 means the batch is running, idx is the next item, and repeat_done is the number of completed cycles. last_err=0 and tx_fail=0 indicate no current transmit error.

Read and Delete Saved Batches

List batches:

AT+BATLIST?

Example:

BATLIST:1,motor_test;2,stand_test

When no batch is saved:

BATLIST:NONE

Read a summary or one item:

AT+BATREAD=1,0
AT+BATREAD=1,1

Example:

BATREAD:id=1,name=motor_test,count=2
BATREAD:id=1,idx=1,proto=2,ch=1,delay_ms=20,payload=00000123081122334455667788

Delete one batch:

AT+BATDEL=1

Delete all batches:

AT+BATERASE

AT+BATERASE only clears offline batch storage, but deleted batches cannot be recovered. It is not required during normal operation.

Configure Power-On Execution

Test the saved batch manually before enabling power-on execution.

Run batch 1 periodically, with 200 ms between cycles, for 2 cycles:

AT+BATAUTOSET=1,2,200,2

Run once after power-up:

AT+BATAUTOSET=1,1,0,0

Query the setting:

AT+BATAUTO?

Example response:

BATAUTO:ID=1,MODE=2,PERIOD=200,REPEAT=2

Disable power-on execution:

AT+BATAUTOCLR

If the referenced batch has been deleted, the board starts normally but does not execute it. Clear power-on execution before deleting the referenced batch.

Upload a Long Command in Chunks

AT+BATADD supports up to 60 bytes. Use chunked upload only when the serial tool cannot send a long command reliably:

AT+BATADDX=<batch-id>,<index>,<protocol>,<Channel>,<delay>,<total-length>,<sequence>,<offset>,<hex-part>
AT+BATADDEND=<batch-id>,<index>,<CRC16>

Sequence starts at 1, offset starts at 0, and chunks must be contiguous. CRC uses reflected CRC-CCITT with initial value 0x0000 and polynomial 0x8408, calculated over the complete raw data.

This example uploads a 40-byte RS485 command with CRC EFCE:

AT+BATBEGIN=2,long_rs485
AT+BATADDX=2,1,3,2,20,40,1,0,11223344556677889900AABBCCDDEEFF
AT+BATADDX=2,1,3,2,20,40,2,16,0102030405060708090A0B0C0D0E0F10
AT+BATADDX=2,1,3,2,20,40,3,32,1112131415161718
AT+BATADDEND=2,1,EFCE
AT+BATCOMMIT=2

Error Responses

Failures return ERR,<code>:

Response

Common cause and action

ERR,1

Invalid format; check commas, hexadecimal data, protocol, and communication parameters

ERR,2

Invalid sequence; run AT+BATBEGIN again and add items continuously from index 1

ERR,3

ID, length, delay, or another field is out of range

ERR,4

Chunk CRC does not match; recalculate CRC over the complete payload

ERR,5

Not enough storage; delete unused batches and retry

ERR,6

The specified batch or item was not found

ERR,7

Transmit queue is busy; reduce the execution rate or retry later

ERR,8

Flash read/write failed; power-cycle and retry, then contact support if the error remains