07-07-2020 06:45 AM
Hello,
Here is a diagram of my project :
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 :
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 ?
Solved! Go to Solution.
07-07-2020 06:52 AM
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
07-07-2020 06:59 AM
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
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.
07-07-2020 07:03 AM
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 ?
07-07-2020 07:06 AM
Hello Redhawk,
Here is my VI under LBV17.
07-07-2020 07:18 AM - edited 07-07-2020 07:19 AM
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.
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.
07-07-2020 07:20 AM
Ah, thank you for clarifying what you are doing. Here is a way to "do what you want", maybe using a State Machine architecture --
Bob Schor
07-07-2020 08:04 AM
Thank you so much ahah it worked !
At least I'll know for next time !
07-07-2020 08:06 AM - edited 07-07-2020 08:07 AM
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.
07-07-2020 09:16 AM
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
Thank you very much for your help !