AdvancedHMI Software
General Category => Support Questions => Topic started by: andrew_pj on February 12, 2015, 12:43:05 AM
-
Dear Archie,
I am using AHMI version 3.97e.
Got an error "InvalidCastException" on OpcDaCom.vb (Refer to attachment for details)
This occurs when I close the program by calling Application.Exit()
Please advise, Thank you.
Best regards,
Andrew
-
You can try adding this Right after the "For" line:
If values(i).ClientHandle is Nothing then Exit For
-
I know this is an old thread, but I'm having this same error show up. My application originally only had the EthernetIPforCLXCom driver and everything was fine. I've since added a second driver for OpcDaCom to communicate with an OPC server on my local machine to talk to ABB robots. Now every time I exit the program, either with the 'x' in the top right hand corner or with the exit button (which has Application.Exit()) I get the same error on the same line. I've tried adding the line you suggest, but it doesn't seem to fix the error.
Any help would be fantastic.
-
If it is only occurring on application exit, I would just trap and ignore it like this:
Dim ReturnedValues() As String = {Convert.ToString(values(i).Value)}
Dim PolledAddress As PolledAddressInfo
Try
PolledAddress = DirectCast(values(i).ClientHandle, PolledAddressInfo)
Catch ex As Exception
Exit Sub
End Try
-
Perfect, that worked!
I'm still pretty new with VB (a lot more experience with Java and Python), so I thought about catching the exception, but I didn't know how.