OPC and VB6 - Simple Remote Solution?

J

Thread Starter

Jeff Gobatto

This is going to be long so I can make sure I cover all my details.

OK here's my problem: I need a VB6 application to read and write data to an OPC server. I can get my application to work locally, but when the app is distributed to another PC it fails.

First thing: DCOM settings good at both ends - I know this b/c I'm using Matrikon OPC browser with success to get to the node, find a server, and get an item.

Second thing: tried using many OPC Automation wrappers, including Kep and some others (I can't remember where I got them). All worked locally, none remotely.

Third thing: yes, the ProgID/CLSID is in both registries. I've gotten the Intellution OPCDATA.OCX working remotely but don't want to use it in the end because it limits me to one group and 50 items.

Fourth thing: I found the Kepware VB samples. The "complex" one was WAY more than I needed, and the "simple" also seemed far more complicated than necessary.

When I run my code on a remote machine I get the Error: Method '~' of Object '~' failed... message.

The only reference is to the Kepware OPC Automation 2.0. (Plus std VB and OLE stuff).

Here's the code block:

Dim WithEvents srvOPC As OPCServer

Private Sub Command1_Click()
Dim intClientHandle As Long
Dim RetVal

Set srvOPC = New OPCServer
srvOPC.Connect "Intellution.OPCiFIX.1", "GOBATTO"
srvOPC.OPCGroups.Add "Group1"
intClientHandle = srvOPC.OPCGroups(1).ClientHandle
srvOPC.OPCGroups(1).OPCItems.AddItem "Fix.WRITE_TEST.F_CV", intClientHandle
srvOPC.OPCGroups(1).OPCItems(1).Read OPCDevice
RetVal = srvOPC.OPCGroups(1).OPCItems(1).Value
MsgBox (">" & RetVal & "<")
RetVal = CInt(RetVal) + 1
srvOPC.OPCGroups(1).OPCItems(1).Write RetVal
RetVal = srvOPC.OPCGroups(1).OPCItems(1).Value
MsgBox (">" & RetVal & "<")

Set grpOPC = Nothing
srvOPC.OPCGroups.RemoveAll
srvOPC.Disconnect

End Sub

I intend it to get a value, increment it by one, and write that new value to the server.

Can anyone offer any input as to why this fails when I try it on another machine? I'd be eternally grateful.

Thanks in advance.

Jeff
 
J

Jeff Gobatto

Solution:

1. change the declaration of the OPC Server object to:
Private srvOPC as OPCServer

2. Use the RSLinx provided DLL. (I know, seems odd, but I tried the EXACT same application with a reference to the Kepware, the Matrikon, NorDyn, and the OPC foundation ones and they all gave an RPC error -- the RSLinx one worked).

Frustrating that I cannot come up for an explanation for the declaration change. As far as the DLL thing goes, from I could gather online there is a bug of some sort with the OPC foundation's DLL that a lot of providers don't fix... apparently Rockwell did.

Anyhow, hope this thread is of use to someone.

J.
 
J
I was in the exact same situation as yourself, but the two suggestions you listed did not fix the problem. Could a DCOM issue at either end cause the error message you described?

Thanks!
 
R
check out Matrikon's OPC tunneler. The problems you are experiencing are exactly why it was created. Have it, love it, will never give it up.

Reg Meyers
 
M

Mario Elmers

Hi,

when you use iFix as OPC Server why don't use the Intellution FDS Control, it should work without errors. The Reference named: Intellution FD Data System Access Control. The OCX Name is FixDataSystems.ocx

With this control you can get a good access to your OPC Server.

Mit freundlichen Grüßen / Best Regards

Mario Elmers
 
C

Charlie Huang

Jeff Gobatto,
My codes works for several hours and it will encouter your problem. Here is my code:

Dim HeartBeat As Boolean
Dim WithEvents OPCMyserver As OPCServer
Dim WithEvents OPCMygroups As OPCGroups
Dim WithEvents OPCMygroup As OPCGroup
Dim OPCMyitems As OPCItems
Dim OPCMyitem As OPCItem

Private Sub Form_Unload(Cancel As Integer)
Unload Me
End Sub

Private Sub HeartBeatTimer_Timer()
'Test for HeartBeaten
'mySleep (1)
Dim ItemServerHandles() As Long
Dim ClientHandles(1) As Long
Dim OPCItemIDs(1) As String
Dim Errors() As Long
Dim i As Integer

'Try to connect to server

On Error GoTo ConnectError
Set OPCMyserver = New OPCServer
On Error GoTo ConnectError
OPCMyserver.Connect "KEPware.KEPServerEx.V4", ""

Set OPCMygroups = OPCMyserver.OPCGroups
Set OPCMygroup = OPCMygroups.Add("Group1")
'On Error GoTo ConnectError
OPCMygroup.UpdateRate = 100
Set OPCMyitems = OPCMygroup.OPCItems

HeartBeat = Not (HeartBeat)

ClientHandles(1) = 1
OPCItemIDs(1) = "Channel1.Device1.L130"
On Error GoTo NoItemError
OPCMyitems.AddItems 1, OPCItemIDs, ClientHandles, ItemServerHandles, Errors

Dim anItem As OPCItem
On Error GoTo NoItemError
For Each anItem In OPCMygroup.OPCItems
'anItem.Read OPCDevice
'HeartBeat=anItem.Value
On Error GoTo NoItemError
anItem.Write HeartBeat
Next anItem

Set anItem = Nothing


'begin to exit OPC Server mode properly
OPCMygroups.Remove OPCMygroup.ServerHandle

Set OPCMyitems = Nothing
Set OPCMyitem = Nothing
Set OPCMygroups = Nothing
Set OPCMygroup = Nothing

OPCMyserver.Disconnect
Set OPCMyserver = Nothing


ConnectError:
Exit Sub

NoItemError:
'If it can not write, keep on write the same value next time
HeartBeat = Not (HeartBeat)
OPCMygroups.Remove OPCMygroup.ServerHandle

Set OPCMyitems = Nothing
Set OPCMyitem = Nothing
Set OPCMygroups = Nothing
Set OPCMygroup = Nothing

OPCMyserver.Disconnect
Set OPCMyserver = Nothing
End Sub

Is anything wrong with my code? If I adjust to timer short, it may work longer. But it never is stable as I need.
Would you be email your code as my example if your code work all year round correctly? My email address is: [email protected]. Please, please....
Thank you very much!
Charlie
 
M

Mark Hensley (Kepware Technologies)

Dear Charlie,

One thing I would suggest is that you not connect to the server on your timer heart beat. It would be much more effecient if you establish your links to the OPC server in a main routine and only do the writes of your heartbeat value on the actual timer tick. I would also not add the item each time as you are doing. Simply add it once in same startup code as connecting to the server, then use the item handle to do the write from the timer subroutine.

I would also suggest you contact our technical support group for more help. They can't write your program for you but they can definitely get you pointed in the right direction.

Mark Hensley
Kepware Technologies
 
I had a similar problem, afetr checking every dll I found nothing. What I did find was that my topic configuration was incorrect in RSLinx.

RSLinx - DDE/OPC -> Topic Configuration...

I had the topic name spelled incorrectly, then i noticed it was accociated with the wrong node.

 
Please check your tag names in PLC side. If any tag missing then it fires that error Error: Method '~' of Object '~' failed...

Vishal
 
Find out where the error occurs... it could be "Method Connect of OPCServer failed" or "Method AddItem of OPCGroup failed" or something else...
 
Top