Skip to content

function numbering wrong ? #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
KLelong opened this issue May 7, 2024 · 1 comment
Closed

function numbering wrong ? #5

KLelong opened this issue May 7, 2024 · 1 comment

Comments

@KLelong
Copy link

KLelong commented May 7, 2024

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
Copy link
Owner

serhmarch commented May 7, 2024

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

  • 0x - intended for coils (discrete outputs, boolean), corresponding modern PLC notation is %M or %Q (e.g. 000001 coil in modern notation can be accessed like %M0 or %Q0), can have Read/Write access, corresponding access functions are READ_COILS (which number is 1) and WRITE_MULTIPLE_COILS(15, 0x0F);
  • 1x - intended for discrete inputs (boolean), corresponding modern PLC notation is %I (e.g. 100001 boolean in modern notation can be accessed like %I0), has ReadOnly access, corresponding access function is READ_DISCRETE_INPUTS (2);
  • 3x - intended for analog inputs (16 bit word), corresponding modern PLC notation is %IW (e.g. 300001 word in modern notation can be accessed like %IW0), has ReadOnly access, corresponding access function is READ_INPUT_REGISTERS(4 (!), yes, it doesn't match with memory type id);
  • 4x - intended for holding registers (analog outputs, 16 bit word), corresponding modern PLC notation is %MW (e.g. 400001 word in modern notation can be accessed like %MW0), , can have Read/Write access, corresponding access functions are READ_HOLDING_REGISTERS(3 (!), yes, it doesn't match with memory type id again) and WRITE_MULTIPLE_REGISTERS(16, 0x10);

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants