01-18-2016 10:08 AM
Hello,
I am communicating with a device over TCP/IP(UDP) protocol. The device has some registers for configuration and there is a register to activate and deactivate the device. I want to implement a shared variable to save operating hour of the device, namely a timer that counts, when I activate the device till deactivating. My approach (not a good idea) is that I create a boolean shared variable, While activating my device I set this shared variable to true, while deactivating to false. But I have to sum all of the times when shared variable is true. It will maybe get slower and slower after months, because it shall sum all the times from the beginning. What is the best approach for this task?
Thanks.
01-18-2016 11:55 AM
I don't understand, do you need to store all of the times individually or keep just a running total? Are you worried about losing this data if the system accidentally reboots? Why is the boolean shared variable necessary?
01-18-2016 12:15 PM
I assume you activate and deactivate the device by doing something (using LabVIEW, I presume) on your PC. So when you Activate the device, save the "Start Time". When you Deactivate the device, get the "Stop Time", subtract the Start Time, and you have the Time Device was On. Save this somewhere/somehow. If your program runs over multiple days/months and multiple Activation cycles, you can (a) save an Array of Run Times, or (b) accumulate (means "add up") the Run Times to save "Cumulative Run Time". No need for Shared Variables,
Bob Schor
01-19-2016 04:22 AM
Yes I am activating and deactivating it from my application, that I implemented in LabVIEW . I am saving lots of values from device in Shared Variables, therefore I want to save also the operating hour in a shared variable and I want to show the operating hour on GUI as hour:minute, it shall be shown to user but not changable by user. Later on I will backup the shared variable database to analyze it. I want to avoid to save it in a text document.
And I don't want to accumulate all of the run times during start-up the program. After a couple of years, maybe the data will be huge and it will take a long time to accumulate all of them.
01-19-2016 07:23 AM
01-19-2016 07:32 AM
01-19-2016 07:41 AM
Yeah, the only thing you need to keep track of is 'accumulated runtime' - it's a single value in a file that you can read, add your runtime since last write, and write back to the file. For example, you might want to write to the file every 10 minutes and if it has been online for all that time - you'd be adding 10 minutes to the accumulated runtime in the file.
As Mike said - you need to be aware of what happens if you run it on another computer (a database or storing the file in a network location - use the serial number of the device to identify it) or what might happen if the device is running and your PC crashes etc. - it might not be 100% accurate.
01-26-2016 03:34 AM
Thanks for answers. Yes, it will not 100% accurate, it will be only a "feature" 🙂 .
I will try your suggestions. Thanks a lot.