LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

duplicate writing of data in datalog

Hi, I have an application which requires data logging. Though my program creates (or opens) a text file and writes the necessary data , it also duplicates it, that is, it writes it twice so I have something like this:
 
Value               3.05E-2
3.05E-2
Value              3.01E-2
3.01E-2
Value              3.04E-2
3.04E-2
 
And so on. So the numerical data I'm sendind gets duplicated in the next lines and it happens every iteration. This, needless to say is not very practical if the user wants to import the information to a datasheet beacuase of the extra characters. Does any one know why this is happening and how can it be corrected?
 
Thanks,
Ali


Message Edited by Ali84 on 06-01-2008 02:53 PM
0 Kudos
Message 1 of 7
(2,767 Views)
Hi Ali84,
where do you get the data from? Can you upload your code or an image of it?

Mike
0 Kudos
Message 2 of 7
(2,761 Views)
Hello Mike. I'm reading data from an instrument via the serial port, converting it to string and writing the datalog. Here's an image of the part of the code that makes the datalog. Each time the user wants to capture the current reading, the button must be pressed and the data is thus sent to the log. I believe the problem has to do with the button, because the writing seems to improve using a retarder. Nevertheless, I need the data to be written quickly. Also, I made another code which lets the user specify how many iterations should be done (I used a for cycle for this) and the time betwwn each, so that the program will write the data to the datalog automatically, but the problem persists.
 
Thanks,
Ali


Message Edited by Ali84 on 06-01-2008 03:23 PM
0 Kudos
Message 3 of 7
(2,758 Views)
Hi Ali84,
remove the local variable "inten..." and connect directly the wire from the subvi to it. Why do you need the for loop?

Mike

Message Edited by MikeS81 on 06-01-2008 10:30 PM
0 Kudos
Message 4 of 7
(2,752 Views)

Are you sure you aren't getting two data points per serial read?  What is that subVI you have in the lower left corner?

You have a couple problems with your code.  First, a for loop with a 1 tied to the N terminal really does nothing but run the loop once.  You might as well eliminate that whole structure.

Secondly, and most importantly, you have a possible race condition.  Why are you using a local variable "Intensidad"?  Just wire in the data from there to where the intensidad control is located inside the loop.  The race condition is that it's possible the control gets read inside the loop before the serial port updates the local variable.  So you could get stale data meaning it could also be duplicated, and also possible that a data point gets lost if the in one iteration the data gets written then the local gets updated, and in the next iteration, the local gets updated first before the data gets written.  You would effectively lose the update in the previous loop iteration.

EDIT, I see Mike got his response in quicker.  One other tip would be to puts some probes on some wires to see if you can see the duplicated data while the code is running.  Then you may be able to tell where it is originating.



Message Edited by Ravens Fan on 06-01-2008 04:38 PM
0 Kudos
Message 5 of 7
(2,745 Views)

Hello again, and thanks for your reply. The subvi that is wired to the local variable is used to modify the format of the data that the instrument sends to the PC. That part works just fine, the current reading of the instrument is displayed in the string indicator in the front panel. The problem is that when the user presses the button, the case structure is "TRUE" and executes the for loop.( I added the for loop in an attempt to ensure that the data be written only once, but it didn't work.)

 What I don't get is that the characters in the string constant are written only once in the datalog each itteration as it should, while the data in the string indicator is duplicated.

I shall try, as you say, to eliminate the local variable and wire the string indicator directly to the array and see what happens. Thank you both for the advice, I really hope that's the problem.



Message Edited by Ali84 on 06-01-2008 03:40 PM
0 Kudos
Message 6 of 7
(2,744 Views)
Your string indicator is actually a control.  If you are seeing duplicate data in there, then it must be either coming in that way from the Basic Serial read/write VI or occurring in that "Modify format" sub VI.  Put a probe or an indicator on the wire before that subVI to see what the data looks like into it.  Open it up and see what it is doing inside.
0 Kudos
Message 7 of 7
(2,738 Views)