nuktameron
Good morning,

I am trying to put together a project with a Raspbery Pi, which is supposed to
run both a PLC program and an HMI application.

So far I can run the openPLC package on the Raspberry and see the GPIO
inputs and outputs changing state controlled by the PLC program.

I can also run the Advanced HMI application on the Raspberry itself (I have a
7" screen). However, the interfacing between openPLC and AvancedHMI is
quite a blurry territory for me.

Would someone else be kind enough to direct me where to look for answers to the
following questions:

1) I am aware that OpenPLC runs as a Modbus slave. What would be the proper protocol to use
    to connect to the GPIO if we want to interface with it from another application? Would we
    choose Modbus TCP? If yes, then will the IP address of the Raspberry be the same that it has
    on the network?
    - The choices that AHMI offers are Modbus TCP and RTU among a number of other drivers

2) What is the correct way to reference the Modbus registers?
   - Let's say if you want to assign a button on the HMI to a Modbus register, which controls a
     variable that controls something in the PLC program.
    - Do we use a number (such as 40010, according to the number of the register) or
      %QX1.2 (for the output directly) or %MW500 or something else along those lines?

Thanks for the help!
Alex
Reply 0 0
thiagoralves
Hi Alex,

I've never used Advanced HMI, but if it can talk Modbus/TCP it should work fine. About the IP address, you can use the IP your Raspberry Pi has in the network, or you can also use 127.0.0.1 or localhost (localhost is an alias for the machine's own IP), it is all the same.

OpenPLC also provides official support to ScadaBR. ScadaBR is a free and open source HMI editor + historian than runs on any web browser. If you want, you can give that a try as well.

About your second question, take a look here: http://www.openplcproject.com/scada
Reply 0 0
nuktameron
Hi again Thiago,

Thanks for the quick response. So this is what I am planning to do. The HMI will control a holding register variable. The holding register variable will be referenced
in an OpenPLC program and will cause the program to turn on or off certain outputs on the GPIO. It really does not simpler than that, I know but I am just testing
the basic functions of the system.

My main question would be, in the HMI application how would we refer to a certain holding register? Same thing applies if we try to manipulate the Modbus register from
another utility while trying to troubleshoot. Say, if I want to use the 16-bit  holding register number 20, will I have refer to it as:
  - %MW20 (same format as PLCopen editor)
  - 40021 (as per the standard Modbus numbering, if we start from 40001)
  - or 40001+1024(%QW- outputs)+20 = 41045- for me this makes the most sense, give or take 1 depending on whether we count the zeros

Also, I will definitely try ScadaBR, I was just wondering if AdvancedHMI will work as well, because my coworker likes it.

Regards,
Alex
Reply 0 0
thiagoralves
This 40001 offset they keep talking on Modbus protocol is nonsense. It is just there to add confusion. Just follow the table on website, can't be simpler than that. Examples:
%QX0.0 = Modbus Coil Address 0
%QX0.7 = Modbus Coil Address 7
%QX1.2 = Modbus Coil Address 10

%QW4 = Modbus Holding Register Address 4
%QW98 = Modbus Holding Register Address 98

%MW2 = Modbus Holding Register Address 1026
%MW7 = Modbus Holding Register Address 1031

...and so on

I suggest you to try experimenting with Radzio Modbus. This will give you a better overview of what Modbus looks like. Download it on your PC and connect to OpenPLC, and start reading, writing some values
Reply 0 0
Rizwan Ahmed
This modbus adressing is still valid?
Because now adress is started from QX100.0
Reply 1 0
thiagoralves
It is valid. The I/O that is mapped to address 100 is only for slave devices. Local I/O (like raspberry pi GPIO pins) start at addres 0. And if you follow the sequence in the table, address 100 (for digital I/O) was and still is Modbus 800. 
Reply 0 0
cheeanbroday
I was just using AdvancedHMI with a program. My addresses seemed to be offset by 1.
QX100.0 = 0801
QX100.1 = 0802
QX100.2 = 0803
Reply 0 0
thiagoralves
This is because your HMI starts the addressing on 1 instead of 0. However, as per standard, Modbus/tcp addresses starts on 0
Reply 0 0
Rizwan Ahmed
thanks cheeanbroday, that helped me , I was connecting open PLC with WinCC explorer. @Thiagoralves there are different types of CPUz by Modicon, that use different addressings. 
Reply 0 0
JeffH
Advanced HMI addressing of DINT variables - set Modbus interface parameter Swapwords to True, and add ONE to the calculated address. e.g. for %MD201 set the PLC address to L42451. Reading and keyboard input now matches the Monitor screen.
Reply 0 0
Reply