Serial port WriteFile () freeze

I have a simple application that sends one byte to a serial port once a minute. But sometimes, for some strange reason, it hangs somewhere in the WriteFile () function. Both flow controllers sw and hw are off. I was looking for some things while waiting for read operations to be performed from other threads, but I believe this is not a problem because my application has one thread. In addition, the handle from CreateFile looks correct, so the port should not be used by any other applications. Has anyone suffered from this?

+4
source share
4 answers

If you use Google for words depending on the file name, you will find a series of discussions on this issue. Some of them are buffer overflows, the correct definition of your buffer, a defective COM port, clearing the state of an error ... It seems that there are many things to try.

Another thing I would suggest is to use a communications library instead of directly calling the API, something like Async Professional ( http://sourceforge.net/projects/tpapro/ ), even if they add some overhead to your application , they can simplify your work and avoid some potential mistakes ...

+2
source

Well, I use this library: http://lhdelphi.ic.cz/uploader/storage/ComDrv32.pas in Delphi 7, in Windows XP, but the component inside is just a wrapper around some Win API calls, CreateFile, WriteFile, etc. .d.

0
source

Have you tried setting CommPortDriver.CheckLineStatus to true ("to prevent freezing when the device is not connected or the device is turned off")? The source for the comdrv32.pas library contains this sentence.

0
source

You can also try ComPort , which for some time has been ignored, but is now actively developing again.

0
source

All Articles