This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

F&F LE-03MQ Modbus energy counter
#21
I will check how can I improve the topology, but unfortunately I wasn't the starter of modbus network and so because everything was working properly I wasn't searching for a bad topology. This is my first project with modbus. Thanks for your help, all of youSmile

But last question(from my curiosityWink):
Is it has matter that first slave from master has an address 1 and second 2 etc. or not?
Reply
#22
Hi,

No, order of addressing has no impact on the system.

BR,

Erwin
Reply
#23
Erwin, full documenation is not finished, but here are the most important functions:
Code:
mb:setslave(slaveid)
 Sets slave id to read/write data from/to

mb:readcoils(start, count) [01]
mb:readdiscreteinputs(start, count) [02]
mb:readregisters(start, count) [03]
mb:readinputregisters(start, count) [04]
 Reads one or many registers/coils from the start address
 Returns all values on success and nil, error description on error

mb:writebits(start, v1, [v2, [v3, ...]]) [05]
mb:writemultiplebits(start, v1, [v2, [v3, ...]]) [15]
mb:writeregisters(start, v1, [v2, [v3, ...]]) [06]
mb:writemultipleregisters(start, v1, [v2, [v3, ...]]) [16]
 Writes values to registers/coils from the start address
 Single write will be used when only one value is supplied, multiple write otherwise
 Returns all of values written on success and nil, error description on error
 Use writeregisters/writemultipleregisters to force writing using multiple
 coil/register write function even when writing to a single coil or register

mb:readregistervalue(address, datatype, [swap]) [03]
mb:readinputregistervalue(address, datatype, [swap]) [04]
 Reads encoded register(s) value based on the specified datatype:
   "int16" - signed 2-byte (1 register) integer
   "uint16" - usigned 2-byte (1 register) integer
   "float16" - 2-byte floating point (KNX format, used in some HVAC units)
   "int32" - signed 4-byte (2 registers) integer
   "uint32" - unsigned 4-byte (2 registers) integer
   "float32" - 4-byte (2 registers) floating point (IEEE 754)
   "int64" - signed 8-byte (4 registers) integer
   "uint64" - unsigned 8-byte (4 registers) integer
   "float64" - 8-byte (4 registers) floating point (IEEE 754)
 Optionally, it`s possible to swap register/byte order
 Default value is word (2-byte) swap
 Possible string values: n (no swap), w (word swap), b (byte swap), bw (byte and word swap)
  Returns value on success and nil, error description on error

mb:writeregistervalue(address, value, datatype, [swap]) [06/16]
 Writes encoded value to register(s) based on the specified datatype:
   "int16" - signed 2-byte (1 register) integer
   "uint16" - usigned 2-byte (1 register) integer
   "int16m" - signed 2-byte (1 register) integer, force multiple write
   "uint16m" - usigned 2-byte (1 register) integer, force multiple write
   "float16" - 2-byte floating point (KNX format, used in some HVAC units)
   "int32" - signed 4-byte (2 registers) integer
   "uint32" - unsigned 4-byte (2 registers) integer
   "float32" - 4-byte (2 registers) floating point (IEEE 754)
   "int64" - signed 8-byte (4 registers) integer
   "uint64" - unsigned 8-byte (4 registers) integer
   "float64" - 8-byte (4 registers) floating point (IEEE 754)
 Optionally, it`s possible to swap register/byte order
 Default value is word (2-byte) swap
 Possible string values: n (no swap), w (word swap), b (byte swap), bw (byte and word swap)
  Returns number of values written on success and nil, error description on error

mb:reportslaveid()
 Reads slave internal data
 Returns values on success and nil, error description on error
Reply
#24
I've changed the connection to serial and also I've tried connect terminators 120ohm on the start and at the end of the bus and still there are a lot of timeouts. Now I've connected this only energy meter to the RS-485-2 (very short distance ~5m) and I am trying read values from it via resident script but also there are a lot of timeoutsSad How can I change timeout of every request on resident script?

This is what I am using now for testing:
Code:
require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485-2', 9600, 'N', 8, 1, 'H')
mb:connect()
mb:setslave(4)

-- L1 - N
-- read 32-bit floating point value from input register nr 123, use word swap
res, err = mb:readinputregistervalue(0, "float32", "w")
log(res, err)

-- L2 - N
res, err = mb:readinputregistervalue(2, "float32", "w")
log(res, err)

-- L3 - N
res, err = mb:readinputregistervalue(4, "float32", "w")
log(res, err)

mb:close()

Attached Files Thumbnail(s)
   
Reply
#25
(26.09.2017, 14:20)buuuudzik Wrote: I've changed the connection to serial and also I've tried connect terminators 120ohm on the start and at the end of the bus and still there are a lot of timeouts. Now I've connected this only energy meter to the RS-485-2 (very short distance ~5m) and I am trying read values from it via resident script but also there are a lot of timeoutsSad How can I change timeout of every request on resident script?

This is what I am using now for testing:
Code:
require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485-2', 9600, 'N', 8, 1, 'H')
mb:connect()
mb:setslave(4)

-- L1 - N
-- read 32-bit floating point value from input register nr 123, use word swap
res, err = mb:readinputregistervalue(0, "float32", "w")
log(res, err)

-- L2 - N
res, err = mb:readinputregistervalue(2, "float32", "w")
log(res, err)

-- L3 - N
res, err = mb:readinputregistervalue(4, "float32", "w")
log(res, err)

mb:close()

Hi 
What happen when you read only 1 registry? 
What kind of cable do you use? 
Which LM is it?
BR
Reply
#26
For such script there are also from time to time timeouts:
Code:
require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485-2', 9600, 'N', 8, 1, 'H')
mb:connect()
mb:setslave(4)

-- L1 - N
-- read 32-bit floating point value from input register nr 123, use word swap
res, err = mb:readinputregistervalue(0, "float32", "w")
log(res, err)

mb:close()

I am using KNX cable A-red, B-black.

This is LM4, but other Modbus-RTU devices are working correctly. I am thinking that this is probably an issue of energy meter or its modbus part is little unique.

Attached Files Thumbnail(s)
   
Reply
#27
If other modbus devices works correctly then for sure issue is with this meter. In the past I had similar issue with some Chines fancoil. It was not answering 100% but as long I was getting every second value I ignored it.
Reply
#28
Have you connected GND between LM and slave devices?
Reply
#29
How can I change the timeout?

(26.09.2017, 15:16)admin Wrote: Have you connected GND between LM and slave devices?

This is only 1 device and 5 meter and 9600baud/s so it should be not a problem.
Reply
#30
It won't hurt to try Smile
Reply
#31
(26.09.2017, 15:49)admin Wrote: It won't hurt to try Smile

But this energy meter hasn't GND. I will contact with some technic from this company.

But if you can tel me Admin how can I change the timeout? I've tries mb:timeout(1) but it is not working
Reply
#32
Timeout is set like this:
Code:
mb:setresponsetimeout(1)

You can also try increasing byte timeout, but I'm not sure if this will help:
Code:
mb:setbytetimeout(1)
Reply
#33
I've optimized communication with this meter and now script is trying max 7 times read the register. Min. time to read all registers(or spending 7 times to try) i 7s and maximum 16s. Today I will try contact with the manufacturer.

Code:
require('json')
require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485-2', 9600, 'N', 8, 1, 'H')
mb:connect()
timeout = 0.05
mb:setresponsetimeout(timeout)

mb:setslave(4)


energyMeters = [[
{
 "manufacturer": "F&F",
 "description": "Licznik energii LE-03MQ",
 "mapping": [
    { "address": 0, "name": "Napięcie fazowe L1", "delta": 2 },
    { "address": 2, "name": "Napięcie fazowe L2", "delta": 2 },
    { "address": 4, "name": "Napięcie fazowe L3", "delta": 2 },
    { "address": 6, "name": "Natężenie prądu L1", "delta": 0.5 },
    { "address": 8, "name": "Natężenie prądu L2", "delta": 0.5 },
    { "address": 10, "name": "Natężenie prądu L3", "delta": 0.5 },
    { "address": 12, "name": "Moc czynna L1", "delta": 50 },
    { "address": 14, "name": "Moc czynna L2", "delta": 50 },
    { "address": 16, "name": "Moc czynna L3", "delta": 20 },
    { "address": 24, "name": "Moc bierna L1", "delta": 50 },
    { "address": 26, "name": "Moc bierna L2", "delta": 50 },
    { "address": 28, "name": "Moc bierna L3", "delta": 50 },
    { "address": 30, "name": "Współczynnik mocy L1", "delta": 0.01 },
    { "address": 32, "name": "Współczynnik mocy L2", "delta": 0.01 },
    { "address": 34, "name": "Współczynnik mocy L3", "delta": 0.01 },
    { "address": 52, "name": "Całkowita moc układu", "delta": 50 },
    { "address": 60, "name": "Całkowita moc bierna układu", "delta": 50 },
    { "address": 62, "name": "Współczynnik mocy układu", "delta": 0.01 },
    { "address": 70, "name": "Częstotliwość napięć zasilania", "delta": 0.25 },
    { "address": 200, "name": "Napięcie międzyfazowe L1-L2", "delta": 2 },
    { "address": 202, "name": "Napięcie międzyfazowe L2-L3", "delta": 2 },
    { "address": 204, "name": "Napięcie międzyfazowe L3-L1", "delta": 2 },
    { "address": 224, "name": "Prąd przewodu zerowego", "delta": 1 },
    { "address": 234, "name": "Współczynnik zawartości harmonicznych napięcia L1-N", "delta": 1 },
    { "address": 236, "name": "Współczynnik zawartości harmonicznych napięcia L2-N", "delta": 1 },
    { "address": 238, "name": "Współczynnik zawartości harmonicznych napięcia L3-N", "delta": 1 },
    { "address": 240, "name": "Harmoniczne prądu fazy 1", "delta": 1 },
    { "address": 242, "name": "Harmoniczne prądu fazy 2", "delta": 1 },
    { "address": 244, "name": "Harmoniczne prądu fazy 3", "delta": 1 },
    { "address": 334, "name": "Harmoniczna napięcia międzyfazowego L1-L2", "delta": 1 },
    { "address": 336, "name": "Harmoniczna napięcia międzyfazowego L2-L3", "delta": 1 },
    { "address": 338, "name": "Harmoniczna napięcia międzyfazowego L3-L1", "delta": 1 },
    { "address": 342, "name": "Całkowita energia czynna", "delta": 0.1 },
    { "address": 344, "name": "Całkowita energia bierna", "delta": 1 }    
 ]
}]]

energyMeters = json.decode(energyMeters)
meterName = 'Licznik 1 - '

function readRegister(meterName, address, name, delta)
 for i = 1, 7, 1 do
   res, err = mb:readinputregistervalue(address, "float32", "w")
   if res then
       GA = meterName .. name
         value = math.round(res, 2)
     grp.checkwrite(GA, value, delta)
     break
   end
 end
end

for k,meter in pairs(energyMeters.mapping) do
 readRegister(meterName, meter.address, meter.name, meter.delta)
end


mb:close()
Reply
#34
I've talked with some technic guy from F&F and he asked me if I can check this issue via Modbus Pool and some RS485 converter.

And when I've tried this in Modbus Pool Software via very cheap(~4$) chinese converter everything works great. Below screenshots:

How can I mount the usb-RS485 converter to LM LB? This is ch340 converter. Below data from System log after plug the device:


usb 1-1.3: Product: USB2.0-Serial
usb 1-1.3: New USB device strings: Mfr=0, Product=2, SerialNumber=0
usb 1-1.3: New USB device found, idVendor=1a86, idProduct=7523
usb 1-1.3: new full-speed USB device number 8 using ehci-pci


I've found also this article:
http://blog.lincomatic.com/?p=1616

Attached Files Thumbnail(s)
               
Reply
#35
1) I've tried also with switching on Modbus mapper, and after this, reading all of this registers takes only 4 seconds so I see that other RS-485 inputs are connected with themselves.

2) When I switched on the Modbus mapper then still reading the registers via script takes 3-5 seconds. It is enough, but if there would be a possibility to go down to 1 second it would be great from the learning pointWink What I can improve in below script? (When I am changing timeout the interval is still the same)

Code:
start = os.microtime()

require('json')
require('luamodbus')
mb = luamodbus.rtu()
mb:open('/dev/RS485-2', 9600, 'N', 8, 1, 'H')
mb:connect()
timeout = 0.020
mb:setresponsetimeout(timeout)
mb:setslave(4)


energyMeters = [[
{
 "manufacturer": "F&F",
 "description": "Licznik energii LE-03MQ",
 "mapping": [
    { "address": 0, "name": "Napięcie fazowe L1", "delta": 2 },
    { "address": 2, "name": "Napięcie fazowe L2", "delta": 2 },
    { "address": 4, "name": "Napięcie fazowe L3", "delta": 2 },
    { "address": 6, "name": "Natężenie prądu L1", "delta": 0.5 },
    { "address": 8, "name": "Natężenie prądu L2", "delta": 0.5 },
    { "address": 10, "name": "Natężenie prądu L3", "delta": 0.5 },
    { "address": 12, "name": "Moc czynna L1", "delta": 50 },
    { "address": 14, "name": "Moc czynna L2", "delta": 50 },
    { "address": 16, "name": "Moc czynna L3", "delta": 20 },
    { "address": 24, "name": "Moc bierna L1", "delta": 50 },
    { "address": 26, "name": "Moc bierna L2", "delta": 50 },
    { "address": 28, "name": "Moc bierna L3", "delta": 50 },
    { "address": 30, "name": "Współczynnik mocy L1", "delta": 0.01 },
    { "address": 32, "name": "Współczynnik mocy L2", "delta": 0.01 },
    { "address": 34, "name": "Współczynnik mocy L3", "delta": 0.01 },
    { "address": 52, "name": "Całkowita moc układu", "delta": 50 },
    { "address": 60, "name": "Całkowita moc bierna układu", "delta": 50 },
    { "address": 62, "name": "Współczynnik mocy układu", "delta": 0.01 },
    { "address": 70, "name": "Częstotliwość napięć zasilania", "delta": 0.25 },
    { "address": 200, "name": "Napięcie międzyfazowe L1-L2", "delta": 2 },
    { "address": 202, "name": "Napięcie międzyfazowe L2-L3", "delta": 2 },
    { "address": 204, "name": "Napięcie międzyfazowe L3-L1", "delta": 2 },
    { "address": 224, "name": "Prąd przewodu zerowego", "delta": 1 },
    { "address": 234, "name": "Współczynnik zawartości harmonicznych napięcia L1-N", "delta": 1 },
    { "address": 236, "name": "Współczynnik zawartości harmonicznych napięcia L2-N", "delta": 1 },
    { "address": 238, "name": "Współczynnik zawartości harmonicznych napięcia L3-N", "delta": 1 },
    { "address": 240, "name": "Harmoniczne prądu fazy 1", "delta": 1 },
    { "address": 242, "name": "Harmoniczne prądu fazy 2", "delta": 1 },
    { "address": 244, "name": "Harmoniczne prądu fazy 3", "delta": 1 },
    { "address": 334, "name": "Harmoniczna napięcia międzyfazowego L1-L2", "delta": 1 },
    { "address": 336, "name": "Harmoniczna napięcia międzyfazowego L2-L3", "delta": 1 },
    { "address": 338, "name": "Harmoniczna napięcia międzyfazowego L3-L1", "delta": 1 },
    { "address": 342, "name": "Całkowita energia czynna", "delta": 0.1 },
    { "address": 344, "name": "Całkowita energia bierna", "delta": 0.1 }    
 ]
}]]

errors = 0

energyMeters = json.decode(energyMeters)
meterName = 'Licznik 1 - '

function readRegister(meterName, address, name, delta)
 for i = 1, 7, 1 do
   res, err = mb:readinputregistervalue(address, "float32", "w")
   if res then
       GA = meterName .. name
         value = math.round(res, 2)
     grp.checkwrite(GA, value, delta)
     break
   else
     errors = errors + 1
   end
 end
end

for k,meter in pairs(energyMeters.mapping) do
 readRegister(meterName, meter.address, meter.name, meter.delta)
end


mb:close()


developmentInfo = false


if developmentInfo then
log('Duration: ' .. os.microtime()-start .. 's, ' .. errors .. 'errors')
end



If it is about LM Load Balancer please provide some example how can I mount RS-485<>USB converter ch340.

http://blog.lincomatic.com/?p=1616
Reply
#36
CH340 is not currently supported by LB, but support can be added in next FW release.
Reply
#37
(02.10.2017, 06:38)admin Wrote: CH340 is not currently supported by LB, but support can be added in next FW release.

Please add this device because it is an alternative for ftdi chip and not everytime in datasheet there is the information what kind of chip is used. Thanks AdminWink
Reply
#38
It looks that I have switched on other script which was use the RS-485, it was only connected, not send nothing, but this was the cause of errors.

But after checking this was not the case, and still there are a lot of errors while readingSad
Reply


Forum Jump: