From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reading the first character in every row

Solved!
Go to solution

Hello!

 

I have a problem with reading a text file in LabView which I am sure is pretty easy to do but since I'm really new to labview (and programming at all) I am having a hard time figuring it out.

So basically I am using the "write to measurement file" VI to write some test results into a text file. I am just getting ones and zeros so the text file looks something like this:

1,00000

0,00000

1,00000

..

and so on . 

I would then like to import these values to labview but I dont want the decimals and I would like everything on the same row, something like this:

1 0 1 0 etc etc.

(the idea is then being able to convert the values to a hexadecimal number 1-F, so for example the input above would translate to 6.)

I've tried to use the read from text file function but I don't know how to then convert the input to my desired format.

 

Also if you have any clue on how to make it start reading at the first 1 and then read the next 4 inputs that would be great as well.

 

Any help is really appreciated! 🙂

0 Kudos
Message 1 of 15
(3,044 Views)

Hi Tob,

 

use ReadFromSpreadsheetFile and read your data as INTEGER. Then index the first column…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 15
(3,024 Views)

Hello, 

thanks for the reply! Is this what you are suggesting?

vi.png

vi2.png

I have tried something similar before but as you can see I dont get what I want.. Feels like Im missing something, you have any idea what? 

Thanks again!

0 Kudos
Message 3 of 15
(2,996 Views)

Is anything in the loop supposed to happen in a particular order?  It's hard to tell from the picture because I have no idea if the the file paths are even related.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 4 of 15
(2,990 Views)

Just read the entire file as one long string, search for newline characters, and look at the character right after each.

Message 5 of 15
(2,978 Views)
There is no point in reading a file in a loop. You only need to read once. You should also attach the file you are trying to read. An lvm file typically has header information so the first row is not data. If you use Write to Measurement File, then use Read from Measurement File.
Message 6 of 15
(2,971 Views)

This sounds exactly like an idea for a solution that I had but couldnt find the functions to do it, do you have any idea which ones to use?

0 Kudos
Message 7 of 15
(2,969 Views)

Heres the file! Yeah I realise the loop is kinda pointless.. Like I said Im really new to programming at all! 

Its a lvm file but I put the settings so I only get the 1's and zeroes, figured it would be easier to read that way..

I tried using the read from measurement file but kept getting an error saying " end of file reached" every time i tried to read it. (Even the first time, I am aware of the issue with recieving the error the second time reading as i read some forum posts about that)

0 Kudos
Message 8 of 15
(2,960 Views)

After you read the file and convert the strings to 1 and 0, how will those values be converted into the "hexadecimal number" you mentioned? Are all the values used for one number or will the data in the file represent multiple numbers? If so, how many "bit" per number?

 

The code shown below will read the file you posted and convert the data into a single number (expressed here as decimal). The hex equivalent is C002.

 

Lynn

 

file to boolean to number.png

Message 9 of 15
(2,936 Views)

something like this

Capture2.PNG

You need to declair the decimal separator


"Should be" isn't "Is" -Jay
Message 10 of 15
(2,934 Views)