
Posted: 2014-10-07 01:18 AM . Last Modified: 2024-07-15 12:05 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
AN003_SL - Modbus Power meters and spaceLYnk
Reading basic and complete Modbus parameters from Acti9 Power meters via LUA scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Hi Darya,
I've tried your scripts and they work fine.
No I've tried to modify the script for reading values of other power meters like PM800. But against what is written in your AN I can't find supported datapoint formats like Int16 and Int32, only UInt16 and UInt32. Please can you give me a hint, how I will have to modify the script to support signed integers (I can read all the values from the PM800, but negative values are showed as unsigned values e.g. -1 -> 32767)?
Thanks
Daniel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Hi Daniel,
Darya is not available till wednesday, so here is your answer. Extend your library MbPwmRTU.TYPES definition for these types:
Int16 = {
size = 1,
deltaFunct = 5,
-- function to read value from modbus registed
read = function(mb, address, regsize, debug)
local ret = MbPwmRTU.mbRead(mb, address, regsize or MbPwmRTU.TYPES.UInt16.size, debug)
return bit.band(ret, 0x7fff) * ((bit.rshift(ret, 15) == 0) and 1 or -1)
end,
},
Int32 = {
size = 2,
deltaFunct = 5,
-- function to read value from modbus registed
read = function(mb, address, regsize, debug)
local v1, v2 = MbPwmRTU.mbRead(mb, address, regsize or MbPwmRTU.TYPES.UInt32.size, debug)
return (bit.lshift(bit.band(v1, 0x7fff), 16) + v2) * ((bit.rshift(v1, 15) == 0) and 1 or -1)
end,
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Hi Jaroslav,
Thanks a lot for your support. Unfortunately it didn't work that way, so I had to modify your script a little bit like this:
Int16 = {
size = 1,
deltaFunct = MbPwmTCP._numDeltaFunct,
-- function to read value from modbus registed
read = function(mb, address, regsize, debug)
local ret = MbPwmTCP.mbRead(mb, address, regsize or MbPwmTCP.TYPES.UInt16.size, debug)
return bit.band(ret, 0x7fff) + ((bit.rshift(ret, 15) == 0) and 0 or -32768)
end,
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Yes, you are right, I see it now, really sorry for misleading you.
It happens when you are used to work mostly with scripting languages and coding and writing to forum when asleep.
