LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Boolean values from file

I am attempting to read in boolean values from a spreadsheet file, where each row is an 8 bit boolean array represented by 0s and 1s
eg.
10110101
00110100
...

When I read from spreadsheet file, it interprets the numbers as integers. Although there is a Boolean to 0,1 function, I cannot seem to find the reverse. Is there a better way to go about this? Thanks in advance.
0 Kudos
Message 1 of 9
(3,737 Views)
You can use the "Not Equal To 0" function in the Comparison palette. If you input a 0 you get a false boolean, if you input a 1 then you get a true boolean. Is this what you are looking for?

Brian
Message 2 of 9
(3,737 Views)
It's not quite what I need. I'll try to give you some more detail. The file I'm taking my values from is a .txt with each 8-character number separated by a EOL. So when the file has:

11101011
01001011

I want to use the data 235d, 75d. But what I get is 11 million, 101 thousand and 11, etc.
I need to take each digit individually and convert it to a boolean, with groups of 8 digits (one line) making up a 8 element boolean array, or even the decimal equivalent, such as 235d, 75d as in the example above.

Thanks for your previous answer, and I look forward to hearing from you again.
0 Kudos
Message 4 of 9
(3,737 Views)
Then you can use the Scan From String function in the String palette. Wire each line into Input String and %b into Format String. The output will be your number.

See vi attached to a reply I'll make to my original answer. I think this'll do the trick.

Brian
0 Kudos
Message 5 of 9
(3,737 Views)
Here is that example

Brian
0 Kudos
Message 6 of 9
(3,737 Views)
In addition to the solution Brian just mentioned, you might want to check out the answer to a similar question just a few days ago. Jean-Pierre came up with a beautiful solution to that question (just like the one Brian just mentioned) and he attached a sample VI for it as well. Below is the link to it. /Mikael

http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=50650000000800000046250000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0
0 Kudos
Message 3 of 9
(3,737 Views)
The attached VI shows you how to do what you are trying to accomplish. You need to use the spreadsheet string to array function, but use the "%b" format string which tells the function that the it is reading a binary format. Also, use a CR or LF as your delimeter. The resulting output will be an array of Numerics.

Best of Luck

-Jim
Message 7 of 9
(3,737 Views)
A very good solution! However, here is a disclaimer for those out there with older versions of LabVIEW:

I tried this approach in LabVIEW version 4.1 and it did not work. Only the first row is read into the array. I then tried it in LabVIEW version 6i and it worked!

I converted my version 4.1 VI to version 6i to eliminate the risk of implementing things differently. I suspect that the old (4.1) version of Spreadsheet string to array is not as powerful as the new one.

/Mikael
0 Kudos
Message 8 of 9
(3,737 Views)
Yes, Mikael, the spreadsheet string to array function has a lot of logic (smarts) built into it that are not entirely documented. These smarts, I am sure, do evolve as LabVIEW evolves. I have found that the newer versions are very good at parsing my strings with a little experimentation on what to use as the format and delimeter strings.

-Jim
0 Kudos
Message 9 of 9
(3,737 Views)