yecao
Three slave stations are connected via the USB to RS485 module. The slave modules are ID1 ID2 ID3.
The OpenPLC V3 configuration can be communicated normally by adding any slave module.
But if you add two or more, the communication times out.
Whether the OpenPLC Modbus RTU is connected to multiple slave modules on the same port does not use the polling mechanism, resulting in the failure to join the multi-slave module.

The slave module uses the Modbus poll test on the computer to allow multiple blocks of normal communication.
Modbus Poll test.png
Reply 0 0
yecao

There is no update file. OpenPLC slave devices driver apparently seems to be broken which means that me (or someone else willing to help) will have to check it and fix it.

yecao, are you running OpenPLC runtime on Windows, Linux, or Raspberry Pi? Have you tried the same setup on a different architecture (i.e. Linux as opposed to Windows, etc)?



Raspberry Pi
Reply 0 0
thiagoralves
dennie wrote:
I wonder if I am honored to participate in this project, I have PLC and RTU design experience

Anyone can participate, this is an open source project. Even though I am the main programmer I get a lot of code contributions from users every now and then. If you want to work on this particular problem, you should analyze the file /webserver/core/modbus_master.cpp.This is the file that handles communication with slave devices. It has two parts. First it parses the configuration file (mbconfig.cfg) generated by the webserver. This configuration file has all the information added on the slave devices screen, like port, baud rate, protocol type, etc...

Once the configuration is parsed, it builds a structure list containing all Modbus devices. Finally it goes through this structure and uses libmodbus commands to read/write from every device in the structure list.

I believe that the modification that needs to be done is that, once the structure list is being built, if there are multiple devices using the same port, they should be combined into one.
Reply 0 0
dennie
Modbus reading data If you use 3 MODBUS modules with ID1 ~ 3, the normal reading data is
ID-1 : IW100~IW103
ID-2 : IW104~IW107
ID-3 : IW108~IW111
But if ID-1 fails, ID-2 data will go to IW100
Data cannot be pinned to a specific address
Reply 0 0
thiagoralves
Data should stick to the address given at the Slave Devices screen. The data from the second device cannot go to the address of the first device. If this is happening, then it is also a bug that must be fixed. I'll check the code again to understand better what is going on.
Reply 1 0
pbosscha
Hi,

I can confirm the problem on my Ubuntu / RS485 setup; did identical configuration as dennie's.
When I make ID-1 stop answering, the data from ID-2 winds up in %IW100.
Reply 0 0
dennie
If you complete the repair; please tell me how to update; I am very happy to assist with the test
Reply 0 0
pbosscha
Thiago,

Looking through modbus_master; line 424
bool_input_index += (mb_devices[i].discrete_inputs.num_regs);

should that not be something like:
int_input_index += (mb_devices[i].input_registers.num_regs);
Reply 0 0
thiagoralves
pbosscha wrote:
Thiago,

Looking through modbus_master; line 424
bool_input_index += (mb_devices[i].discrete_inputs.num_regs);

should that not be something like:
int_input_index += (mb_devices[i].input_registers.num_regs);

I think you nailed it. This should be int_input_index because it is related to analog input registers.

However, I don’t think this is the only problem. If the device is disconnected and it fail to reconnect again (line 331), it should also update the indexes for all the registers of the failed device so that those addresses will be skipped
Reply 0 0
pbosscha
Ok, will start working on this, make changes and debug. 
Have also found that "Read Holding Registers" is not implemented at all. (And we need this)

Pretty clueless about contributing, so please advise on method for that ? 
Reply 0 0
thiagoralves
Thanks pbosscha! I would help you more if I had more time available, but right now I’m finishing my Ph.D. dissertation and so far all I can do is quickly respond to forum messages.

I know that read holding registers is not implemented. I reused some old code from OpenPLC v2 to implement the slave devices functionality on v3, and it didn’t have the read holding registers feature. So I just left it undone to finish it someday when I had time to do it. But I don’t think it would be hard to implement this at all. You will have to add a few lines on the cfg parser to read the line about the read holding registers, modify the original struct to have that information, and finally implement the code that does that.

If you want to contribute back with your fixes, you can commit and push directly on git. If you don’t know how to work with git, it is fine also. Just post the .cpp file here in the forum and then I can push it to git myself.
Reply 0 0
pbosscha
Attached file fixes the problem as discussed previously in this thread and adds a new feature "Read Holding Registers". Both have been tested on Ubuntu and ArchLinux. 
Was wondering about ways to signal higher levels about the status of slave devices, some register that has flags indicating whether slave devices are answering. Any ideas ?
Reply 1 0
thiagoralves
Thanks pbosscha!! I’ll take a look at the file and push it to git today
Reply 0 0
dennie
Excuse me pbosscha , Where I make ID-1 stop answering, the data from ID-2 winds up in %IW100.
Have you fixed it?
Reply 0 0
pbosscha
As far as I'm aware that problem has been resolved yes. You can test it by copying the file into your core directory (keep the old file!) and do another install, this should build the new solution.
Reply 0 0
thiagoralves
I just committed the new code to git:  https://github.com/thiagoralves/OpenPLC_v3/commit/bf03e31701b15646f3b8058f4bb53f3ee702c56f

I also made a two simple modifications to pbosscha's code. The first one was to increment output indexes as well when a device fails. The second was to move this increment code to the block when the device actually fails. In the place it was before, If a device fails once but then reconnects, the data would get misplaced because the indexes would be incremented without having to.
Reply 0 0
Reply