Closed michaelr1966 closed 2 years ago
When do get the exception? How does the callstack look like? Have you tried to catch the exception and to close the handle explicitly?
"When do get the exception?"
By open the port.
"How does the callstack look like?"
"Have you tried to catch the exception and to close the handle explicitly?"
Yes, with the code above. The number of handles still increases by 6.
Can you find out in which line exactly in the Method InitPort the exception happens?
As a workaround could you please try the following code:
{code} uses AdExcept, AwUser;
type TProtectedApdComPort = class(TApdComPort) end; TProtectedApdDispatcher = class(TApdBaseDispatcher) end;
procedure TForm1.Button1Click(Sender: TObject); begin Button1.Enabled := False; try ApdComPort1.ComNumber := 2; ApdComPort1.Baud := 115200; ApdComPort1.DataBits := 8; ApdComPort1.StopBits := 1; ApdComPort1.Parity := pNone; ApdComPort1.HWFlowOptions := []; ApdComPort1.SWFlowOptions := swfNone; try ApdComPort1.Open := True; except on E: EAPDException do begin CloseHandle(TProtectedApdDispatcher(TProtectedApdComPort(ApdComPort1).FDispatcher).ComEvent); CloseHandle(TProtectedApdDispatcher(TProtectedApdComPort(ApdComPort1).FDispatcher).ReadyEvent); CloseHandle(TProtectedApdDispatcher(TProtectedApdComPort(ApdComPort1).FDispatcher).GeneralEvent); CloseHandle(TProtectedApdDispatcher(TProtectedApdComPort(ApdComPort1).FDispatcher).OutputEvent); CloseHandle(TProtectedApdDispatcher(TProtectedApdComPort(ApdComPort1).FDispatcher).SentEvent); CloseHandle(TProtectedApdDispatcher(TProtectedApdComPort(ApdComPort1).FDispatcher).OutFlushEvent); end; end; finally Button1.Enabled := True; end; end; {code}
Here is the location were the value of -995 is set.
In the workaround code "TProtectedApdComPort(ApdComPort1).FDispatcher" is nil
I hope I could fix the issue. Could you please try?
I have tested it. That solved the problem. Thank you!
We use a service that serves various serial scales. The COM interfaces are provided via the network via COM servers from W&T (Wiesemann & Theis GmbH). If, for example, this COM interface is not available in a test environment, the exception "Apro exception" occurs.
Rec=-995
In my opinion, the reason are the 6 events (ComEvent, ReadyEvent, GeneralEvent, OutputEvent, SentEvent and OutFlushEvent) which are generated but not closed again in such a case.