Calcumbery operation time in generator set control
Summary: This paper explains the development of the generator set control system's upper-board software software, and the computer data type knowledge applied by the developer in the process of developing software.
Keywords: database, object-oriented, control, clock, file
The generator set is our company's development and development, mainly used in the series of products for the telecommunications department. The requirements of the unit on the control system are mainly timely and accurate, and one of the requirements for the control system is that the cumulative runtime of the display unit is required in the host computer software. The function seems simple: as long as the system time is subtracted from the system time, the system time is equal to the time of this unit, plus the time that the previous cumulative operation is equal to the accumulated operation of the unit, and the time to stop the signal will be accumulated. It is possible.
But in the process of program debugging, it has found problems:
1. If the user modifies the system time during the run, the system time is very large and even negative when the system time is very large, and the unit accumulated operation is not allowed;
2. The time 0 value in VB is 0 seconds, 0 seconds, 12:0am, 1899, so it is displayed in 1 second as: "1899/12/30 12:00:01 AM" This is obviously not what we need;
3. In VB's time type variable or constant middle age, no one in the day, no one is 0, otherwise it will be wrong;
4. If the computer crashes or errors, this runtime is not allowed to save the cumulative operation time in the operation time.
Complete timing function first should declare three variables:
The static variable T1 is used to store the system time when calculating the accumulated time TL, that is, the accumulated time baseline
Variable TL, used to store accumulated runtime
Variable T2, used to store system current time
Distinguishing the normal idea of this function: In the operation process, the unit is turned to "Run" in the running process. "This time the program will save the current time to a static variable T1 (assuming 2000/12/20 00:00:00) After running for a while, the program uses the current system time t2 (assuming to 2000/12/20 00:20:00 with the difference (00:20:00) that just saved T1 (00:20:00) as the time run.
Since the Windows operating system is a multi-task operating system, this may occur during the program run, that is, after the program saves T1, the user modifies the system time through other programs (assuming modifications to 1998/12/20 00:20: 00) The statistics of T2-T1 <0 appears in the program runtime statistics, and the time value in VB is interpreted as the date before 1899, so that T2-T1 is equal to 30, 1897: 00:00 The time displayed time will display the incorrect time.
In order to prevent the user from modifying the system time during operation, the problem is not allowed to make the unit accumulated in the legal range in the legal scope of the system time during the operation. The program is calculated every 1 second, and the T2-T1 is calculated. If the value obtained by T2-T1 is accumulated in the accumulated time TL within 0 to 6 seconds, regardless of the value of T2-T1, Both T1 = T2. This time the time base T1 is updated once per second, since T1 is updated every second, so whether the user will modify the time in the program running only 1 second error. Error.
In addition, the value of the time type in VB is 0 seconds 0 seconds, 12:0am, 1899, so it is shown in 1 second as: "1899/12/30 12:00:01 AM" and year, month , The ancestor cannot be equal to 0, which is clearly not in line with what we need. To solve this problem, first understand the data type of VB.
The time type variable in VB is stored as the IEEE 64-bit (8 bytes) floating point numerical form, which can represent the date range from January 1 to December 31, 9999, while time can be from 0:00 : 00 to 23:59:59, when other types of data are converted to time type, the values on the left side of the decimal point indicate the date information, and the values on the right side of the decimal point indicate time. The midnight is 0 and the noon is 0.5. The negative integer represents the date before December 30, 1899, so the value of 1 second in VB is 1 ÷ 24 ÷ 60 ÷ 60 = 1.15 × 10-5 Application This value is in the program The time variable is converted into floating-point variables, and then the floating-point variable is divided by 1.15 × 10-5 to the cumulative number of minutes, because the cumulative operation time of the unit is the largest unit in hours, So don't need to be converted for the year and month. The disadvantage of this method is to calculate comparison, and 1 second corresponds to 1.15 × 10-5 error, and the error is easily errors in the accumulated time.
Finally, the use of data structural methods to solve the time problem, that is, the new type of data structure is defined as follows:
Type Timel
THOUSE As Long
TTIME AS DATE
End Type
definition
DIM TIMELJ As Timel
Use Timelj.thouse to record the number of hours of the accumulated time, and use Timelj.ttime to record the minutes and seconds of the accumulated time. The procedure subtracted from the current system time t2 subtracted to Timelj.ttime each second, when the value of the hour bit of Timelj.Ttime is ≥ 1, the value of the hour bit is added to Timelj.thouse. At the same time, Timelj.Ttime's hourly bit is 0. When the display unit accumulates time, Timelj.ttime is split open, and it is read from it, seconds and combines Timelj.Thouse, it shows the generator set. The accumulated time running since the start. If you read the accumulated time of the last run in the program, the time displayed during the program is running is time to run the unit. In the program run, each time a set of valid data is read from the serial port, the status of the unit is discriminated, and if it is discriminated as "run", the cumulative runtime will be accumulated, and this time is stored in the hard disk. Read the history of this unit starting the front unit during the program loading process, in order to prevent user mistakes from delete the historical runtime data, the system error that can not open the file is read, in the program reads historical runtime The history run time file will be judged before. If there is already existing, open it read the data, otherwise it will be handled, that is, the unit is the first run.
In order to prevent the system time storage caused by the system from exit, the cumulative storage time is increased to 3 to 5 seconds.
Through the long-term learning and application of computer programming knowledge, I have accumulated some experience, I found a lot of problems that seem to be easy but realization, once solved, I will involve other knowledge, in the future machine Software upgrades or writing new host computer software works will save a lot of time and effort when solving similar problems.