LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write in multiple txt files but not at the same time

Solved!
Go to solution

Hello,

 

Here is a diagram of my project :

Naxmouk_0-1594121645578.png

So, Arduino TX1 and Arduino TX2 are sending data to my arduino RX. The Arduino RX can identify from wich arduino TX the data is coming. Then, Arduino RX send the data to Labview via "Serial.print()".

Here is my VI :

Naxmouk_1-1594121800425.png

With the "VISA read" I can extract my data.

I want to save the temperature and the humidity in a file, but if this is coming from the arduino TX1 (the case when header=1) I want to save the data in FILE1 and if it's coming from the arduino TX2 (the case when header=2) I want to save the data in FILE2.

When I launch the program, I can see the different values "Hum", "Temp" and "Header" in my front panel but when I open FILE1 and FILE2 there are only the data from TX1.

 

TL DR : When header is 1 I want to write in FILE1 and when header is 2 I want to write in FILE2.

 

How can I do it ?

0 Kudos
Message 1 of 10
(2,394 Views)

You open two files, File 1 and File 2, have two lines of data flow, one for the data going into File 1, one for the data going into File 2.  

 

One way to do this is to write a program for doing only 1 file.  Make sure it works.  Now (on the block diagram) make a copy of the code, running in a parallel track below the first code, change references to File 1 to File 2, change the source of the data from (say) DAQ Device 1 to DAQ Device 2, have a separate set of Controls and Indicators, and keep it neat!

 

Bob Schor

0 Kudos
Message 2 of 10
(2,390 Views)

Could you save for '17 so I can open your VI?

 

And a little note on scalability, you always want to code such that what you've done is scalable, and if you have to add a case manually each time you add a new "TX#", which means having to recompile, that isn't very scalable. 

 

But really, for what you need, it should just be a matter of using the right reference in each case

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 3 of 10
(2,383 Views)

Hello Bob_Schor,

 

Ty for your reply.

The problem is that I don't receive my 2 data flows simultaneously.

It's TX1 for 1 second then TX2 for 1 second ect...

There is only one serial port.

I can't do your solution if I don't receive the 2 data flows simultaneously ?

 

 

0 Kudos
Message 4 of 10
(2,377 Views)

Hello Redhawk,

 

Here is my VI under LBV17.

0 Kudos
Message 5 of 10
(2,371 Views)
Solution
Accepted by topic author Naxmouk

Here is your problem, you accidentally made Header 2, Temp 2, and Hum 2 when you made your case statement for "2". When you use CTRL+C, CTRL+V to make copies of local variables, it creates new terminals. Link all of those with the original Header, Hum, and Temp, and your code should run fine I bet.

Redhawk92_1-1594124286051.png

 

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

Message 6 of 10
(2,361 Views)

Ah, thank you for clarifying what you are doing.  Here is a way to "do what you want", maybe using a State Machine architecture --

  • Initialize.  Open VISA.  Open two files for the two sets of data.
  • Take/save Data Set 1.  Do a VISA Read, and save results in File #1.  Put a Wait 1 sec to "clock this state".
  • Take/save Data Set 2.  Also clock this state.
  • Repeat the above two steps (by having "Do Data Set 1" be the "next" state after "Do Data Set 2".
  • Note if you put the Stop button in Data Set 2, you'll get equal numbers of Data Set 1 and Data Set 2.

Bob Schor

0 Kudos
Message 7 of 10
(2,358 Views)

Thank you so much ahah it worked !

At least I'll know for next time !

0 Kudos
Message 8 of 10
(2,336 Views)
Solution
Accepted by topic author Naxmouk

1. You should NOT have ANY local variables in this code.  Data Flow should be used whenever possible.

2. I don't see a need for a wait.

3. I recommend creating your files in a FOR loop.  You can then use Index Array to choose which file to write to.


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 9 of 10
(2,334 Views)

Hello crossrulz,

 

Your program is much better than mine ahah !

I tried to copy it, it works well !

The only problem : the first row of the file that is opened first is always weird

 

image.png

Thank you very much for your help !

0 Kudos
Message 10 of 10
(2,311 Views)