04-16-2021 09:19 AM
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.
Solved! Go to Solution.
04-16-2021 09:46 AM - edited 04-16-2021 09:47 AM
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.
04-16-2021 10:35 AM - edited 04-16-2021 10:44 AM
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!
05-17-2023 09:43 PM
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?
05-18-2023 02:41 AM
05-18-2023 02:02 PM - edited 05-18-2023 02:08 PM
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.
05-18-2023 02:08 PM
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)
05-18-2023 02:13 PM
GerdW,
Thanks for the prompt replies. I have attached a 2019 and 2021 version. I also attached a block diagram of my .vi
05-18-2023 02:23 PM
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.
05-18-2023 04:03 PM - edited 05-18-2023 04:05 PM
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.