frangoteam / FUXA

Web-based Process Visualization (SCADA/HMI/Dashboard) software
https://frangoteam.org
MIT License
2.49k stars 741 forks source link

[BUG] ModbusTCP 16bit register write - bad function code #1175

Open AllmarkPL opened 2 months ago

AllmarkPL commented 2 months ago

Hello, I'd run into an issue where I can't write values into single 16bit register of modbus device. I have created a single tag with INT16 datatype and proper device addressing, but when I tried to write data into it nothing happended. Quick look into modbus logs has shown that function 16 (multiple registers) is used instead of 06 (single registers) and communication is interrupted due to "bad lenght 8 (expected more than 8)". When I switched Fuxa tag datatype to INT32 all started working, but I can't leave it that way, because device I'm using have 6 consecutive 16bit registers which I got to use... Is there a way to properly send single 16bit register by modbus TCP in Fuxa? I don't think it's issue with the device itself, because I can write data into it using simulator or HMI.

To Reproduce

  1. Create a modbus TCP IP device with single INT16 tag
  2. Try to write any value either due to script action or by input.

Expected behavior I think it may be a bug in modbus tcp plugin.

Environment

rvbatista commented 2 months ago

Hello, thanks for your issue. Are you able to test both conditions with Wireshark capturing the packages?

AllmarkPL commented 2 months ago

Hello, as for now I can provide packet data for writing into modbus simulator software, I will have access to physical device on monday. As You can see on packets below, the function code used for writing is in fact 16, and is lacking second byte in transmission which causes error. First screen is from writing by script, second is from writing by input box. Third is after changing datatype to INT32. I think, that it was working properly in one of older versions, but I got to verify that. Writing to INT16 by input box: image Writing to INT16 by script: image Device dataset: image Modbus dump: image Writing to INT32 by the same script: image Device datset: image

unocelli commented 1 month ago

Hi, have you try to update modbus-serial to 8.0.16?

rvbatista commented 1 month ago

What are your modbus server? The reading is working? The usage of write multiple registers is in fact bad for efficiency, but it should work if your server have it implemented.

AllmarkPL commented 1 month ago

Hello, reading works without problem and writing 32 bit registers and booleans is working fine, also this error (FC16 used instead of FC06 when trying to write single INT16) appears on multiple devices and simulators I've tested. I will try to check modbus-serial version, because now I can confirm that this is case on version which is included in latest docker container (I don't have access to server now, but will check later and also test on modbus-serial 8.0.9 which I have on another server).

rvbatista commented 1 month ago

The usage of FC16 instead of FC06 is in fact I'm the logic, today Fuxa will never use FC06. You know this is not exactly an error, since you can use FC16 to write only one register, but I trying to figure out why you are having an error in this case.

unocelli commented 1 month ago

Hi, I added the possibility to set a frame delay that maybe can help (in master branch), would be nice to try and give me feedback

AllmarkPL commented 1 month ago

Hello, thank You for reply. I tested it (tried several delay values from 10 ms to 2000 ms) just now, but it don't fix the issue - still the same error ("bad lenght 8, expected more than 8"). I had worked around it using OpenPLC on server and some DINT to INT processing, because I had to move forward with the project. I got to make it that way, because device which I'm working with had scrict registers addresing (separate memory part for 16 bit HR for setting and setpoints for which it will only accept FC06 modbus command separate and 32 bit memory registers for process settings).