Because ONSPEC and all its supporting processes are running in a multi-programming environment, the I/O template's sense of time should NOT be kept by the use of a real-time clock. In order to give more CPU time to the other programs (such as ONSPEC) the I/O template should use operating system calls to put itself into sleep mode for a period of ticks.
The method of simulating time mentioned in Section 2.0 - i.e. putting the I/O template to sleep for some time once each loop - obviously leaves something to be desired. What if during that one loop twenty commands were sent to the device, twenty replies were waited for, processed, interpreted and sent on to ONSPEC ? That one loop might well have taken 5 seconds of real time, and delaying for yet another second at the end of it certainly does not help maintain accuracy. (See main loop in provided code delay( -delayTime )). The delay_time can be adjusted for heavily loaded I/O templates by using the DELAY command in the configuration file. The format is as follows:
where n is the number of ticks to delay each time through the loop.
The final note here is on error handling. If the operator enters invalid data in the command file, the I/O template should be able to detect it and inform the operator of the error. The I/O template should not abort upon seeing an error. Instead, it should output the line to the screen as an error and then ignore it, continuing to read in the file and construct the command list. How far you want to go here with error interpretation and so forth is up to the individual programmer. However, there should certainly be enough error checking to ensure that the program does not crash during operation due to an invalid value in any field.