Quote:
|
they both work because the processor looks at one program and then the other -- they are independant.
|
That is exactly correct. Basically, you can think of this as two programs running concurently. One of them deals with all the user interface stuff (mouse clicks, menu selection, displaying text, etc), while the other one ONLY talks to the serial port. This child process, to use the official name, would also deal with getting the data to the user interface. Far and away the easiest way of doing this is through a global variable.
In my Linux dashboard viewer, for example, all data is stored in a global struct called gRoboData. It is of type RoboData, which is basically just a struct with a variable to store each byte in. The regular part of the program then keeps reading this struct over-and-over again and updating the display as needed.
While this may seem like an overly complicated way of doing things, trust me. It is FAR easier than dealing with non-overlapped I/O.
As for whether this is C or C++, the distinction between the two is very fine. Basically, the way I chose to do multithreading is the C way of doing it. Other than that, all the code could be used under either language. I chose C for the multithreading because using the CThread class and MFC often induces more headaches than its worth.