modbus-webserial / Smoke test (64 words / 64 bits)

Elapsed: 0 s

- Connect opens a WebSerial Modbus RTU client.
- Apply (in settings) re-opens the client using the current settings, reusing the same port.
- Start runs a full "runOnce()" test cycle repeatedly.
- Delay below is applied only between cycles.
- If repeated errors: apply interRequestDelay of a few ms

Loop interval: 1.0 s
WebSerialConfig
Port: none

Preview below is the exact object passed to ModbusRTU.openWebSerial(opts).
CRC policy only chooses strict vs resync; maxResyncDrops is always set to the default.


      
  1. Holding registers (0 ā€“ 63)   0
  2.   ā€¢ FC 16 bulk-write 64 words 0…63
      ā€¢ FC 03 bulk-read verify
      ā€¢ FC 06 single-write each word (reverse order)
      ā€¢ FC 03 read back in 8-word chunks verify
  3. Input registers (0 ā€“ 63)   0
  4.   ā€¢ FC 04 one-shot read all 64
      ā€¢ FC 04 8-word chunk reads (8Ɨ8)
      ā€¢ FC 04 64 single-word reads — compare all three results
  5. Coils (0 ā€“ 63)   0
  6.   ā€¢ FC 0F write-multiple T F T F … pattern
      ā€¢ FC 01 bulk-read verify pattern
      ā€¢ FC 05 toggle each coil individually
      ā€¢ FC 01 8-byte chunk reads verify new pattern
  7. Discrete inputs (0 ā€“ 63)   0
  8.   ā€¢ FC 02 one-shot read all 64
      ā€¢ FC 02 8-byte chunk reads (8Ɨ8)
      ā€¢ FC 02 64 single-bit reads — compare all three results
Errors appear with their sub-step tag (e.g. ā€œ3-cā€), counters tick after each major step completes without error.
Example Arduino sketch (ATmega32u4 over USB CDC, 64 regs/64 bits)
#include <Arduino.h>

// Some AVR cores don't define HAVE_CDCSERIAL even though USBCON exists.
// This makes ModbusRTUSlave(Serial_&) available on ATmega32u4 (Leonardo/Micro/Pro Micro).
#if defined(USBCON) && !defined(HAVE_CDCSERIAL)
  #define HAVE_CDCSERIAL
#endif

#include 

constexpr uint8_t  SLAVE_ID = 1;
constexpr uint32_t BAUD     = 9600;

/* 64-word / 64-bit data areas */
uint16_t holdingRegs[64];
uint16_t inputRegs  [64];
bool     coils      [64];
bool     discretes  [64];

// Force USB-CDC serial (Serial_) on 32u4
ModbusRTUSlave mb(Serial);

void setup() {
  Serial.begin(BAUD);

  // Don't block forever; browser opens the port when ready
  unsigned long t0 = millis();
  while (!Serial && (millis() - t0) < 2000) {}

  mb.configureHoldingRegisters(holdingRegs,  64);
  mb.configureInputRegisters  (inputRegs,    64);
  mb.configureCoils           (coils,        64);
  mb.configureDiscreteInputs  (discretes,    64);

  mb.begin(SLAVE_ID, BAUD, SERIAL_8N1);
}

void loop() {
  mb.poll();
}
  
Example Arduino sketch (SAMD21 over USB CDC, 64 regs/64 bits)
#include 
#include 

constexpr uint8_t  SLAVE_ID = 1;
constexpr uint32_t BAUD     = 9600;

uint16_t holdingRegs[64];
uint16_t inputRegs[64];
bool coils[64];
bool discretes[64];

ModbusRTUSlave mb(Serial);

void setup() {
  Serial.begin(BAUD);

  unsigned long t0 = millis();
  while (!Serial && millis() - t0 < 2000) {}

  delay(100);   // helps USB CDC settle

  mb.begin(SLAVE_ID, BAUD);

  mb.configureHoldingRegisters(holdingRegs, 64);
  mb.configureInputRegisters(inputRegs, 64);
  mb.configureCoils(coils, 64);
  mb.configureDiscreteInputs(discretes, 64);
}

void loop() {
  mb.poll();
}