From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Save each iteration of data using VISA read to file

Solved!
Go to solution

Hi,

 

I am using a simple labview vi to read data from an Arduino, which is attached to a couple of sensors. The VISA read is correct, and I'm happy with that, but I now want to be able to save each serial reading over each while loop iteration. Each attempt I've made to do this has resulted in only one iteration being saved. Either it is overridden each time, or it only appears to save the last iteration before I hit the stop button.

 

I've attached my vi as it currently is, which saves the last iteration. If I remove the property node entirely it saves every iteration but it causes an override. Any help would be appreciated.

 

 

0 Kudos
Message 1 of 20
(1,677 Views)
Solution
Accepted by CJT1993

Do not use the Read VISA To File.  It is made for a single write.  Instead, treat the file like the VISA session: open/create/replace the file before the loop, close the file after the loop, and write as much as you want inside of the loop.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 20
(1,655 Views)

Hi, thanks a lot for the reply. I've tried to implement your suggestion. I added the changes you suggested, but now I don't seem to read anything, or save anything. So I tried to copy your block diagram completely, and I can't seem to replicate it. I've attached my vi, not sure if I'm doing something dumb or not. From my untrained eye, it looks like the wiring is different on the build path block diagram object, but I can't seem to get what you did, so perhaps the difference is aesthetic across out labview versions/settings?

 

Edit: Ignore that, I figured out the mistake. Funnily enough I got the VISA read to file working too, so I now have two working solutions. Thanks a lot though!

0 Kudos
Message 3 of 20
(1,621 Views)

Hello, I have the same issue. I read from the sensor just fine, but the file is overwritten with each new value. I noticed you said you had figured this out in your edit. How did you fix it?

0 Kudos
Message 4 of 20
(1,080 Views)

Hi frakf,

 

did you use crossrulz' accepted solution? That would NOT overwrite the file, but append all read data to one file.

 

When YOU have problems with YOUR VI then YOU should attach YOUR VI!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 20
(1,059 Views)

GerdW,

 

Thank you for replying, my apologies for not attaching the VI or image. I have done so.

 

I did look at the verified solution. My Vi is a bit different, I have a write function inside the loop before the read and wasn't sure I could still write outside the loop between the write and read function as crossrulz' solution said. You said you figured a way to to make write to file work, I figured I'd stick with that.

 

Thanks.

 

Edit: Added image.

 

Download All
0 Kudos
Message 6 of 20
(1,021 Views)

Hi frakf,

 


@frakf wrote:

I did look at the verified solution. My Vi is a bit different,


There's the problem… 😄

 


@frakf wrote:

my apologies for not attaching the VI or image. I have done so.


Unfortunately you are using the latest LabVIEW version, but many on this board (including me) still use older LabVIEW versions.

You would reach a broader audience when you would downconvert your VI to LV2021 or LV2019! (File->Save for previous)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 20
(1,016 Views)

GerdW, 

 

Thanks for the prompt replies. I have attached a 2019 and 2021 version. I also attached a block diagram of my .vi

Download All
0 Kudos
Message 8 of 20
(1,010 Views)

1. That code looks nothing like the "solution" to this thread.

2. DO NOT USE THE BYTES AT PORT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (still not enough emphasis).  Just tell the VISA Read to read more bytes than you expect in a message and let the termination character complete the read.

3. Generally speaking, the VISA Read To File is not a good solution as it will overwrite your data every time unless you find the right VISA property.  And even then, it will be constantly opening and closing the file which is SLOOOOOOOOW.

 

Go and copy what I did before and see if that works.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 20
(1,001 Views)

Hi crossrulz,

 

thanks for the reply. I initially looked at your solution, but I didn't implement it in the vi I sent. I don't mind the VISA read to file solution even if it's slow. It doesn't require I make too many modifications and that's great for me. I am a beginner. I have implemented your solution. I put everything you had between configure port and read, inbetween my write and read. However I still got an error. I have attached screenshots and the .vi The error says something is wrong with my filename but it looks just fine to me.

 

Edit:

The Error: 

Error 1 occurred at Write to Text File in U2.vi

Possible reason(s):

LabVIEW: (Hex 0x1) An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @.
=========================
Command requires GPIB Controller to be Controller-In-Charge.

Download All
0 Kudos
Message 10 of 20
(986 Views)