Testing a 32-Input module with Modbus Master Sim & Arduino, beginner advice needed

This seems somewhat straightforward, but maybe it is not.
I'm experimenting with a 32-digital Input module, said to have "MODBUS RTU 03 06 command control mode". See attached.

I have it working (somewhat) using a simple Arduino sketch, verifying this example:
For example: Read channel X00-X15 port value:
Send data(RS485 address is 1):01 03 00 C0 00 01 84 36
Returns data:01 03 02 00 80 B9 E4
01 RS485 address,03 Function,02 length,B9 E4 crc16,
00 80 represents the input status of X00-X15, the eighth bit is 1, the other bits are 0; it means that X07 has input, and other channels have no input
Using the Arduino, the RS485 is from a MAX485 board connected to a serial port of an Arduino Nano, works great. With the Modbus Master Simulator, I'm using a USB to RS485 dongle I've had around a while. It is listed in the Win10P device manager as USB-Serial CH340 (COM8), and has the latest driver.

So next I'm trying to use the Radzio! Modbus Master Simulator. This app seems very simplistic, with few settings, but it doesn't work.
I have the serial port set correctly, and device setting I'm quite sure, but every frame returns 0 valid response and an error.

I have attached the manual and the Modbus RTU protocol paper that was included from the manufacturer.

Is there possibly a setting of this board, like "Input port status reporting" that must be set to enable the Modbus Master Simulator?
I'm trying to learn how this operates to create a simple input status indication display to use on the farm.

Any advice greatly appreciated.
 

Attachments

Looks like the Radzio! Modbus Master Simulator is only sending frames like:
"<tx>0x01 0x02 0x00 0x00 0x00 0x0A 0xF8 0x0D </tx>"
But this 32-Input module will only respond to the 03 Read function, not 02 function.
 
In the Radzio! Modbus Master Simulator there is a dropdown menu to select the type in the Device Settings section. You currently have Input Status selected, which results in the 02 function code. You need to select Holding Register for it to use the 03 function code. Also, the Address field should be 192 (0x00C0 hex), not 0 and the Length field should be 1, not 10.
 
Thanks jschulze.
I have it working in Radzio! now.
RMMS_scn.png

I'm looking for some example code for Arduino, the Modbus master.h libraries (examples) I have looked at leave a lot of unanswered questions in the area of reading holding registers, function 03, and basic configuration. My first step is to create a simple Modbus Poll display like above. I'm looking for a better understanding of the 'Read each individual Input - one-by-one' on my above board. I'm going to use a serial port monitor/logger to view exactly what is being send and received by Radzio!.
(no Edit in this forum? or is it because I am a new member?)
 
Take a look here for example code:
https://github.com/arduino-librarie...entKitchenSink/ModbusRTUClientKitchenSink.ino

You want to focus on the setup() and readHoldingRegisterValues() functions.

The input module you have gives you two options for reading the current state of each input:

One Channel per Register
Zero-based register addresses 0x0080 - 0x009F (128 - 159 decimal) correspond to 32 registers, each containing the current state of one channel, X0 - X31. If the register value is 1, the input is in the active state while a value of 0 means the input is in the inactive state. For example, to read X02, you would read register 0x0082 (130 decimal). If you want to read all inputs in one request, read 32 registers starting at 0x0080 (128 decimal).

One Channel per Bit
Zero-based register addresses 0x00C0 - 0x00C1 (192 - 193 decimal) corresponds to 2 registers, where each bit in the registers contain the current state of one channel, X0 - X31. Register 0x00C0 (192 decimal) contains X0 - X15, while register 0x00C1 (192 decimal) contains X16 - X31. Each register value is a 16-bit integer. The least significant bit (bit 0) corresponds to the lowest channel (X0 or X16, depending on which register is read), while the most significant bit (bit 15) corresponds to the highest channel (X15 or X31, depending on which register is read). For example, if only X12 was active, reading register 0x00C0 (192 decimal) would result in a value of 0x1000 (4096 decimal). Writing this out in binary would look like this:
X15...............................X0
0001 0000 0000 0000
 
Thanks jschulze
I'm anxious to test the kitchen sink example, it compiles, and I'm trying to transition it to an Arduino Nano I have been using with this test.
But, I have been using SoftwareSerial.h to create a second port with pins 2 & 3 for my serial to RS485 adapter, and I'm not quite sure how to configure the second port in this example. Any advice on this appreciated.
Outputs displays as:
Code:
Modbus RTU Client Kitchen Sink
Writing Coil values ... failed! Unknown
Reading Coil values ... failed! Unknown
Reading Discrete Input values ... failed! Unknown
Writing Holding Registers values ... failed! Unknown
Reading Input Register values ... failed! Unknown
Reading input register values ... failed! Unknown
 
I'll have to learn a bit about ArduinoRS485.h and the Modbus library requirements it looks like.
My RS485 is coming from one of these:
61fwDtGRx2L._AC_SL1500_.jpg

setup.jpg
 
It appears that with the ArduinoModbus and ArduinoRS485 libraries, you must use the TX and RX pins on the Arduino. Even the RS485.setPins() function doesn't seem to allow you to change the TX and RX pins used for data transfer. Try using the TX (D1) and RX (DO) pins on the Arduino instead of D2 and D3. You should then be able to confirm communication by looking at the Arduino's TX and RX LEDs, which should both flash when there is successful communication with your Modbus input module.

If you can't use the TX and RX pins, another library may allow you to use the SoftwareSerial.h.
https://github.com/angeloc/simplemodbusng
https://github.com/syvic/ModbusMaster

This appears to be an example of someone doing just that:
https://github.com/worrajak/modbus-softwareSerial

I'd also recommend taking a look at, or posting on, the Arduino forums for this. A quick search turned up someone asking a similar question:
https://forum.arduino.cc/t/modbus-and-software-serial-libraries/584062

As far as the adapter, it is a TTL to RS-485 adapter. But since it only has TX and RX signal inputs, it must automatically generate the driver enable signal to the RS-485 transceiver chip. This could potentially cause issues, as it is designed to work for a specific minimum baud rate, and any baud rates higher than what it is designed for will result in the transceiver driving the bus for additional time, which could cause contention if your Modbus slave device responds very quickly to the requests.
 
In the post you linked, you stated you got this working with an Arduino UNO. Is this true?

If so, wouldn't the Arduino UNO and Arduino Nano be very similar, both hardware and software-wise, even using the same code?

Did you try using the TX and RX pins with the ArduinoModbus library?
 
Top