Lookout

cancel
Showing results for 
Search instead for 
Did you mean: 

Access bit of words in Lookout

Is it possible to access individual bits of integer values using some type of Lookout tag reference? For example, I have a Lookout integer value tag called FT1001. I would like to access a particular bit from that word, without having to use an expression to extract it, by referencing the bit directly. I would expect it to be called FT1001.B01 or something like that. Any help would be appreciated.
0 Kudos
Message 1 of 5
(3,726 Views)

Here's my (edited) answer from an earlier post....  the licensing stuff may not apply in your case.. and the ModbusSlave solution should work with a non-driver tag as well:

Hi,

I would strongly advise against using any undocumented features, 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.  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?O...

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 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 😉

0 Kudos
Message 2 of 5
(3,712 Views)
Thanks Khalid, that is exactly what I was looking for.

As a follow up, would you be able to comment on the communication load a driver object endures when reading blocks of integers vs. blocks of bits? For example, is the load the same if reading 10 integer values vs. 160 bit values (assuming all memory is contiguous)? How would this degrade if the blocks were not contiguous? I am trying to evaluate how to design my application. I/O count is not an issue, will be using an unlimited license. But in either case there will be a high I/O count (estimating 3000+ points), to be scanned every 3 seconds via TCP/IP to a Siemens PLC, and I am trying to evaluate how best to minimize the communications load.

Thanks again for your help.
0 Kudos
Message 3 of 5
(3,702 Views)
I have used mathmatical terms IF, mod & trunc to extract bits from words.

general formula
IF(MOD(TRUNC(FT1001/Z)=1,TRUE,FALSE)
where Z=2^bit number. (constant to enter in formula)

EXAMPLES:
Zeroth bit would be
IF(MOD(TRUNC(FT1001/1)=1,TRUE,FALSE)
Second bit
IF(MOD(TRUNC(FT1001/4)=1,TRUE,FALSE)
16th bit
IF(MOD(TRUNC(FT1001/32768)=1,TRUE,FALSE)
0 Kudos
Message 4 of 5
(3,675 Views)
I have used mathmatical terms IF, mod & trunc to extract bits from words.

general formula
IF(MOD(TRUNC(FT1001/Z)=1,TRUE,FALSE)
where Z=2^bit number. (constant to enter in formula)

EXAMPLES:
Zeroth bit would be
IF(MOD(TRUNC(FT1001/1)=1,TRUE,FALSE)
Second bit
IF(MOD(TRUNC(FT1001/4)=1,TRUE,FALSE)
16th bit
IF(MOD(TRUNC(FT1001/32768)=1,TRUE,FALSE)
0 Kudos
Message 5 of 5
(3,675 Views)