EMoncenis
Hi everyone,

Fisrt of all, congratulations for the work done on openPLC.

I run OpenPLC on a windows 10 mini-computer and with a USB-RS485 converter and Modbus RTU, i communicate with a frequency inverter.

I made some tests with CASModbusScanner to be sure that the frequency converter responds well to modbus rtu protocol. 

But i have some problems : 
(1) - I would like to have access to data of the frequency inverter but in the Slave Devices panel of the openPLC Runtime, i can only access to the Holding Registers - Read address.
Furthemore, I would like to have access to several data of the frequency inverter but there is a "gap" in the hexadecimal address of the frequency inverter (like you can see on the following pictures). How can i do to have access to the 2000h and 3000h address for example ?

Frequency_inverter_1.png  frequency_inverter_2.png 


(2) On the same computer, I also want to use ScadaBR for a HMI interface : I guess it's possible following this post : https://openplc.discussion.community/post/error-using-scadabr-for-openplc-server-9506871 and use Modbus IP with host address : 127.0.0.1. 
When i try it, i can see a lot of Modbus scan nodes creates (240 in the following picture) and don't really understand why..scadaBR.png 
Any help will be appreciated,
Thanks in advance
Edouard
Reply 0 0
Szmita

I cant help you, buy maybe you can find some thing helpful here:

https://openplc.discussion.community/post/big-update-with-new-cool-features-8173271?trail=30#28

Reply 0 0
EMoncenis
Hello,

Thank you for your help, ScadaBR is now working fine !

But i am still stuck with the address gap problem...
Reply 0 0
thiagoralves
Try creating multiple slave devices pointing to the same device, but each one attaching to a different "segment" of the address space
Reply 0 0
EMoncenis
Thank you for your response Thiago.

I will try it and keep you in contact.

By the way, i have an other question :
-I made several tries with two others modules :
  • Wallpro WP3066ADAM : acquisition module for temperature sensor DS18B20
  • Wallpro WP8028ADAM : acquisiont module for 8 Digitial Input and 8 Digital Output

So i created two devices slaves : Wallpro_8DI/8DO and Wallpro_8DS18B20 with the following settings :
 
  8DI8DOSettings.png 
    
8DS18B20Settings.png 


When i have this configuration (Wallpro_8DI/8DO first in the list) :

config1.jpg 

I can observe this log and only this first module works : 
Log1.jpg    
works1.jpg 

In the other hands, when i changed the configuration (Wallpro_8DS18B20 first in the list), it acts in the opposite direction : 

config2.jpg 
Log2.jpg 
works2.jpg 

So just the first module in the list works... I don't know how to solve this problem.

Any idea will be appreciated,
Thanks in advance,

Edouard 
Reply 0 0
thiagoralves
Oh, this is a bug. OpenPLC tries to connect to both devices, but since they are on the same COM port (just different slave IDs), when it tries to connect to the second one, it gets a permission denied because that COM port is already being used by the first device. If you know a little bit of C code you can try to fix this at /OpenPLC_v3/webserver/core/modbus_master.cpp. I'll try to check that as well to come up with a fix, but my time is limited and I don't have any serial RS485 modbus device to test.
Reply 0 0
EMoncenis
Thanks for the explication, i will try to fix it
Reply 0 0
thiagoralves
Just a quick hint if you’re working on this, once you modify any .cpp file on OpenPLC you need to recompile your program to see the changes. You don’t have to recompile the whole OpenPLC Runtime, just the PLC program is enough. You can do that on the web interface, just launching the same program again (Programs -> select a program -> Launch)
Reply 0 0
EMoncenis
Hi Thiago,

I have a little question : are you sure the problem is inside the modbus_master.cpp file ? 
If i don't make a mistake, the problem is due to the boolean argument isConnected ? But it may also be a problem due to the function modbus_connect but i can't find the declaration of this one...
If you have a lead or an idea, that would be great ! 
Thanks in advance,     modbus_master_1.jpg 
Reply 0 0
thiagoralves
modbus_master.cpp uses libmodbus to perform all modbus operations. You can check libmodbus documentation here:  https://libmodbus.org/documentation/
Reply 0 0
thiagoralves
Sorry for the double-post, but I think it is wise to add that perhaps the only change you will have to make is to check if devices have the same COM port on the devices list that is assembled after parsing the config file. If they have the same COM port, perhaps you will have to add a flag as a complimentary device, and associate the isConnected variable to just the primary device, which means that if the primary device is connected, the second device should be connected as well, because they are on the same COM port. Also, there is a call on libmodbus that changes the device ID for a given context. You will have to call that as well, because for devices that are connected to the same COM port, the only difference is their device ID. So you will have to set this every time you talk to each of these "complimentary" devices
Reply 0 0
EMoncenis
Thank you for the precision about libmodbus.

Little question, Is the mbconfig.cfg the file you are talking about ?  mbconfig.jpg 

Do you think that the problem is here because i am using the Windows version of the OpenPLC software ? Or the same things occurs with Linux ?

Update : yes, the mbconfig.cfg is the config file. But, i have an other question what exactly is mb_ctx and how is it determinate ?

Thanks for your time 😊
Reply 0 0
thiagoralves
OpenPLC for Windows and Linux behave in the same way. It is the same code for both. The mbconfig file is generated automatically by the webserver when you add devices on the Slave Devices page. About mb_ctx, it is the main libmodbus structure that holds information about the modbus device you want to connect to. You can read more about it on libmodbus documentation:  https://libmodbus.org/docs/v3.0.8/ (read section Contexts). About my previous message, you probably will have to use  https://libmodbus.org/docs/v3.0.8/modbus_set_slave.html to change the SlaveID of the given mb_ctx device that uses the same COM port.
Reply 0 0
EMoncenis
Hi Thiago,

I hope you doing well, i would like to thank you again for your quick response and your help.

With your help, i could make some modification in the modbus_master.cpp file and now this is working fine !!!

I put here the file if it could help someone.
Warning : If you want to use it,  you must declare devices communicate via the same port on the "slaves devices" tab one below the other

Modification : 
modif.jpg 
Reply 0 0
thiagoralves
This is great. Thanks for the contribution. I would just change the first if to be a for loop searching the whole mb_devices array checking if there is any other device with the same dev_address. If I find one, I would proceed with your code as it is and end the for loop with break. If I can't find one, then all goes as usual. This logic would eliminate the need for devices on the same port having to be one below the order, and would also allow multiple devices (more than 2) to be sharing the same port as well.
Reply 0 0
Reply