Extracting bit data from Modbus registers
-
I am working with a MangoES Box with Mango 3.x upgrade. I am trying to figure out how to manipulate a 16 bit data word that I get via modbus from a PLC. The issue is that the 16 bits of the data are flag/binary data, not numeric. I need to be able to sort messages to post to the screen based on which bits (one or more at a time) are a "1" or "0".
For example, Bit 12 indicates the device is RUNNING, bit 1 indcates the device is working nomally, others bits indicate alarms or warnings, etc. Are there any examples or information available on this. I have searched for bit mapped data word in the forum and came up empty. I am using both Chrome and Firefox latest version browsers.
Thanks,
Tracey -
This post is deleted! -
Hi Tracey,
Yes! This is possible. The easiest way is to set the data type for the point to binary, and then assign it a bit position.
Alternatively you could read any integer data type (probably unsigned two byte integer is the most sensible) and then do bit masking in JavaScript, whether meta points or point links.
-
That works. I think the only issue with doing this type of data acquisition (vs manipulation using JS) is that the number of bus transactions increases for all the bits desired to observe in that data word.(ie: 16 bus transactions to be able to observe each of the 16 different bits). I understand where to go from here on this. Thank you.
Tracey -
Is there a way to take the word data and put into a virtual data so that mango can act on it "locally/virtualy" in a bit wise fashion without additional data cycles across the bus (modbus) over and over?
Tracey -
Have you actually confirmed that it takes another trip across the modbus for each bit? I would not expect that to be how it functions. It should make a near minimum number of requests for less than the maximum read registers per request. The actual code for segmenting the modbus request is open source, but not overly obvious, if you would like me to link it for you.
Edit: but to answer your question. Yes, you can use a two byte unsigned integer as the data type, then use point links, meta points or scripts to use bit operations on it.
-
I'm with Phillip on this and if you are reading bits in a holding register Mango will do one read for the holding register and get all 16 bits at once or more as it might read multiple registers. There are some setting for this on the data source but Mango pretty much always uses the most efficient method for asking for data even if that means asking for more than it needs and disregarding data other than what you have specified in data points.
-
That being the case, it should allow me to do lots of bit banging very quickly. I need to gather about 60 words of data from each PLC (2 plcs) and then show the numeric or bit field representation. Thank you for the explanation that Mango buffers the data for quicker access between scans.
Tracey