LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save data in a file and email the file

Dear all,

I have 2 vi files:

1. one vi file can store data into a file when it runs and stopped

2. another vi can send a file out through email when it is run.

 

Is it possible for me to run the first vi and stop after one hour (to store data into A file), then run the second vi file and stop (to send A file through email), and then run the first vi again immediately after running the second vi? This is because I need to send out my data saved hourly through email and get my 1st vi to continue running through out the day.

 

Due to the file path for my first vi and the second vi are the same, I keep getting error as below when either 1 vi is not stopped.

Error 5 occurred at Open/Create/Replace File in Write Spreadsheet String.vi->Write To Spreadsheet File (DBL).vi

 

Please advice. Thanks.

 

Kim

0 Kudos
Message 1 of 10
(4,115 Views)

Error 5 is "File already open"  Did you remember to close the file before the first VI ends?

 

Rather than having 2 VI's, you should just combine them into one.  A state machine architecture would handle this.

 

Open File

Collect Data until time is up.

Close File

E-mail File

Go back to Open File and repeat.

Message 2 of 10
(4,112 Views)

Hi Ravens,

Thanks again! Raven can u pls send me a graphic or a simple vi to help me understand your explanation?

I tried to connect as in 3.jpg but I still et the same error. How can I fix the problem?

 

Kim

0 Kudos
Message 3 of 10
(4,101 Views)

Are those 2 sequence frames separate, or are they part of the same flat sequence?  There is a weird disjoint between the frames just to the right of the XBow stop function.

 

I think if those are two separate sequence structures rather than a 2 frames of the same flat sequence structure, then I think you E-mail frame is executing simultaneously with your data collection frame.  Run it in highlight execution to be sure.

 

I would put a file close function just above the XBow stop and wire the file reference coming from the spreadsheet write into it.  That would guarantee it closes.  But that shouldn't be necessary because I think the file close is embedded in the Write to Spreadsheet file function.

 

0 Kudos
Message 4 of 10
(4,097 Views)
Ravens, I put in the sequence structure is because I assume that is the state machine structure... am I correct? How can I make the second frame runs after the 1st and then run the first frame again?
0 Kudos
Message 5 of 10
(4,091 Views)

A state machine architecture is a while loop surrounding a Case structure.  An enum is used to determine which case of the case structure to execute.  When one iteration of the while loop ends, it can tell what the next iteration should do by passing a value of the enum through a shift register.  Search the forums for threads on state machines, or do a File / New.... and browse for the State machine architecture.

 

What you have isn't technically a state machine, but for the time being, it should function okay.  What you need to do is remove the sequence from around your e-mail section.  Go to the other sequence structure and insert a frame after it.  Drag and drop the e-mail portion of code into that second frame.  Now you have a true sequence structure where the 2nd frame executes after the first.  (Right now you have two 1-frame structures that execute parallel to each other).

 

You can actually eliminate both sequence structures.  If you wire up the error wire from the Xbow close into the Error In of one or more of your e-mail property nodes, that will force the e-mail to execute after the data collecting part of the code.

Message 6 of 10
(4,082 Views)

Hey Ravens,

I tried ur advice on wiring up the error wire it works- sending email after I press Stop. But I can't figure out how can I make the system to continue reading data after email hourly.

I tried to use state machine as the picture attached, but I don't know how can make state 1 to run for an hour and then run state 2 to send email and continue running state 1. How can I correct the connection? What should I add? Please advice. Thanks!

0 Kudos
Message 7 of 10
(4,050 Views)

Why did you replace it with an event structure?  You still don't have a state machine.

 

The event structure will hold the operation of the loop until an event triggers it.  Kill the event structure, then there will be no wait.  That or put a timeout value into the timeout node at the upper left of the event structure for a small wait.

 

Your master while loop will take things back to the beginning.

0 Kudos
Message 8 of 10
(4,047 Views)

Dear Ravens,

I tried to kill (remove) the event structure from my earlier code, but as I run it, I get the same error again- error 5.

I also tried to put time out value 200 at the timenode at the upper left of the event structure but the email part just never executed.

 

I searched thru the forum and found a several examples on state machine as attached. I tried the first attachment for my program but obviously I used the wrong one as you adviced. As for the other state machine examples that I downloaded, I couldn't figure out how to apply them for my case correctly. Can you advcice how can I implement state machine to get the results tat I need?... Pls gv me some clearer hints? 

 

 

0 Kudos
Message 9 of 10
(4,015 Views)

Here is what I consider a better example of queued state machine with events.  It puts the event structure in its own while loop.

 

Here is the VI saved for 8.0, but I have no way of saving it further back then that.

 

With this, either the event structure can add commands to the queue, or even the state machine itself.  For instance, when the timer is up (maintained through the shift registers), it can queue up a state 2 command (save then e-mail) rather than queueing up itself (state 1, acquistition command)  Once e-mail is done, it can queue up state 1 acquisition all over again.

Message Edited by Ravens Fan on 02-27-2009 08:40 PM
0 Kudos
Message 10 of 10
(3,992 Views)