LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW FPGA Can't Write Input to text file

Good Afternoon,

 

I have been trying for the last couple of days to get my LabVIEW code to write some input data to a text file. The code is fairly simple at this point as I am trying to get it to work piece by piece before incorporating all inputs I need to acquire.

 

I have a CompactRIO system with 4 modules, of which I am using the NI-9205 for this code (analog voltage input) to read a throttle position sensor in a hybrid vehicle. The first step I took was to get the code to recognize and plot the signal (on a Waveform Chart) from the TPS which I deemed it did successfully (when the engine was off, the voltage went to 0 and when it came on, I read a voltage that varied according to the engine speed within the expected limits). Now I am trying to get the code to additionally write the data it acquires to a text file that can be used in either Excel or MATLAB. I found several examples online and in the LabVIEW help and thought I had a good idea of how to approacht his problem. After a couple days of testing, it is clear that I do not. I have attached both FPGA codes for reference.

 

Does anyone have any suggestions, comments, questions? Any and all help will be greatly appreciated.

 

Thanks,

Andrew

Download All
0 Kudos
Message 1 of 23
(5,225 Views)

Where are you running the "host" code?  On the RT Target or on a connected PC?  Do you know if the file gets created with nothing in it or no file, or an error thrown?

 

I'll be able to test your code here shortly . . .

 

 

TR

><><><><><><
Tommy R.
><><><><><><
0 Kudos
Message 2 of 23
(5,188 Views)

I am embedding the Escape_AIs_Test on the cRIO and running the Escape_AIs_Host on a host PC. I was working today with an NI App's Engr nad we modified it to include by:

 

1) Deleting the filename prompt

2) Moving the 'Open File' VI and it's attributes to the far left and putting a Flat Sequence Loop around it

3) Wiring the 'Error Out' from the 'Open File' VI to the 'Error In' of the FPGA Reference

 

However, the code still does not work. Now it returns an Error 7 when it tries to run. This error deals with the file path not be valid, but I've tried the 'Open File' in every mode (Open, Create, Replace, etc.) with the same result except for open (which returned a file doesn't exist error). I've also tried using both types of slashes and colon (the '\' slash should be the right one for Windows).

 

I did in my looking find in the Help that the 'Open/Create/Replace File' VI will not work in an LLB. If I am using these codes in a LabVIEW project, is that an LLB? I'm not sure what an LLB is...

 

Thanks

0 Kudos
Message 3 of 23
(5,181 Views)

I think the solution is simple . . .You need to include a path!

 

I stripped the save data part of your program (removed the prompt for filename) and simply added a full path with filename and this worked for me.  Remember that depending on your target the path might be formatted differently.  On the one I tested with (a cRIO-9002 with 9205 for AI) it's like windows (c:\filename.txt).  I also added the character constant to create a new line each time the loop turns so the data is saved in a single column.  This is an unbuffered solution to your problem and won't be good if you're grabbing data at high speeds, but this is another issue.

 

There's a lot more formatting you could do to your data files, and the Sub-VI's "Write to spreadsheet file" will work for saving more than one channel on a RT host.

 

Finally, your data files will be on the target, not on the PC, so you'll have to create a method to "go get your files".  I just went to ftp://my_target_ip_address and saw the "c:\TextFile.txt" and grabbed it.  You don't have to save the file in the root on the target, you can do it in the temp dir, or create a dir specifically for data . . .

 

Hope this helps.

 

TR

 

PS.  an LLB is a LabVIEW Library, basically a wrapped up file with lots of VI's hiding inside.

><><><><><><
Tommy R.
><><><><><><
0 Kudos
Message 4 of 23
(5,167 Views)

Thank you for your help. I'm sampling at 1kHz. I'm eager to see if this solves the problem, which I think is the first time I've been eager to do anything with LabVIEW...but I'll let you know how it turns out.

 

Thanks again!

0 Kudos
Message 5 of 23
(5,160 Views)

1kHz is cake for any FPGA/RT combo.  Be sure you don't adjust the sample rate (the way you have it programmed you can) in the middle of a run - dT should be consistent within a data set to make any sense of the data.  If you know the sample rate and since you have the IRQ pause/continue set up, you don't need to include a column of data to represent time (as long as all your channels collect at the same rate).  All you need is row number and dT and you're good.

 

Be glad to help out further if I can.  I remember being a newbie with my cRIO and found lots of help in the forums.  Figured it's time for a little payback.

 

Good Luck!

><><><><><><
Tommy R.
><><><><><><
0 Kudos
Message 6 of 23
(5,148 Views)

I have the same problem. I could not open the attached file, because I am using LabVIEW 8.6(lower version). I am looking for an example code illustrating how to write to measurement file from FPGA. Any help would be very appreciated.

 

Regards,

Moris

0 Kudos
Message 7 of 23
(5,073 Views)

My problem ended up being an issue with the directory I was trying to write to. I can't remember off the top of my head what format I had to change it to (the computer with the code is in my office and I am home), but it was pretty simple. Can you attach your block diagram?

 

Andrew

0 Kudos
Message 8 of 23
(5,067 Views)

I have attached the host and FPGA vis. I use cRIO 9074 and NI 9205.

First of all, I am new with all of this so you can see that in the host file, there are some broken wires (connection of terminals with different types) which I don't know how to resolve.

How can I modify this code to match the type of terminals? ("The type of sink (or source) is void and the type of input (or output) is a cluster of 4 elements or ...)

Now how can I write the "AI Data" to a file?

 

Thanks very much,

Moris

Download All
0 Kudos
Message 9 of 23
(5,062 Views)
Do you want to save the file on a PC host or on the RT host for retrieval later?
><><><><><><
Tommy R.
><><><><><><
0 Kudos
Message 10 of 23
(5,051 Views)