LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

rt- Writing to TDMS every hour

Solved!
Go to solution

Hi guys,

Attached I have a project in which i am attempting to write to TDMS file on my cRio every hour.( I have a variable X which you can change so you don't wait for an hour in testing phase :D)

The VI is kind of working but as you can see i have a wait( 1000ms) in my false case structure or otherwise the program will stop working, so i guess my question is what is the right way of writing to file every hour? is there better or more optimized solutions?

Also if you let the program run the second file that gets created has bogus numbers so i guess there is some sort of binary shift happening because it couldn't write the data correctly!!!

Thanks for your help in advance.

Download All
0 Kudos
Message 1 of 15
(3,046 Views)

Hey persol

 

I took a look at your code and it looks good mate.  You clearly have your initialisation/ shutdown steps prepared in your flat sequence structure and you use high priority deterministic timed loop to acquire your data and a low priority non-deterministic while loop to write data to file.  However, your problem is coming in your case structure in the write to file loop.

 

Looking at your code I would guess the reason your program stops working is because you are getting an error -2220 in your true case out of the Buffer RT FIFO.  Your variable returns no data and therefore writes empty data into Reshape Array.  This will give an error message out of your TDMS write vi which will stop your both loops via the shared variable Stop.

 

Personally; I would bring your read Buffer RT FIFO outside your case structure and wire the error code, from the unbundle by name error cluster, into the case selector.  You will get an error -2220 if the buffer is empty, so in this case you can wire the wait function and clear (specific) error in order to fill the buffer in the deterministic loop.  In the no error case write to your TDMS file the data from the buffer and bingo.

 

Hope this helps,


Regards,

 

Robert Ward
Applications Engineer, NI
0 Kudos
Message 2 of 15
(3,026 Views)

Rob,

Thank you for you response. Actually that was what i thought ( buffer becoming empty) when i brought the read buffer inside the case structure, originally i had it out like you suggested. but unfotunately that doesn't seem to be the problem because like you said i wired the error out from the buffer to unbundle by name and i am monitoring the status as the program runs and it is always false.

There has to be something else going on ( since the code kind of works when i have 1000ms wait in my false structure).

Attached i have two TMDS files generated by the code describing what is happening. the first file gets created when VI starts and the second file is when the case structure is false and a new file is created. In the first file you can see that everything is being written fine but in the second file, the first line is similar to the previous file but the rest of data are basically trash. 

Download All
0 Kudos
Message 3 of 15
(3,003 Views)

Hey Persol,

 

I have a few questions about your application. Do you want the application to write to the tdms file for an hour and then create a new tdms file or do you want it to write the last 50 elements from the buffer? As you have it now the file constantly writes to the tdms file until the time stamp matches the x input.

 

An alternative to structure that could potentially help is to use a state machine. You could have an initialize state that creates the file. Next, you could have a state which writes to the file after a certain wait time and then goes to a close state which closes the tdms file. The main state could be timed for an hour and then restart the create/write/close states.

 

I have included a knowledgebase related to LabVIEW state machines:

http://www.ni.com/white-paper/3024/en

I hope this helps.

Wear
National Instruments
Product Support Engineer
0 Kudos
Message 4 of 15
(2,957 Views)

Wear,

Thank you for yur response, Yes i want data to be writen to tdms constantly and creat a new file every hour and continue writing.

So do you know what my problem is? and you think by doing state machine algorithm my problem will be solved?

I feel like the state machine will do basically what my case structure is doing but it is a bit fancier! but then again that might be what make the problem go away.

0 Kudos
Message 5 of 15
(2,947 Views)

Wear,

Ok so I think I did the state machine approach.( Don't mind the init state i will eventually either take it out or i will put my initial create file in there).

if i did everything correctly i end up with the same exact problem!!!! which is if i don't allow 1sec for closing file my program crashes, and when i do my tdms files are bogus!!

Attached please find the new VI. 

Thank you

0 Kudos
Message 6 of 15
(2,918 Views)

Persol,

 

Try to put a .tdms flush before the .tdms close in the close state. This might resolve the issue of the second file having incorrect data.

Wear
National Instruments
Product Support Engineer
0 Kudos
Message 7 of 15
(2,899 Views)

Hello persol,

 

You mentioned that your VI must wait 1 sec for closing file, otherwise the VI will crash or stop working. Since I don't have these chassis hardwares, and I can only run your VI by removing all these hardware-related stuffs and write some random values to the "Buffer", your VI works well even after removing the "waiting 1 second", no crash happens.

 

I recommend that you should put a file close node to close the last-opened file after the writing loop ends. This will do some help to avoid data corruption. You could first make sure whether the last-opened file is really closed(the newly-added close node gets executed) in your crash situation, and then check the data integrity.

 

Thanks,
Tianbin

0 Kudos
Message 8 of 15
(2,884 Views)

Wear,

Unfortunately putting a flush didn't help. Thank you

 

Tinabin,

Maybe I don't quite understand what you mean when you say to put a file close node after the write loop. Because I already have one in my state machine! Did you mean to put an additional one?

I have all the errors connected through a shift register, wouldn't that make sure the file is closed and if the not give me an error?

Thank you

 

Persol

0 Kudos
Message 9 of 15
(2,865 Views)

Tinabin,

I also ran the program with made up numbers and i still get corrupted data!!!

See attached.

Thank you

Download All
0 Kudos
Message 10 of 15
(2,860 Views)