Randy C
April 24th, 1999, 12:27 PM
This is going to be a tough nut to crack. I built up multithreaded serial Comm drivers, using the model Allen Denver presented in his Multi Threaded MTTTY example, on the Microsoft Knowledge base. It works fine. but there are some instances where I need to talk to very primitive devices, and a delay is needed between characters that I write to the port. Interestingly, the baud rate does not make a significant difference. Anywhere from 57.6K baud down to 9600, I still need an intercharacter delay of at least 250 microseconds to make it work. This is where the problem comes in. The messages I need to send are 25 byte packets, and there are lots of them to complete a "download". So simply doing a "Sleep" between Write calls is no good. I don't know what the specification is, but as near as I can tell, Sleep(1) doesn't seem to resolve to less then 10 milliseconds at best. That makes the download take forever. I've tried brute forcing a delay between write calls, by doing the obviously horrendous practice of waiting in a loop, using the multimedia timeGetTime() call. That works better, since timeGetTime() does resolve to a millisecond, at least on Win 95. By keeping my application thread at a slightly lower than normal priority, and keeping the Write thread at HIGHEST_PRIORITY, this kludge works wiithout impacting the system too badly. But it still falls apart once I try to go below 3 milliseconds. At that point, the overlapped events seem to pile up, and garbage comes out of the port. Maybe Overlapped I/O was not a good idea for Writing, but it is needed for robust reading, and the portt can't be opened both ways at once.
This is nonsense. I have a DOS version of the same program I'm porting that easilly forces a 1 millisecond delay between writes to the COMM port. While my above kludge works, 3 milliseconds is overkill for intercharacter delay, and the performance is still only about 10% of the DOS version. With all the COMM port handshaking features built into the operating system, how is it that such a simple feature as character delay has been left out? Am I missing something? It really should be done at a low level. Using a scope, I can see that even a 1/4 millisecond (250 uS) delay would work. Yet the API provides no apparent way to tap into the many high frequency counters that must be available in your average machine running at hundreds of MegaHertz.
Can anyone think of a strategy for doing a character delay, at least down to (an actual millisecond)? I'm not afraid to get down to the interupt and driver level if I have to, but an off the shelf solution would be nice, even if I have to buy it.
Thanks
--Randy C
* * * Second star to the Right!
This is nonsense. I have a DOS version of the same program I'm porting that easilly forces a 1 millisecond delay between writes to the COMM port. While my above kludge works, 3 milliseconds is overkill for intercharacter delay, and the performance is still only about 10% of the DOS version. With all the COMM port handshaking features built into the operating system, how is it that such a simple feature as character delay has been left out? Am I missing something? It really should be done at a low level. Using a scope, I can see that even a 1/4 millisecond (250 uS) delay would work. Yet the API provides no apparent way to tap into the many high frequency counters that must be available in your average machine running at hundreds of MegaHertz.
Can anyone think of a strategy for doing a character delay, at least down to (an actual millisecond)? I'm not afraid to get down to the interupt and driver level if I have to, but an off the shelf solution would be nice, even if I have to buy it.
Thanks
--Randy C
* * * Second star to the Right!