Modbus4J Modbus RTU master
-
@hussam I downloaded the mango 2.5.2. But it just like another software that you can use to interact with the electrical device. How should I integrate the mango with my system ?
-
What is your end goal? What are you trying to accomplish? What system are you trying to get your power meter data into?
-
@jeremyh Hi Jeremy. My goal is to read the data in the Schneider Power Login meter. The value going to be store in the database. My system going to show the meter value. Its like the real time data. The system going to take the meter reading every 5 second and show the value in the system. My system using the Java Language and Spring framework.
Below is the example of my system interface.
-
To answer your question your PC would be the master and the power meter the slave. You would need to set a Slave ID in your power meter though with Modbus TCP sometimes this is not implemented and IP addresses are used instead of slave IDs.
Sometimes the server/client model is used in which case the power meter is your server, as it is serving the data (via a Modbus TCP Server), and the PC becomes the client.
How far along are you in your application?
It seems to me that it would be easier to make such a dashboard using the graphical views module of Mango, a DGLux dashboard (which would be the easiest, if your users dont mind running Flash) or a web interface using the API (maybe the hardest, but most future-proof).
Otherwise you will have to reinvent the wheel, there is a lot of stuff under the hood of mango to make sure it keeps working.
-
@jeremyh For me, it interface is not a problem. The problem right now is that, I am not able to read the data from the power meter. I also have done the TCP master. Below is the latest code that I try
ModbusFactory factory = new ModbusFactory(); IpParameters params = new IpParameters(); params.setHost("10.168.168.197"); params.setPort(502); params.setEncapsulated(false); ModbusMaster master = factory.createTcpMaster(params, true); // master.setRetries(4); master.setTimeout(2000); master.setRetries(0); long start = System.currentTimeMillis(); try { master.init(); ModbusLocator locator = new ModbusLocator(1, RegisterRange.HOLDING_REGISTER, 43111, DataType.TWO_BYTE_BCD); System.out.println("value: "+master.getValue(locator)); } finally { master.destroy(); } System.out.println("Took: " + (System.currentTimeMillis() - start) + "ms"); }
and the output of the coding is :
value: 8000
Took: 78mswhile there is no 8000 value at the power meter. Thank you.
-
From looking at the documentation for your power meter it appears that register 43111 is the second half of a four-byte float (which starts at register 43110) so you might just be reading the last two bytes. You should try reading from 43110 with DataType set to four byte float. If that doesn't give you the correct result try again from 43109 because some manufacturers start counting from 0 not 1.
-
@jeremyh actually some of my senior said that I suppose to add 40001 from its original register due to modbus protocol. I want to read the data from the register 3110 actually. In the documentation, the 3110 refer to the Frequency (Hz). That is my I get the 43111 register.
But I also try the 43110 and 43109 as you ask me to, but both the result is value: -4.5918E-41
-
Try using 3110 and and 3109 in your Java code then. Modbus4J is pretty 'smart' and probably makes such an adjustment for you.
You might like to get a modbus scanning application and run it on your PC to verify that the data is where you think it is, Mango has such a tool built in so if you have already installed Mango I would suggest using that. Just set up a Modbus TCP data source and use the Modbus read data function which will return the registers in Hex:
You can also try the 'point locator test', click the 'read' button and Mango will return the value it sees there.
-
@jeremyh Thank you so much jeremy. You really save my life. I try 3109 in my java code, and it show the correct value that I want. Thank you so much for helping me out. Can you explain more on how you get the 3109 value ? Why in the documentation it say that 3110 ?
God bless you Jeremy..
-
Modbus4J already does the 'subtract 40001' bit for you, so your colleague gave you a bit of misdirection there. It's still usually necessary if you are setting up a Modbus master in a PLC or something.
And some manufacturers start counting registers from 0 and some from 1, so sometimes (actually, often) what you think is register 3110 in your slave is 3109 according to your master.
A modbus scanner which shows you a whole bunch of registers is usually handy for figuring this out.
Just trial and error..
-
@jeremyh so what should I do next is, minus 1 from all the register that I want since it start count from 0 right ? Thank you so much again. Thank you for helping me around since the beginning.
-
Yes subtract 1 from all the registers in the documentation.
-
Out of curiosity are you logging all the data in a database on disk? Or just in memory to draw the graphs?
-
@jeremyh yaa, the data will be insert into the database every minute.
-
@jeremyh Hello Jeremy. Want to ask you one more question. I am not from the Electric background. So, I find a difficulty in calculating the power consumption of the meter. For you information, my system going to add the data in the database for every one minute. How am i going to calculate the power consumption for the device for a day (24 hours). I have Kw value for every minute.
Do I have to add the Kw value for every minute up to the whole day ?
Thank you.
-
Power (kw) is an instantaneous measurement. Energy (kWh), which is sounds like you want, is Power over Time. One kW of power being drawn for one hour is 1 kWh of energy. Half a kW for two hours is still 1 kWh.
To convert kW to kWh you would have to integrate the kW measurement i.e calculate the area under a plot of power over time. This is only as accurate as your measurement/sampling interval which is only 1 minute.
The real answer is to find the registers for cumulative energy (kWh and kVAh generally) in your meters and use that measurement to compute hourly/daily/annual kWh and kVAh energies. It will be a lot easier and a lot more accurate than trying to work it out yourself.
-
@jeremyh below is the sample of my database.
could you teach me how to calculate.
-
Just use the deltas. In energy/utility metering a 15 minute interval is generally used.
at 10:00am the MWh used was 122.858
at 10:15am the MWh used was 122.859122.859 - 122.858 = 0.001 MWh or 1kWh used in the 15 minute period.
Because you are measuring in MWh you lack the resolution to get tenths of kWh, so you should consider storing more decimals if you can, or reading from a kWh register if you can.
If that's not an option then you could integrate using the method/s discussed here: http://physics.stackexchange.com/questions/109295/calculating-kwh-from-time-series-of-kw
You could very crudely say that if the average demand over the 15 minute period is 4.75kW then the energy consumed in that 15 minute period (which is 1/4th of an hour) is (1/4 hours)*4.75 kWh = 1.1kWh.
-
Is it correct ? Do i need to sum all the KW and I will get the total consumption for an hour ?
(1/4 * 4.8) + (1/4 * 4.9) + (1/4 * 4.8) + (1/4 * 4.8) = 4.825 KWH
-
No. You would need to do:
(1/samples per hour) * (sum of kilowatts over period) = kilowatt-hours
i.e. (can't believe you made me type this):
(1/60) * (4.872+4.873+4.808+4.896+4.744+4.768+4.896+4.832+4.816+4.776+4.888+4.872+4.760+4.840+4.792) = 1.2kWh
This is honestly a really bad and dumb way to do this though. It is very inaccurate and if you miss any measurements your energy will be even further off. Just add the kWh register (rather than MWh) from your panel meter and calculate the difference every period - that is what it's there for!
If you ended up with 15-minute energy kWh then to get hourly energy you would just sum the kWh. Energy can be added to energy.