thiagoralves
I finished writing a Modbus Master Driver for the OpenPLC. It means that you can now use your Modbus Slave device as an I/O for the OpenPLC soft-core running in your PC. The driver supports Modbus TCP and RTU, although I haven't tested the RTU mode yet because I don't have any RTU device. I'll be happy if any of you can test it and report back if it worked.

The instructions are fairly simple. If you already have OpenPLC installed, you will need to remove it before installing the new version, or install it into a different directory. To remove, just open terminal (or cygwin terminal on windows) and type:
rm -Rf OpenPLC_v2

Then follow the instructions on the website to install the OpenPLC in your platform (windows or linux). You don't need to download and install cygwin or nodejs again, but you will need to execute all the commands listed on the instructions again because there are new packets that are needed to be installed for this driver to work. Then, at the end of the build process, choose the Modbus driver (option 2).

Finally, when you start the OpenPLC, you will notice a new field on the web interface. It's a place to upload the modbus configuration file. The OpenPLC must know how to connect to your modbus slave devices, and the parameters must be written in this file. I've attached one example here, but you need to modify it in order to match your configuration. (PS: The forum doesn't support files with .cfg extension. After downloading it, you must change the extension from .txt to .cfg)

The modbus configuration file is a text file that can be edited on any text editor (i.e. notepad on windows), and it's pretty much self-explanatory. Just edit the file with your configuration and upload it using the web interface. I'll post more detailed instructions later on the website. First I just need to know if it works well for your devices.


Thanks!
Quote 1 0
nmambre
I hope to be able to try this out next week. I'll need to set up a virtual machine first and then I'll test with some hardware at the office.
Quote 0 0
jinyistudio
Hi
You can try following tool for testing your protocol
PeakHMI MODBUS Serial RTU Slave simulator
http://peakhmi.com/

Null-modem emulator

http://com0com.sourceforge.net/
[jinyi_title_1p] 
Delphi, B4A, B4J, C#/Mono, Mitsubishi Q-PLC
[image]
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
[image]
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
Quote 0 0
nmambre
I just changed the IP to 127.0.0.1 and the port to 1502 to use a slave simulator on same machine. When I load the cfg I see in the terminal that it is started, but I don't see any query to the slave.
I loaded the HelloWorld example to the softplc (WinXP).
Do I need to change anything else?
Quote 0 0
jinyistudio
Hi

I have install OpenPLC and modbus driver in my PI2. I try to use Modbus/TCP but i don't how to including modbus's varialbe  into my OpenPLC's program ?

Bye
[jinyi_title_1p] 
Delphi, B4A, B4J, C#/Mono, Mitsubishi Q-PLC
[image]
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
[image]
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
Quote 0 0
thiagoralves
nmambre wrote:
I just changed the IP to 127.0.0.1 and the port to 1502 to use a slave simulator on same machine. When I load the cfg I see in the terminal that it is started, but I don't see any query to the slave.
I loaded the HelloWorld example to the softplc (WinXP).
Do I need to change anything else?

You should see queries constantly. Which platform you are running the OpenPLC on? Can you try to start the OpenPLC manually and post here the output. To do it, just enter on the core folder inside OpenPLC_v2 and run the executable:

(Linux)
cd OpenPLC_v2
cd core
sudo ./openplc

(Windows)
cd OpenPLC_v2
cd core
./openplc

I've seen libmodbus having issues on some platforms. To know if you're having issues I need to see the OpenPLC program output.

Quote 0 0
thiagoralves
jinyistudio wrote:
I try to use Modbus/TCP but i don't how to including modbus's varialbe  into my OpenPLC's program?

All of your located variables are exported to the modbus module. For example, the coil output %QX0.3 is on the modbus coils address 3. The only difference is that coils and digital inputs grow in groups of 8 values (after %QX0.7 the next value is %QX1.0) but the modbus coils grows sequentially. Therefore, the coil %QX1.2 for example would be modbus coil address 10.
Quote 0 0
jinyistudio
Hi

1. My modbus tcp testing tool don't receive any request from OpenPLC in Raspberry PI2. My cfg as attachied file.
    I have upload st and mbconfig. no error and all strating. Do you have any idea for me ?
2. Do i need change the class of lamp ?

open_q1.png 
[jinyi_title_1p] 
Delphi, B4A, B4J, C#/Mono, Mitsubishi Q-PLC
[image]
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
[image]
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
Quote 0 0
thiagoralves
Yesterday I discovered a problem with OpenPLC on the RaspberryPi. I fixed the code on github but you might have the old code. To fix it, just type:

sudo ldconfig

and then run OpenPLC again. It worked on my RaspberryPi B+, although I don't have a Pi2 to test. It should work as well.

I tested with this modbus slave tool (http://www.modbustools.com/modbus_slave.html) and it worked.

Also, try running the OpenPLC manually (outside the webserver) to see the program output. There are some errors on the OpenPLC program that the webserver doesn't catch yet. To run it manually, just enter on the core folder inside OpenPLC_v2 and run the executable:

cd OpenPLC_v2
cd core
sudo ./openplc

Please post here your output when running the OpenPLC manually.
Quote 1 0
jinyistudio
Hi

Thank's,I have do "sudo ldconfig" and "sudo ./openplc" and i can communication with slave device now.  
So my question is how to run OpenPLC, Is "sudo nodejs server.js" Or "sudo ./openplc" ?

Bye
[jinyi_title_1p] 
Delphi, B4A, B4J, C#/Mono, Mitsubishi Q-PLC
[image]
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
[image]
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
Quote 0 0
thiagoralves
For the OpenPLC to "run" you only require to run the sudo ./openplc application. However, it's always better to run the webserver (sudo nodejs server.js) because it will be easier to change the PLC program or its configuration anytime you need.
Quote 0 0
nmambre

I did this test on WinXP 32 bit (VM in VirtualBox)
When I run from the webserver, the slave doesn't show any queries.
I'm using https://sourceforge.net/projects/modrssim2/  (shows if any master connected)

$ node server_win.js
Working on port 8080
Stopping OpenPLC Software...
Starting OpenPLC Software...


When I start openplc directly I see the queries.

$ ./openplc.exe
OpenPLC Software running...
Waiting for Modbus/TCP connection on Port 502
Getting current time


I'll do further tests.


Quote:
All of your located variables are exported to the modbus module. For example, the coil output %QX0.3 is on the modbus coils address 3. The only difference is that coils and digital inputs grow in groups of 8 values (after %QX0.7 the next value is %QX1.0) but the modbus coils grows sequentially. Therefore, the coil %QX1.2 for example would be modbus coil address 10.

What are the naming conventions for Input and Holding registers?


Quote 0 0
thiagoralves
nmambre wrote:
When I run from the webserver, the slave doesn't show any queries. When I start openplc directly I see the queries.

That's weird. It should run the same way, because the server is simply starting ./openplc.exe. There might be something wrong with the server_win.js code, I'll check that.

nmambre wrote:
What are the naming conventions for Input and Holding registers?

iec_io.png 
Which means that
%IX0.0 to %IX0.7 -> the first 8 digital inputs (modbus discrete input)
%QX0.0 to %QX0.7 -> the first 8 digital outputs (modbus coils)
%IW0.0 to %IW0.n -> the first n analog inputs (modbus input registers)
%QW0.0 to %QW0.n -> the first n analog outputs (modbus holding registers)

You can have more than 8 digital inputs and outputs, but to access them you'll need to use the second group: %QX1.0 and so on...


Quote 1 0
thiagoralves
nmambre wrote:
When I run from the webserver, the slave doesn't show any queries.


Fixed! [smile]
Just git clone the code again from the repository and rebuild.

Also, could you try that on your real hardware (specially modbus RTU)? Let me know if it worked
Quote 2 0
jinyistudio
Hi
Thank's I try it in PI2 and it is OK.
thiagoralves wrote:


Fixed! [smile]
Just git clone the code again from the repository and rebuild. Also, could you try that on your real hardware (specially modbus RTU)? Let me know if it worked
[jinyi_title_1p] 
Delphi, B4A, B4J, C#/Mono, Mitsubishi Q-PLC
[image]
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
[image]
Delphi, C#, Q-PLC, B4A, B4J, Raspberry PI2
Quote 0 0