MODBUS Libraries
Hi all,
I've been using Industruino implementing Modbus RTU in a couple of projects. Everythings work fine. But now I'm trying to use Modbus in a new application and I have not succeded until now.
I guess that the problem could be the offset of the registers in the slave, but is not possible for me to check it. I us the SimpleModbusMaster Library, wich has no error management. I found another library simplemodbusng that has the error management, but that it doesn´t allow me to change Serial to Serial1. I've tryied to edit this second library to include Srialport selection, but everything was a mess (I'm not a programmer) and the scketch is not compiling.
The question: do you know any library that include error managment for RTU and support Serial1 choice?
I'm specially interested in wrong adress, wrong id and wrong data type.
Thanks a lot in advance.
Finally I could manage to modify the library to store the frame[x] values in the register matrix that, when an error is returned, contain the type of error (together with more information). So I could ensure that the modbus Id I was using was ok.
Now my problem is different. In this project I read the modbus registers of a Fronius PV Inverter in order to manage the excess energy for Off-grid PV installations. This is something that I've been doing for a long time and everything is ok. Now I want to implement another device, which is a Fronius Energy Meter in a specific point of the electricity installation (this is the device I had problems with), in order to have more details of the energy flow. This Fronius Meter is fully compatible with the Fronius Inverter when the inverter is the Master (I have installed some of these systems and they communicate via Modbus RTU with no problem). But in my case both, Fronius Meter and Fronius Inverter must be slaves and Industruino the Master.
To convert the paremeter of the inverter I use the "union Pun {float ModbusFloat; uint32_t ModbusInt;}; "+"union Pun pun;"+ "pun.ModbusInt = ((uint32_t)regs[0] << 16) | regs[1];Power = pun.ModbusFloat;" method, and everything is great. But doing the same with the Fronius Meter is not working (For instance, for real Power = 1470 W I get reg[0] =2 and reg[1]=1676, whic is a calculated P<0.01 W). I'm not sure if the problem could be that the registers from the Smart Meter could be signed integer while the registers from the Inverter are unsigned integer... not sure.
The rest of thigs are great. With Industruino and Blynk I have now a real nice device, even with a (private by now) skill for Alexa. It's great Industruino and all its capacities.
Hi again, Tom,
I tried that method with a 1286 Industruino under 1.6.5 IDE and everything was ok. But when testing in my other industruinos with 1.8.5 IDE release I had compilation issues. I solved it by doing the next thing:
Before setup:
union Pot {long ModbusL; uint16_t Modbusi[2];};
In loop:
union Pot pot;
PotenciaConsumida = 0;
pot.Modbusi[0] = regs[1];
pot.Modbusi[1] = regs[0];
PotenciaConsumida = (pot.ModbusL)/100;
Maybe you could test it and update your post about Modbus tips.
Best regards
Joaquín Murillo
Telf.: (+34) 661456149
From: Tom <tomtobback@gmail.com>
Sent: jueves, 20 de junio de 2019 1:07
To: Joaquín Murillo <jmurillo@krentec.com>
Subject: Re: MODBUS Libraries (786)
thanks for the feedback. we have some examples for modbus register conversion at https://industruino.com/blog/our-news-1/post/modbus-tips-for-industruino-26
--
Tom
Sent by Industruino using Odoo
Hi, indeed that is a rather simple library as the name suggests, but there are ways to diagnose errors by checking the attributes of the packet struct. Have a look at SimpleModbusMaster.h to see the attributes, maybe that already helps to find .
connection, retries, failed_requests, exception_errors
This should enable you to at least find out if you are using the correct Slave ID.
For slave registers, if you are using function READ_HOLDING_REGISTERS and the slave doc says e.g. register 40101 then that should be register 100 in the SimpleModbusMaster modbus_construct (common offset is 40001 as far as i understand)
Finally I could manage to modify the library to store the frame[x] values in the register matrix that, when an error is returned, contain the type of error (together with more information). So I could ensure that the modbus Id I was using was ok. Now my problem is different. In this project I read the modbus registers of a Fronius PV Inverter in order to manage the excess energy for Off-grid PV installations. This is something that I've been doing for a long time and everything is ok. Now I want to implement another device, which is a Fronius Energy Meter in a specific point of the electricity installation (this is the device I had problems with), in order to have more details of the energy flow. This Fronius Meter is fully compatible with the Fronius Inverter when the inverter is the Master (I have installed some of these systems and they communicate via Modbus RTU with no problem). But in my case both, Fronius Meter and Fronius Inverter must be slaves and Industruino the Master. To convert the paremeter of the inverter I use the "union Pun {float ModbusFloat; uint32_t ModbusInt;}; "+"union Pun pun;"+ "pun.ModbusInt = ((uint32_t)regs[0]
Your answer
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
Keep Informed
About This Forum
This community is for professionals and enthusiasts of our products and services.
Read GuidelinesQuestion tools
Stats
Asked: 6/14/19, 5:26 PM |
Seen: 2579 times |
Last updated: 6/18/19, 5:27 PM |
thanks for the feedback. we have some examples for modbus register conversion at https://industruino.com/blog/our-news-1/post/modbus-tips-for-industruino-26