Skip to content

tokio-modbus fails to read data while direct serial communication works #320

Open
@Alarak-Alex

Description

@Alarak-Alex

Issue: tokio-modbus fails to read data while direct serial communication works

Problem Description

When trying to read Modbus RTU data from a device, direct serial communication works successfully, but tokio-modbus library fails with IllegalDataValue error.

Working Implementation (Direct Serial)

// Manual request frame construction
let mut request = vec![0x01, 0x03, 0x01, 0x00, 0x00, 0x03];
let crc = crc16(&request);
request.push((crc >> 8) as u8);
request.push(crc as u8);

// Send request
port.write_all(&request).await?;

// Read response
let mut response = vec![0u8; 256];
let n = port.read(&mut response).await?;
let response = &response[..n];
println!("Device response: {:02X?}", response);
// Response: [01, 03, 06, 31, 3D, 31, 79, 30, FA, 03, F7]

Failing Implementation (tokio-modbus)

let slave = Slave(0x01);
let mut ctx = rtu::attach_slave(port, slave);
let rsp = ctx.read_holding_registers(0x0100, 3).await??;
// Error: IllegalDataValue

Environment

  • OS: 15.3.1 (24D70)
  • Serial Port: /dev/tty.usbserial-1110
  • Serial Parameters:
    • Baud Rate: 4800
    • Data Bits: 8
    • Parity: None
    • Stop Bits: 1
    • Flow Control: None

Additional Information

  1. The direct serial communication successfully receives a response from the device
  2. The response data format appears to be valid Modbus RTU
  3. The same serial port and parameters are used in both implementations
  4. The device is responding with 6 bytes of data (as indicated by the 0x06 in the response)

Questions

  1. Is there a known issue with address mapping in tokio-modbus?
  2. Could the library be misinterpreting the response data format?
  3. Are there any specific configuration requirements for handling non-standard response formats?

Reproduction Steps

  1. Connect to the serial device with the specified parameters
  2. Try reading holding registers using tokio-modbus
  3. Compare with direct serial communication results

Any help or guidance would be greatly appreciated!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions