Author Topic: com problem - invalid cast exception  (Read 8326 times)

Thegreyghost

  • Newbie
  • *
  • Posts: 13
    • View Profile
com problem - invalid cast exception
« on: December 21, 2014, 02:04:14 PM »
Downloaded latest version of software (v3.94 beta) and ran it on Visual Studio 2013.  Had no problems installing, building, or adding a com control and a panel meter from the toolbar.  Configured the com control for com 6, which is where my DF1 driver for Rslinx is configured for my micrologix PLC.  Pointed my panel meter at N7:2 in my data table and ran the application.  What i get is the error in the attached file.  I've also tried the same scenario using OPC rather than the df1 connection.  It generates the same error at the same point in the code.  Neither seem to make a connection with Rslinx or the PLC.

Let me start by saying that I'm very new to Visual studio.  I've used VB6 in the past with Rslinx and OPC successfully, but am struggling with the conversion to .net.  If it helps, I'm running an older build of Rslinx (2.42) - Gateway.

Seems like I'm missing something simple, but I have no idea what at this point.

Any help is appreciated.

Jeff.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: com problem - invalid cast exception
« Reply #1 on: December 21, 2014, 02:56:41 PM »
I can't validate this right now, but here is a start of something to try. Open EthernetIPforPLCSLCMicroCom.vb in the AdvancedHMIDrivers project found in Solution Explorer. Go to line 403 and change the code to this:


        If DLL IsNot Nothing AndAlso DLL.Count > MyDLLInstance AndAlso DLL(MyDLLInstance) IsNot Nothing Then


Rebuild the solution and try it again.

Thegreyghost

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: com problem - invalid cast exception
« Reply #2 on: December 21, 2014, 03:57:37 PM »
No dice.  The OPC driver seems to error on creating the dll instance (line 91) of the OPCdacom.vb code.
The DF1 seems to error in the get processor type routine.   I'm kind of flying blind when it comes to interpreting this code, so bear with me if I'm pointing out things that have nothing to do with the problem I'm having.

I'll try to send you the output from the debug window.  It has some errors with file loads that may help.

Thanks for the quick response.
Jeff.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: com problem - invalid cast exception
« Reply #3 on: December 21, 2014, 04:13:38 PM »
You can try the previous version. Version 3.94 had some driver changes that affect the AB drivers.

Thegreyghost

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: com problem - invalid cast exception
« Reply #4 on: December 21, 2014, 04:25:24 PM »
O.K.  Thanks.  Dumb question - where do i get the older versions?

Jeff.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: com problem - invalid cast exception
« Reply #5 on: December 21, 2014, 04:34:08 PM »
http://sourceforge.net/projects/advancedhmi/files/advancedhmi/3.5/

You wil be able to get several previous version at that link

Thegreyghost

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: com problem - invalid cast exception
« Reply #6 on: December 21, 2014, 04:44:39 PM »
Yep.  Did find some.  Was able to get 3.87 - same problems.   Has to be something in my configuration.  Sometimes Rslinx does some strange things, although i can connect through their OPC test client just fine.


Thanks for the suggestions,
Jeff.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: com problem - invalid cast exception
« Reply #7 on: December 21, 2014, 04:48:03 PM »
If you can use the native drivers, they are easier than OPC. If you are using the DF1Com driver, you need to make sure RSLinx is completely shut down

Thegreyghost

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: com problem - invalid cast exception
« Reply #8 on: December 21, 2014, 05:14:22 PM »
Yes, I guess i should have realized that seeing as it's a serial connection.  That got rid of the error for the DF1 driver, but it's failing to get the processor type and update the display.  Does this require the PC to have a physical serial port?  The laptop I've been running this through utilizes virtual com ports.   It still makes a DF1 connection so long as the virtual com port is configured correctly.  One of the reason i was leaning on using OPC.

Jeff.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: com problem - invalid cast exception
« Reply #9 on: December 21, 2014, 05:32:09 PM »
There is "bypass"to get around the Failed To Get Processor.

- Open AllenBradleyPCCC.vb in the AdvancedHMiDrivers project
- Go to line 427
- Insert the following line just below the function declaration:

Return &H78


It should look like this after inserting the line of code:

    Public Function GetProcessorType() As Integer
        Return &H78
        If m_ProcessorType <> 0 Then
            Return m_ProcessorType


After making the change Rebuild the Solution

Thegreyghost

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: com problem - invalid cast exception
« Reply #10 on: December 21, 2014, 06:02:30 PM »
That did work, and it did open the com port, but fails to retrieve the data.  Error -1, read failed result = -20 no data returned.

FYI - I found the code you were referring to on line 437.

Jeff.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: com problem - invalid cast exception
« Reply #11 on: December 21, 2014, 06:13:05 PM »
I will have to do some testing with this later tonight when I can get to a PLC

Thegreyghost

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: com problem - invalid cast exception
« Reply #12 on: December 21, 2014, 06:20:11 PM »
Thank-you for all the time you spent on this already.  I appreciate it.  If you need any additional information about the components i'm using, please let me know.

Jeff.

Thegreyghost

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: com problem - invalid cast exception
« Reply #13 on: December 21, 2014, 07:54:01 PM »
Ironically, I tried the ABDF1 ver200beta project and it works perfectly.  This is good since it verifies that i should be able to connect through the virtual com port on my machine.  Hope this helps.

Jeff.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: com problem - invalid cast exception
« Reply #14 on: December 21, 2014, 11:49:39 PM »
The good news is that I found the problem, but it will need to be a fix in the next release which will probably come in the next couple days.

The DF1 driver is the oldest driver, so it's structure is far behind the other drivers making it a little more tricky to troubleshoot. Also the demand has been drastically falling off, so the testing of it before new releases tends to get neglected.