yurgen1975
Hi All
I have an openplc v3 running on linux server with Arduino Uno board connected as slave device.
Modbus commands are working perfect on addreses designed for slave devices IX%100.0 and etc (corresponding addresses of 800 in Modbus). all functions are ok, coils, registers and etc. including read/write..
The problem is with DNP3.
I enable DNP3 server, configure DNP3 HMI addresses in ScadaBR. The ScadaBR connects to the OpenPLC, see the log bellow:

Issued start_dnp3() command to start on port: 20000
DNP3 ID manager: Starting thread (0)
DNP3 ID DNP3_Server: Listening on: 0.0.0.0:20000
DNP3 ID DNP3_Server: Accepted connection from: 10.0.3.1

The problem is that i can't write/read to/from addresses starting at 800 (%100.0) which is address of my Arduino device (always "n/a" value), but can read/write to the addresses starting at 0 (%0.0)...

Is there any problem with DNP3 for slave devices?

Thanks for your support
Reply 0 0
yurgen1975
Hi again. I just realized that dnp3.cpp configured (recognizes) just addresses up to 800:
#define MAX_DISCRETE_INPUT 800
 #define MAX_COILS 800

How it can be changed and recompiled?
Reply 0 0
thiagoralves
That's a good finding. I modified the modbus addressing but forgot to modify the dnp3 one. Just change these two #defines to 8192 and then save the file. Next time you upload a new program, your changes will take effect
Reply 0 0
yurgen1975
Hi, many thanks for your reply.
Just tried to do what you said. Changed values of defines and saved dnp3.cpp. After I did re-compilation of "blank program.st", the same situation is persists (cannot work with addresses of the slave device)...
May be there is another place where some values should be updated. Anyway, when i write value (Binary Output -> LATCH_ON) from ScadaBR to address 800 or 801 i get the following message in log of OpenPLC, the value in ScadaBR is still "n/a":

DNP3 ID outstation: Not enough data for specified objects

Can you please take a look again in the code and instruct me what to do?

Thanks again for your support
Reply 0 0
yurgen1975
Hi,
Do you have any update? The slave device is not functional with DNP3...
Thanks
Reply 0 0
thiagoralves
It should work with these modifications on the #defines. Can you try using a different tool other than ScadaBR? It could be that DNP3 on ScadaBR is also broken
Reply 0 0
yurgen1975
I tried also XMasterSlave dnp3 version, it also not working. If you can suggest other tool I also can try
Reply 0 0
yurgen1975
Just tested it with Freyscada DNP3 Client simulator. The simulator reads available points from outstation automatically. What i can see is just 10 first points for each Binary I/Os and Analog I/Os (0-9). I connected to OpenPLC Modbus client simulator also. When i write from Modbus simulator to points 0-9 (of Analog and Binary Outputs) i see that values are updated in DNP3 client simulator. When I try write values via DNP3, the values are not updated and i get error in Freyscada (operation is not allowed).
Of course if i want to write to Arduino device i need addresses of 800 for Binary Inputs and Outputs which currently not implemented in DNP3 master code in OpenPLC (no such data points).
Reply 0 0
thiagoralves
I have never played much with DNP3 on OpenPLC (and I also am not the one who implemented it), however I was checking the dnp3.cfg file and I believe your answer could be there. You said that you can only see 10 points on the DNP3 client simulator, and I see that event_buffer_size and database_size are both set to 10. Try increasing these numbers and check if something changes.
Reply 0 0
yurgen1975

Hi

First of all thanks for your support! Your solution is working, but I have some comments (I performed a lot of tests in last two days).

Regarding dnp3 – the best software to test the dnp3 operation is Opendnp3 Simulator by Automatak (dnp3 driver used by OpenPLC was written by them, therefore is fully supported by their simulator)  

hxxxxs:// automatak.com/opendnp3/simulator/setup.msi

It’s a little bit  problematic idea to increase event_buffer_size and database_size to 900 (the way dnp3 push all values is different from Modbus, where only specific value is read by master – here outstation send all values at once, when get read request from the master) – therefore a lot of garbage send by the outstation, therefore I did some change in the software to support offsets. This change also allow user to read just required number of datapoints and also starting from 0…

 

I define additional optional parameters - offsets of 800 for Digital Outputs and Inputs, and offset of 100 for Analog Outputs and Inputs in dnp3.cfg file (in case the user have another offset it can be configured in the file, or it can be commented and work in way you mentioned in you last reply).

Then I read offset parameters in dnp3.cpp from dnp3.cfg and update or read relevant/corresponding values which implemented by slave device (Arduino or another)

I’m attaching both files for your reference (If you wish you can implement it into the next OpenPLC release)

 

 

Another problem I found, belongs to Modbus master, polling external slave device. In Analog Input (Input registers), the last register value is never read – the bug found in Modbus_master.cpp(line 465)

                    int return_val = modbus_read_input_registers(            mb_devices[i].mb_ctx, mb_devices[i].input_registers.start_address,

                                                                    mb_devices[i].input_registers.num_regs-1, tempBuff);

 

should be:

                    int return_val = modbus_read_input_registers(            mb_devices[i].mb_ctx, mb_devices[i].input_registers.start_address,

                                                                    mb_devices[i].input_registers.num_regs, tempBuff);

Reply 0 0
thiagoralves
Thank you for your contributions. Sorry for taking so long to reply, the last days have been crazy with Christmas, travels, etc...

I will push your DNP3 changes to github. About the Modbus changes, I will keep it the way it is now. The modbus configuration specifies the start address and the number of registers. This second parameter means the range of registers, which is not inclusive. For example, if the start_address is 0, and num_regs is 3, the Modbus driver should read registers 0, 1 and 2 (total of 3 registers), and not 0, 1, 2 and 3 (total of 4 registers). That's why line 465 has the -1 subtracting num_regs.
Reply 0 0
thiagoralves
yurgen1975 wrote:

Another problem I found, belongs to Modbus master, polling external slave device. In Analog Input (Input registers), the last register value is never read – the bug found in Modbus_master.cpp(line 465)

                    int return_val = modbus_read_input_registers(            mb_devices[i].mb_ctx, mb_devices[i].input_registers.start_address,

                                                                    mb_devices[i].input_registers.num_regs-1, tempBuff);

 

should be:

                    int return_val = modbus_read_input_registers(            mb_devices[i].mb_ctx, mb_devices[i].input_registers.start_address,

                                                                    mb_devices[i].input_registers.num_regs, tempBuff);



I'm sorry, you're absolutely right. I quickly read these lines without looking properly to the code, and I though that num_regs was inclusive in the function, but it is not. I don't know why the -1 was added there, because it was not there in the original code. I believe that one of the commits I pushed from suggestions here in the forum ended up adding the -1 and I didn't notice it. In fact, the -1 is wrong and shouldn't be there. I've fixed it now. Thanks for all the help!
Reply 0 0
yurgen1975
Hi Tiago, thanks for update, happy to help you.
I like this software, you did very impressive work!
Currently i'm working on implementation of OpenPLC on custom HW (my company have IIoT gateway). Is it possible officially add our HW to your website and to your github commits? If you wish to hear about the HW and the project, we can also discuss it privately.

Thanks again

Yuri
Reply 0 0
thiagoralves
Yes, definitely! There are three commercial devices officially supported by OpenPLC, I would be happy to add one more. Please let me know about your device, I might be able to help you adding support for that.

Also maybe in the future we can even join forces to design a low-cost PLC based on OpenPLC. I’ve been trying to do that for a while but never had enough free time to do it all by myself.
Reply 0 0
yurgen1975
Hi again,
Sent you an e-mail to your gmail address...
Yuri
Reply 0 0
Reply