IdeaSoft
Hello 

My name is Bojan and this is my first post to OpenPLC forums. 

I have many years of experience with PLC programming (mostly Siemens and Beckhoff). Now I try new direction of PLC with Revolution PI and OpenPLC. I manage to install both runtime and editor on RevPi Connect and it works fine.

I am trying to re-design 2 years old application running on Raspberry Pi, written in Python (with pymodbus) and using Turck modbus I/O (BL20-E-GW-EN). My application is acting as modbus client and reads input and writes coils at address 0 (zero).

Configuring modbus  slave devices are attached to address 100 onward, but my Turck I/O module returns  input and coils at address 0 (as I program in my Python application). In  https://www.openplcproject.com/reference/modbus-slave/ there is discussion about this topic, but I need some help on implementation.

Do I miss some basics here? Please advice as this implementation is "show stopper" of using OpenPLC.

Regards
Reply 0 0
thiagoralves
Slave devices are attached to address 100 onward on OpenPLC address base, not on the slave address base. This means, for example, that if you add a slave device with one coil at modbus address 0, it will be available directly on OpenPLC at address %QX100.0. You can see this when you are configuring a generic modbus slave, you can define all the addresses and ranges for all modbus data types.
Reply 0 0
IdeaSoft
Thank you for really quick response.
Yes, it works as you describe, but I realize that the output is on only fraction of time during poll  active i.e. if I define pool interval 5000 ms, coil is off 4900 ms and on 100 ms. How can I achieve permanent coil on setting?

Thank you for help.

 
Reply 0 0
thiagoralves
That should be something you fiddle on your slave device, not OpenPLC. In essence, a slave device must keep it latest state until a new command is received. If it is not keeping its last state, either it is misconfigured or it is receiving commands from someone else.
Reply 0 0
IdeaSoft
As I stated before, I two years ago build Python program to communicate with Modbus I/O and today I extract only essential code to test ma slave device. Although I have two long sleep() in my code, there is no output flickering. Light on output module is steady. This is my complete code.
Reply 0 0
thiagoralves
OpenPLC won’t make your output flicker, unless you have explicitly programmed it to do so in your PLC program. This is most likely being caused because you have two or more masters controlling your slave device. A slave device must have only one master, otherwise its outputs will be undetermined 
Reply 0 0
IdeaSoft
I did Wireshark trace to check if there is more than one master in the session and it turns out there is only one source at the time communicating. There is different of commands. My program use function 5 Write single coil, OpenPLC is using function 15 Write multiple coils. 
I attach screen shots of both cases
Reply 0 0
thiagoralves
OpenPLC uses the write multiple versions of the Modbus protocol to improve latency, so it can write to all locations at once. If your slave device does not support these functions, then there is nothing you can do except change your device or modify OpenPLC internal code.
Reply 0 0
IdeaSoft
I think the problem is not in TURCK device. Can you point me to OpenPLC area where I can find modbus communication?

Device GW Configuration:

[37405f96]

[2de42dcc]

[a9b8cdb3]

Reply 0 0
thiagoralves
You can find the Modbus master code here:  https://github.com/thiagoralves/OpenPLC_v3/blob/master/webserver/core/modbus_master.cpp

How is your slave device config on OpenPLC? Have you tried using just one coil and one discrete input like your Python script?
Reply 0 0
IdeaSoft
I find the cause of problem.

Definition of Address of Holding registers write in my slave definitions was wrong. As I do not use this area, I was not aware of this. The address actually overlap coils and writing holding registers overwrite coils.

I have another question. I want to use PSM, but running the example code in python I get error on import psm. Can you point me to some description of how to use this option.

Thank you for help.
Reply 0 0
Reply