serhmarch / ModbusTools

ModbusTools are cross-platform (Windows, Linux) Modbus simulator tools (client and server) with GUI to work with Modbus protocol (TCP,RTU,ASCII)
GNU General Public License v3.0
15 stars 2 forks source link

function numbering wrong ? #5

Open KLelong opened 2 months ago

KLelong commented 2 months ago

Hi, I'm running my first tests after compiling the project myself. I had unexpected results : I wanted to read holding registers, but I didn't receive the values I setup in the server. On the server-app in the device window, tab 3x, I setup the value I wanted and in the same tab of the client-app I did the counterpart. Running this, I got the expected results. So far so good. But then running my application I did not get those results. After a lot of sniffing with wireshark, I found the server-app and the client-app have the numbering of the functions wrong. I didn't pay attention to the logview but when I finally did I saw the same thing. Setting/getting things in the 3x fields resulted in function code '4' in stead of '3'. The reverse is similar : 4x gives code '3' in stead of code '4'. See the enclosed image. modbus-function I hope I made myself clear. Is this a bug ? Or something from my own compilation-process ? B.T.W. I compiled this on Kubuntu 22.04LTS. Now I know this I can work around it, but it's annoying.

I'm also not sure about the numbering of the registers. I have to have an offset of 1 to the address of the registers, but that could be the way of modbus.

serhmarch commented 2 months ago

0x,1x,3x,4x are just memory type identifiers notation and those identifiers do not correspond to Modbus function numbers:

This is an old notation used since the 1980s by Modicon (now Schneider Electric) in PLC software (e.g. Modsoft and Concept). And the elements use an address number (starts with 1, e.g. 400001, 400000 is incorrect) instead of an offset (starts with 0). But the offset (not the number) of the discrete/register is used to transfer data.