Open
Description
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
- The direct serial communication successfully receives a response from the device
- The response data format appears to be valid Modbus RTU
- The same serial port and parameters are used in both implementations
- The device is responding with 6 bytes of data (as indicated by the 0x06 in the response)
Questions
- Is there a known issue with address mapping in tokio-modbus?
- Could the library be misinterpreting the response data format?
- Are there any specific configuration requirements for handling non-standard response formats?
Reproduction Steps
- Connect to the serial device with the specified parameters
- Try reading holding registers using tokio-modbus
- Compare with direct serial communication results
Any help or guidance would be greatly appreciated!