AdvancedHMI Software

General Category => Support Questions => Topic started by: andrew_pj on February 12, 2015, 12:43:05 AM

Title: OpcDaCom - InvalidCastException
Post 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
Title: Re: OpcDaCom - InvalidCastException
Post by: Archie on February 12, 2015, 09:30:05 PM
You can try adding this Right after the "For" line:

If values(i).ClientHandle is Nothing then Exit For
Title: Re: OpcDaCom - InvalidCastException
Post by: Uncle3MTA3 on October 01, 2015, 10:30:46 AM
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.
Title: Re: OpcDaCom - InvalidCastException
Post by: Archie on October 01, 2015, 10:41:08 AM
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
Title: Re: OpcDaCom - InvalidCastException
Post by: Uncle3MTA3 on October 01, 2015, 10:50:39 AM
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.