LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best cRIO Logging Method

Solved!
Go to solution

I have a cRIO application that needs to keep track of a timer in hours across reboots. The application will almost never be shutdown gracefully (meaning the power to the cRIO will just be unplugged). What is the best logging method that can be used to keep the latest value in a file on the cRIO without it getting corrupt or losing the value.

 

I could simply write to this value to an INI file every 30 seconds or so, but I don't want to risk someone unplugging the cRIO at the exact moment the file is being written to (I know the odds are slim but I have seen it happen).

 

Any help is appreciated,

Thanks,

-CAC

0 Kudos
Message 1 of 5
(2,846 Views)
Solution
Accepted by topic author CAC10268

I can think of a couple options:

 

1. (Easy) Open a new file every hour or so. Timestamp the filename so you know even between reboots when to go on to the next file. This at least limits the damage done if the system reboots during a file operation. You might even consider always starting a new file after a reboot, even if the last file was just opened a few minutes ago. This would even further limit the amount of data lost or corrupted if one file is bad. Also, if you use the LabVIEW File I/O primtives, consider using the Flush command after every write to make sure all buffered data gets written to disk.

 

2. (Hard) Have you heard of SQLite? It's a cross-platform embedded SQL-compliant database. It is sufficiently lightweight enough to operate comfortably on your cRIO. The main reason I bring it up is that its transactions are safe and won't corrupt the database (which is really just a file) even in the case of a loss of power in the middle of the transaction.

Jarrod S.
National Instruments
Message 2 of 5
(2,838 Views)

Thanks for your reply!

 

I am in the process of implementing the 2nd option you suggested, I will mark your answer as the solution if it is successful.

 

-CAC

0 Kudos
Message 3 of 5
(2,827 Views)

I have successfully installed SQLite on the cRIO and ran the example project that is included, but I am having a bit of an issue changing the queries so that it does what I need it to do.

 

This should be fairly simple since I only want to keep track of one value and don't need to keep a history.

 

I first create a table using this query:

CREATE TABLE TestTable (Hrs Real);

 

Then I insert a value of zero:

INSERT INTO TestTable (Hrs) VALUES (0);

 

Then I update the value every 30 seconds using this query:

UPDATE TestTable SET Hrs=1.56;

(can exclude the 'WHERE' and replace the entire column since only should have one field.)

 

When I go to try to query the database for all its data, nothing is returned...

SELECT * FROM TestTable;

 

When I simply replace the UPDATE command with an INSERT INTO, all insterted data is returned when I query for it.

 

If someone could just verify that the UPDATE command works in SQLite for VxWorks, I'd greatly appreciate it.

 

Thanks,

-CAC

0 Kudos
Message 4 of 5
(2,799 Views)

I'm not familiar with with cRIO hardware, but I did write a LabVIEW (Windows) SQLite interface last week. So I might be able to help.

 

How are you interfacing LabVIEW with SQLite (Some sort of cRIO equivalent of the CLN)? Are you binding variables, or just inserting them into strings? 

I assume you're checking for errors, if you're using CLN's many of the return values are an error code, the errmsg function can help explain the error if you're finding one.

 

 

You might be able to workaround using update's with a primary key and a INSERT OR REPLACE command. But just the update failing implies something about the way you're interacting with it. SQLite is tested extremely thoroughly so I doubt it would only half work.

 

 

 

0 Kudos
Message 5 of 5
(2,786 Views)