24.09.2017, 04:41 (This post was last modified: 24.09.2017, 05:07 by buuuudzik.)
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 you
But last question(from my curiosity):
Is it has matter that first slave from master has an address 1 and second 2 etc. or not?
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
26.09.2017, 14:20 (This post was last modified: 26.09.2017, 14:24 by buuuudzik.)
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 timeouts How can I change timeout of every request on resident script?
-- 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)
(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 timeouts How can I change timeout of every request on resident script?
-- 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)
-- 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.
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.
27.09.2017, 06:17 (This post was last modified: 27.09.2017, 06:18 by buuuudzik.)
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.
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
27.09.2017, 10:56 (This post was last modified: 27.09.2017, 11:43 by buuuudzik.)
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
27.09.2017, 13:53 (This post was last modified: 27.09.2017, 14:25 by buuuudzik.)
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 point What I can improve in below script? (When I am changing timeout the interval is still the same)
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.
(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 Admin