Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

[beginner] "Write to Measurement File" problem

H! Smiley Happy

 

I'm trying to read data sent from a DC motor, show  on graph and save the necessary information to a text file. when I press the Run button, the code works as I want it to and I don't have any problem with showing on graph or saving. however when I ran execute the code writing to file doesn't start exactly at the beginning. I mean some time later after I have pushed the button it starts saving the data. my guess is it sets time equal to zero whenever it wants. sometimes it works fine but sometimes it doesn't.

I have attached my code and any comment is much appreciated.

0 Kudos
Message 1 of 14
(5,190 Views)

Hello Neo_Ev,

 

If you remove all of your graphs so that all its doing is writing to file do you get the same behaviour? What if you use the "Write to Text File" VI instead of the express VI? Also, what do you mean when you say it sets time equal to zero whenever it wants? Do all of your measurement files start at t=0? If so how do you know that the data is off?

Jonathan L.
Technical Support Section Manager
National Instruments
0 Kudos
Message 2 of 14
(5,149 Views)

Hi

 

the behavior is the same even when I remove all the graphs!

 

All my measurement files start at t=0, (For a specific command) the corresponding number at the second column must start from 2500 (approximately)  and then decrease to zero, sometimes it behaves correctly but sometimes it behaves arbitrarily.

 

I have included some of these data files that I have saved.

 

I tried to rewrite the code using "Write to Text File" VI and strings. at every iteration I save all the data I need into a string and the next iteration I append the new data to the previous one. It stores all the data I need, but I don't know how to reset the string everytime I run the code. I mean everytime I stop and re-run the code.

 

Thanks for your time and effort

sorry if my english sucks!

Download All
0 Kudos
Message 3 of 14
(5,133 Views)

Hello Neo_Ev

 

All of your data starts at t=0 so it would appear that you are in fact getting all the data. Why are you sure that the measurements in the second column should start at 2500? Could you please elaborate on what exactly your data means? I'm having a little trouble understanding what your application is and that may help answer this issue.

Jonathan L.
Technical Support Section Manager
National Instruments
0 Kudos
Message 4 of 14
(5,112 Views)

I have an encoder coupled with dc motors. Using it I have the encoder's frequency and number of pulses.(my encoder is 1024 pulse. This kind of thing is not my specialty. I don't know the correct expression)

 

The second column is the Pulse number I read from the buffer motor sends and I use it for position control. For a specific command, I want motor to start Pulse=2500 and come to Pulse=0. Actually it turns about 20 degrees counterclockwise.

 

I hope my explanation was useful !!

 

After rewriting the code using "Write to text file" and strings it behaves better but a few times it happens again.

0 Kudos
Message 5 of 14
(5,101 Views)

Hello Neo_Ev

 

From what I can tell your code in no way effects the encoder, it only reads information. I don't see any glaring mistakes in the code and since your data is coming out timestamped starting at 0 it would appear that it's getting all the data sent to it. Is it possible that the problem is on the side of your code that actually controls the motors? 

Jonathan L.
Technical Support Section Manager
National Instruments
Message 6 of 14
(5,086 Views)

Hi Jonathan-L

 

Thank you for your time.

 

I don't think the controlling part of the motor has any problems, because all the graphs and motors' behaviour seem right.

I have two computers for working with motors. One is for controlling them (PC 1) and the other one is for plotting the necessary data (PC 2). I receive all the data in PC 1 and after running some control codes I send the necessary ones to Labview using visual studio. can this be the problem?

0 Kudos
Message 7 of 14
(5,077 Views)

Hello Neo_Ev

 

It's possible. What do you mean by "control codes"? Also is this VI from the second computer that is plotting the necessary data? It might be helpful if you explain your physical setup and the steps you take in your procedure. 

Jonathan L.
Technical Support Section Manager
National Instruments
0 Kudos
Message 8 of 14
(5,054 Views)

I sort of solved my problem using Write to Text File VI.

 

Now I have another problem. When I recieve my data in PC1 and then send it to PC2 in order to plot it sometimes I don't recieve all the data I'm sending from PC1. This happens just for one instance and it ruins what I'm trying to do.

 

Is this problem related to serial port itself ?!

0 Kudos
Message 9 of 14
(5,043 Views)

Hello Neo_Ev

 

I'm going to assume from your question that your two PCs communicate through a serial cable. Can you set up a simple loopback test to ensure that they communicate correctly? And then upgrade to sending data that you know; eg the count iterations of a loop. 

Jonathan L.
Technical Support Section Manager
National Instruments
0 Kudos
Message 10 of 14
(5,016 Views)