I am building an application that needs to read and store (ascii) data from sensors at six serial ports, every minute. The state machine (inside a while loop) I use is divided in three cases:
initialization: the six serial ports are initialized (serial settings, timeout, end character etc.). A check is performed on the actual time to see whether a new minute has started. This case runs every second (wait time). If a new minute has started, the state machine turns to the read case. Otherwise the initialization is repeated.
read: a poll is carried out for each initialized serial port (VISA write). When a message is received (VISA read), or when the time out has elapsed, it is decoded by a separate subVI for each sensor and the necessary parameters are determined from the message. Furthermore, the received message is concatenated with a date/time stamp and stored in a text file. When no message is received for a certain serial port, only the time stamp is stored for that one. A check is carried out to see whether a new hour has started. If that is the case, the processing case is executed, otherwise the program returns to initialization.
processing: hourly parameters are derived from the 60 one minute values, and stored afterwards. The program now returns to initialization.
The problem is mostly in the second (read) case. I don't actually know what is the best way to poll (and read) multiple serial ports in the same VI. Currently, I have put them all six below each other so the processes are carried out parallel and the timing is depending on the last one to finish. I think this is not ideal and it could be done easier and more efficiently. Moreover, in this way the CPU usage is very high. Every time a new minute triggers the state machine to execute the processes in the read case, it increases to 100% for the complete polling time. However, polling them in a certain sequence is not really an option I think, since I prefer to poll the sensors synchronously, if possible.
Anyone with a good idea or example?
Thanks in advance.