Lookout

cancel
Showing results for 
Search instead for 
Did you mean: 

bit masking

I need access to the individual bit status of a 32 bit register. I know about the undocumented getbit function but not its exact form. Are there any other ways of performing bit masking.
0 Kudos
Message 1 of 2
(2,950 Views)
"Hi,

I would advise against using the undocumented feature, because of that fact. Its support may at any time be dropped. As it is undocumented, NI does not have an obligation to continue supporting it.


Anyways, one (legal) way of getting the individual bits of a number is to use the ModbusSlave Object. The ModbusSlave object, normally, is used to turn the process into a virtual Modbus RTU. However, as a side benefit, we can use its datamembers to get the bits of a number.


The datamembers H4xxxx.fx give us the individual bits for the register 4xxxx. So, to get the bits of a number, you would first connect it to say, ModbusSlave1.40001. Then, reading the ModbusSlave1.H40001.f1 through ModbusSlave1.H40001.f16 would give its 16 bits as logical values.


Similarly, ModbusSlave1.H42345.f8 would give you the 8th bit of the number connected to register ModbusSlave1.H42345, for example.


For 32-bit integer numbers (as in your case), you would wire the number to the "D" registers. Like, ModbusSlave1.D40001, etc. And then read the two adjacent "H" registers, giving 16 bits each to make up the 32-bits. So, you would read ModbusSlave1.H40002.fx (for bits 0-15) and ModbusSlave1.H40001.fx (for bits 16-31).


Hope this makes sense. I am attaching a demo LKS file which shows this. (Open this from the File>>Open menu, and select LKS as the file-type.)


For 32-bit floating point numbers, you would use the "F" registers. But since the 32-bit floating point numbers are implemented as per the IEEE format, getting the indivdual bits is much more involved. See the following KB articles for details:


http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/2de82ef20b2cc991862567f600432e33?OpenDocument


http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/4ef459f549fcc7028625660a000a7629?OpenDocument


Hope this helps.


Regards,


Khalid


ps: Just in case one is wondering why wouldn't NI implement such a simple feature within Lookout: since Lookout pricing is based on IO points, such a "getbit" feature could be potentially misused to avail more IO points than what is paid for (could end-up getting 16 IO points for the price of one!). NOTE: the ModbusSlave does add to the IO points; hence is a "legal" solution 😉
Message 2 of 2
(2,950 Views)