Home of CLACom for Windows

CLACom FAQ's - Working with 2 or more Ports

To simultaneously monitor and process data on 2 or more Serial Ports, you need to use the Timer Event and process data in "chunks". Both of your "started" Procedures need to have a Window associated with them. This is because you need to do your work inside of an Accept Loop. The Windows, themselves, can be hidden if you have no need to display data.

In order for other Threads to run, you must CYCLE the Accept Loop. You do this by "falling through" to the End of the Accept Loop or by issuing an explicit Cycle command. If you need to import 100 or 1000 records that were received over the Serial Port, into a Database, no other Thread will run until you are finished importing the records. In 16 Bit Windows, no other Windows Program will run until you are finished.

The following is an Example of how things were done in DOS programs:

Set(MyDataBase)
Loop
   Next(MyDataBase)
   If ErrorCode()
     Break
   End
End

If there are 1000 records to process, the Loop would not terminate until an Error occurs or EOF is reached. If it takes 10 minutes to process the records, nobody cared, because your program is the only program running.

In Windows, things are quite a bit different. Your program most likely is not the only program running. Remember, you've got Windows itself running, perhaps a Clock, and perhaps a Word Processing program. If you use the above Loop in a Windows Program, and it takes 10 minutes to process the records, your Program will be non-responsive to Windows Events for 10 minutes. Move another Window on top of your Application, and then move the other Window away, and your Application will be left with a "hole" on top of it, because it is not responding to a Paint Message that Windows sends to your program to tell it to repaint itself.

Under Windows, a better approach would be to process the Records in a Timer Event. Example:

Open Window Event Handling

Set(MyDataBase)

Timer Event Handling

Loop 10 Times
   Next(MyDataBase)
   If ErrorCode()
     Break
   End
End

Note that you prepare the Data File for processing when the Window first opens. You then process 10 records at a time in the Timer Event. Since Timer Events have lower priority than other Windows Events, your Program will be responsive to the User and to Events generated outside of itself (i.e., Windows telling your Program to re-paint itself).

If you break your processing of Serial Port data into "chunks", and use the Timer Event to process the data, you will be able to simultaneously handle 2 or more Serial Ports at the same time, without too much degradation. It should be noted that you can't just take the DOS version of the Loop and put it in a Windows Timer Event. Because the Accept Loop needs to Cycle to allow other Threads to run, if it takes 10 minutes to process data in a Timer Event, the Accept Loop will not cycle until that 10 minutes is up, and you will effectively lock out other threads.