I have a fairly complex application in Delphi 2006 that communicates through an ApdComport using a separate form in another thread. The communication used to fail quite a lot and I found a couple of calls to Application.Processmessages in the loops and reconstructed it using the A开发者_JS百科pdComport.ProcessCommunications instead.
I don't really want to rearrange the code to use event handlers instead at this point.
I also want to make the communication fast so I call ProcessCommunications until there is a CharReady. Sometimes ProcessCommunications raises an ECommNotOpen exception with the message "ie_NOpen - device not open". I've been unable to find info about this in the help or on the web.
I tried putting an ApdComport on a new form in a new project and call its ProcessCommunications frequently and could not get it to crash. It did not do any real communication though.
I have tried checking that the output buffer has enough free space before sending stuff but it always has and the problem is still there.
So what is happening? Where should I look and what can I do?
Are you using a pre 4.06 version?
Search for "ie_NOpen" at this page: http://www.turbocontrol.com/APRO406Fixes.htm
This is the extracted info:
fix 3941 State machine accesses port after closing
The state machine will access the port when deactivated to write to the dispatcher log. This can cause an ie_NOpen exception under some conditions. To fix, make the following change to AdStMach.pas marked by {!!.06}
procedure TApdStateComPortSource.StateDeactivate (State : TApdCustomState);
begin
if FComPort.Open then {!!.06}
FComPort.AddStringToLog (Name + ': Deactivate');
end;
精彩评论