dazeredo
Hello

I'm trying to connect my openplc running on a Raspberry PI3 to a Schneider Electric STBNIP2212 with one input card and one output card.

The STBNIP2212 is working, verified with some MODBUS tools.

The output of the STBNIP2212 is 1 word on position 0 and the input is 1 word located on position 5391.

With a configuration file only to write the outputs, the program works just fine but when I try to read the inputs I've this error:

Quote:
Starting OpenPLC Application...
OpenPLC Software running...

Device Slave1 is disconnected. Attempting to reconnect...

Setting main thread priority to RT
Locking main thread memory

Server: Listening on port 502

Server: waiting for new client...

Connected to MB device Slave1

Getting current time

Modbus Read Discrete Input Registers failed on MB device Slave1: Illegal data address

Device Slave1 is disconnected. Attempting to reconnect...



The configuration file is:


Num_Devices = "1"
​
# ------------
# DEVICE 0
# ------------
device0.name  = "Slave1"
device0.protocol = "TCP"
device0.slave_id = "1"
device0.address = "192.168.113.175"
device0.IP_Port = "502"
device0.RTU_Baud_Rate = ""
device0.RTU_Parity = ""
device0.RTU_Data_Bits = ""
device0.RTU_Stop_Bits = ""
​
device0.Discrete_Inputs_Start = "0"
device0.Discrete_Inputs_Size = "0"
device0.Coils_Start = "0"
device0.Coils_Size = "0"
device0.Input_Registers_Start = "5391"
device0.Input_Registers_Size = "1"
device0.Holding_Registers_Start = "0"
device0.Holding_Registers_Size = "1"


Anyone have an ideia of what's wrong?

Thanks in advance!
Reply 0 0
thiagoralves
This message means that your device is saying that the address you requested is out of range. Are you reading digital inputs? Input Registers are used for analog input readings, so if you're trying to read digital inputs you should use Discrete_Inputs_Start instead. Have you tried that?
Reply 0 0
dazeredo
Yes, with other modes it's says that the function is illegal and disconnects from the STB.
The inputs are digital but the inputs of each card are accessed as a single memory word.
Reply 0 0
thiagoralves
Try to use Radzio Modbus (freeware) or Modbus Poll to query your device. Double check the ranges and try to use Input Status to query for single bit digital inputs. If your query works with one of those software, it should work just fine with OpenPLC. The normal behavior for OpenPLC Modbus driver is to disconnect if there is any failure in communication, and then reconnect at the next cycle. So if your device is not communicating properly or if there is any problem, OpenPLC disconnects and reconnects as an attempt to solve the problem.

For your particular case, it seems that OpenPLC can talk to the device, but it is receiving an "illegal address" message as response. That is flagged as an error and is enough to trigger the disconnect/reconnect process.

One last thing to think about is the difference between PLC addressing and protocol addressing. In PLC addressing the first address is 1, while in protocol addressing, the first address is zero. OpenPLC goes by protocol addressing. See if your address shouldn't actually be 5390 instead of 5391.
Reply 0 0
dazeredo
The addresses have already been validated with the poll Modbus but came back to do testing and analysis of traffic with wireshark and what I realized the problem is the fact that the STB using Holding Registers to read both inputs as outputs.
Now I'm trying on the Modbus Master Configuration config file add two Holding_Registers parameters. There isn't any error but the code doesn't work (if in>0 then out=1 else out =3). 


device0.Holding_Registers_Start = "5391"
device0.Holding_Registers_Size = "1"
device0.Holding_Registers_Start = "0"
device0.Holding_Registers_Size = "1"


I'm using %QW0 as input (mw5391) and %QW1 as input output (mw0), am I addressing the variables correctly?
Thanks for the help!
Reply 0 0
thiagoralves
That’s sad. OpenPLC follows strictly the Modbus standard, which means that digital input should be on Input Status, digital outputs on Coils, analog inputs on Input Registers and analog outputs on Holding Registers. You can add the inputs as holding registers, but in OpenPLC they would be treated as outputs, not inputs, which means that OpenPLC would always write to them, and never try to read from them. The only way to fix this would be for you to modify the Modbus Master driver to allow reading from holding registers, but that could become too complicated....
Reply 0 0
dazeredo
For this project I can't change the equipment, I need to control some equipment already connected to four ST. For now the working solution is using Beremiz directly on the raspberry.
In a future project without the need of using the STBs I'll try again OpenPLC.
Reply 0 0
thiagoralves
I’m currently developing OpenPLC v3 right now. It seems that reading Holding Registers could potentially be a good functionality, so I’m planning to add that on the next version of OpenPLC. I’ll let you know once it is ready, so you can try it out.
Reply 0 0
Reply