Solved.
The input/output names needed to be changed to work with this model. ( Q0_0 -> R1 ).
This fault caused the available number of inputs/outputs to be zero and that's why I couldn't write to the outputs for example.
This code for testing the outputs works:
#include <RS485.h> #include <ModbusRTUSlave.h> #define RS485_RATE 9600UL int digitalOutputsPins[] = {R1, R2, R3, R4, R5, R6}; #define numDigitalOutputs int(sizeof(digitalOutputsPins) / sizeof(int)) bool digitalOutputs[numDigitalOutputs]; // Define the ModbusRTUSlave object with Modbus RTU slave address: 1 ModbusRTUSlave modbus(RS485, 1); void setup() { // put your setup code here, to run once: Serial.begin(9600) ; // Init RS485 RS485.begin(RS485_RATE, HALFDUPLEX, SERIAL_8E1); // Init ModbusTCPSlave object modbus.begin(RS485_RATE); modbus.setCoils(digitalOutputs, numDigitalOutputs); } void loop() { // Process modbus requests modbus.update(); // put your main code here, to run repeatedly: for (int i = 0; i < numDigitalOutputs; ++i) { digitalWrite(digitalOutputsPins[i], digitalOutputs[i]); } }
The test results:
./modpoll -b 9600 -p even -m rtu -a1 -c6 -t0 /dev/ttyUSB0 1 1 0 1 1 1 modpoll 3.9 - FieldTalk(tm) Modbus(R) Master Simulator Copyright (c) 2002-2020 proconX Pty Ltd Visit https://www.modbusdriver.com for Modbus libraries and tools. Protocol configuration: Modbus RTU, FC15 Slave configuration...: address = 1, start reference = 1, count = 6 Communication.........: /dev/ttyUSB0, 9600, 8, 1, even, t/o 1.00 s, poll rate 1000 ms Data type.............: discrete output (coil) Written 6 references.
Old question:
Hello,
I Bought a Ardbox Relay HF+ and was going to use it as a Modbus RTU Slave.
I found some programming examples on github but I can't get it to work.
I had some success when I used the RTU Master examples and could see data being transmitted but when configured as slave I get "Illegal Data Address exception response!". Can't seem to read any data from the slave device.
I have been using modpoll and diagslave from modbusdriver(dot)com and a Schneider PLC for testing.
Is there any more information to find for the modbus slave functions or is the examples the only documentation?
Any tips on how to get it to work?
Regards
Tobias