06-24-2010 01:29 PM
This is my answer to the CLD sample exam "security system" Does anyone have any suggestions or comments?
06-24-2010 03:11 PM - edited 06-24-2010 03:18 PM
Some very quick cosmetic (not algorithmic) comments: (no functional testing)
06-25-2010 06:22 AM
Thanks for looking at this. I see what you mean, and made most of the changes, but I'm not sure what to do about the file reference. I use this to close the file at the end (that's why I circulate it). Since I log an event every time there is a change, I access the file many times, but I want to close the file at the end, only once.
So... Should I place the close function inside the "File" subVI with a Boolean to indicate the close function within the VI ? (seems like a waste). Maybe create a new VI just for close funtion ...nahh....I will look through other code for an example.
Thanks again for the critique, just what I was looking for.
06-25-2010 09:44 AM
@Islandman wrote:
... but I'm not sure what to do about the file reference. I use this to close the file at the end (that's why I circulate it). Since I log an event every time there is a change, I access the file many times, but I want to close the file at the end, only once.
No, you're not understanding. You are using "write to spreadsheet file", which is a high-level function. You can open it like a plain subVI and see what's inside. You will notice that it opens the file, writes (or appends) the data, then closes the file, all inside the function. Thus there is no need to open or close the file externally. At all! Ever! You have a useless and redundant mix of high-level and low-level file functions. 😉
Sure, if performance is an issues, that constant file opening and closing could be a bottleneck. So an alternative would be to use all low-level file function. You would open/create the file before the loop, keep the file open during the loop and write using plain low-level functions, then close the file after (outside) the main loop once the program finishes.
ALSO: Your subVI needs a makeover anyway. Use intuitive control labels (not "numeric"!). Arrange the FP nicely. Add some documentation. You should also do something about the icon. It is surrounded by blank space, making the wires seem to hang off in thin air. It is also a bit disconcerting that you are not doing much error handling. The main program would never know if the file program encounters an error. Then you are abusing the file open error to determine if the file exists or not. There is a function for that! You don't need to get the date/time in the error case, so this function belong inside the other case.
06-29-2010 02:16 PM
Thank you very much for your advice. I'm attaching a much improved version, not quite finished with all documentation, but much better design.