OPC Client in C# or Visual Basic (Alternate Title: OPC SUCKS!!!)

n9xcr

Member
Join Date
Aug 2008
Location
Silver Lake, WI
Posts
11
I've been attempting to use OPC off and on for the past year. I HATE OPC! DDE was so much easier, and I have yet to see any advantage to OPC. I'm hoping somebody here can change my mind. :)

I'm trying to write an application in C# and Visual Basic (Visual Studio 2008) using the Graybox OPC DA Auto Wrapper and KepServer. I haven't been able to find any good examples or tutorials to go by. I'm not an expert programmer, but I know just enough to be a little dangerous.

I want my application to load and connect to a specific OPC server automatically (preferably on a different computer on my network). Every example I find requires me to interact with the application, browsing and connecting to the OPC server. Then I have to add groups. I try to disect the examples and write my own that does all this automatically, but it never works and I keep getting lost.

Maybe it's just me, but it should be much easier than this. I'd really appreciate any help I could get here. I'm ready to just continue programming in VB6 so I can use DDE.

Thank you,
Chris (An Official OPC Hater)
 
How about switching OPC Component ?
If you are not satisfied with the functionality or documentation, then why dont take your business elsewhere.
You can also contact the vendor and tell them your troubles.
Dont tell me that you purchased the graybox component without trying it out first.

I have looked at several OPC client components and Advosols looked the most intersting to me, at least from a superficial glance.

This snippet from their description should interest you:
ItemListBuilder / ItemListLoader
Some client applications access a single OPC server and a pre-defined set of items. OPCDA.NET also provides excellent support for such applications. Instead of coding the item names into the application the OPCItemDef array required in Group.AddItems() can be created from an XML file by the ItemListLoader helper class. The XML item definition file is created interactively with the ItemListBuilder utility. The XML File can optionally be embedded in the client EXE file.
A separate XML file makes the application easy to modify. An embedded XML file prevents changes without recompilation.

So I read it as that you can hardcode the item names, you can load the item names from an XML file, and you can embed the XML file within the application.

http://www.advosol.com/pc-1-3-opcdanet.aspx
 
A project I was involved with last year used Advosol with Kepware, talking Profibus through the Hilscher DP slave PC card.

I didnt do the coding at the PC end, I was doing the PLC end (S7-400), but I was working closely with the team doing the PC application, and they didnt seem to have any problems with it.

Talk to Kepware, I have always found them helpful, even if the problem is not directly 'their fault'.

Mike
 
Don't give up on OPC. It really is a great thing. I remember writing communications code using DLLs and even in-line assembly language with Turbo-Pascal, and I don't miss it one bit.

Take a look at Software Toolbox and the products they offer. In my opinion, they have taken OPC to a new level with their ActiveX controls and .net components and, so far, I haven't been disappointed with any of their products.

Best regards
 
If you are using kepware then it comes with an opc dll for use there are also some examples I have used this on a number of occassions & it's great.
 
Welcome to the forum - that's quite a way to start your first post. I don't feel like defending one antiquated technology (DCOM) against another (DDE) - perhaps the relative simplicity of DDE does pose benefits for cases like yours. I can only hope that the next gen solution (UA) does in fact make this process easier. It certainly would for the networking aspect of your requirement where NETDDE and DCOM both suck.

Out of curiosity, what are you trying to accomplish with your project? I would say that a company selling a commercial product should stick to standards for a variety of reasons. For a small project of your own it may be most effient to find whatever tools exist to solve your particular problem - standards based or otherwise.
 
Been there, done that... not C# and not even VB.NET, but rather VB6 with KEPServer. No, it wasn't straightforward - mostly because KEPWare's manual for interfacing with KEPServer was a bit cryptic and confusing. Looking into provided sample code a few times helped me clarify a thing or two.

Now, make sure your code works with a local KEPServer first, then worry about the remote one. Communicating with a remote OPC server requires setting the DCOM on that server right - and that is not OPC, that is Windows. KEPWare has a document for that, as well as Software Toolbox.
 
BTW, what kind of PLC/device are you trying to communicate with? Just yesterday I have discovered some funny things about KEPWare driver for Omron Ethernet... now it seems trivial but I wish that kind of behavoir was described better in their documentation.
 
Thank you for all the great suggestions! Unfortunately, I work for a company (a major theme park company) where spending money is a mortal sin. It was a fight just to get KepServer. I thought that would be all I needed since it came with a .dll that could be used in my programs to communicate with the server. That's why I'm trying to get one of the free ActiveX controls to work. I tried the examples included with KepServer, but Visual Studio wanted to convert them. That resulted in various build errors. I found one or two others that worked, but was unsuccessful in adapting anything to my program.

I would love nothing more than to purchase SoftwareToolbox's .NET OPC driver. It looks like a great product! My needs would require me to purchase the Single Developer License. I don't care if I use C# or VB. I know more about VB, so I'd probably just stick with it. I haven't attempted to communicate with a remote server yet. I've been sticking with the local server until I am actually able to get this working.

The applications I'm trying to develop will retrieve data from Automation Direct PLCs. I currently have one application retrieving accounting data from a water race game, but it uses an ActiveX control I purchased from vhmiAutomation. I want to get away from using it.

The application I'm working on now will be used in a haunted house. The house has 5 DL05's with photoeyes that detect the guests walking through the house. The computer plays background music for the haunted house, and also controls a rackmount audio player that plays sound effects in various rooms. These are in-house applications that won't be made available to the public.
 
Tark said:
You might want to take a look at SoftwareToolbox's .NET OPC driver

http://www.opcdata.net/

It's a free demo with plenty of documentation http://www.opcwebclient.com/Support/Documents/documents.html and sample source code http://www.opcwebclient.com/Support/ActiveX_Downloads/Web_Based_Downloads/Apps_Downloads/apps_downloads.html

On a seperate note there is a DDE dll that you can use in .NET http://www.codeplex.com/ndde

I decided to download the demo and examples. The only example I can get to run is the OPC Server browser. I tried loading Read Single Tag example into VS2008. I went through the conversion, fixed a few lines in the code that VS didn't like, and tried to run it. It couldn't load the .dll. I tried removing the reference (so I could re-add it), but it won't let me.

I went back to my program and used the code builder. Here's what it gave me:
Code:
Value = EasyDA.ReadItemValue( _
	"", _
	"AutomationDirect.KEPDirectServer", _
	"Games.Hi-Striker Xtreme (Hometown).SP4", _
	"", _
	0 _
	)

Here is all of my code:
Code:
[size=2][color=#0000ff]Imports[/color][/size][size=2] OPCLabs.EasyOPCDANet[/size]
 
[size=2][color=#0000ff]Public[/color][/size][size=2][color=#0000ff]Class[/color][/size][size=2] FormMain
[/size][size=2][color=#0000ff]	Dim[/color][/size][size=2] EasyDA [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]New[/color][/size][size=2] EasyDACOM
	[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] Value [/size][size=2][color=#0000ff]As[/color][/size][size=2] IVTQNet
[/size][size=2][color=#0000ff]	Private[/color][/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Timer1_Tick([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] Timer1.Tick
 
		Value = EasyDA.RequestItem( _
	 [/size][size=2][color=#a31515]""[/color][/size][size=2], _
	 [/size][size=2][color=#a31515]"AutomationDirect.KEPDirectServer"[/color][/size][size=2], _
	 [/size][size=2][color=#a31515]"Games.Hi-Striker Xtreme (Hometown).SP4"[/color][/size][size=2], _[/size]
	 [size=2][color=#a31515]""[/color][/size][size=2], _[/size]
[size=2]	 0 _[/size]
[size=2]	 )
[/size]
[size=2][color=#008000]	 Label1.Visible = Value[/color][/size]
[size=2]	 EasyDA = [/size][size=2][color=#0000ff]Nothing[/color][/size]
[size=2]	 Value = [/size][size=2][color=#0000ff]Nothing
[/color][/size][size=2][color=#0000ff]End[/color][/size][size=2][color=#0000ff]Sub
 
End[/color][/size][size=2][color=#0000ff]Class
[/color][/size]

Running that program results in an exception. "Unable to cast object of type 'OPCLabs.EasyOPCDANet.ItemCOM' to type 'OPCLabs.EasyOPCDANet.IVTQNet'." It's complaining about the tag being a Boolean data type. Please tell me I'm overlooking something really stupid here.
 
Finally!!! :)

I finally figured out where I was going wrong. I can now read tags from a Kepware server on my machine. I decided to try browsing my remote server, but I can't get in. I've gone through the DCOM configuration many times over, but don't seem to be having any luck. Is there anything else I can look at?
 
See if these two interactive guides from KEPWare help:
http://www.kepware.com/Support_Center/Viewlets/XP_Dcom.html
http://www.kepware.com/Support_Center/Viewlets/XP_sp2_viewlet_swf.html

Please note the following:
1. The DCOM has to be configured on the computer that runs the KEPServer.
2. Any changes come into effect after reboot (tedious, I know.)
3. The second guide deals with some specifics of Windows XP SP2, which almost anyone has now (or SP3).
4. The first guide doesn't mention it, but you must configure the same DCOM access not only for "KEPServer" process but also for "OPCEnum".
5. Pay attention to firewall configuration as described in the guides - I dealt with servers on the corporate internal network where Windows Firewall was disabled, thank God, so it was a bit easier for me.
6. If you are not sure if your application is 100% right, use Quick Client that comes with KEPServer to try to connect to a remote server and to read a tag or two - if it works then your DCOM configuration is correct and your app should work too.
7. Skip going fancy and trying to configure a special user group that would be allowed to communicate to a remote server for now - just make sure that "Everyone" can do it. You will worry about security later.
8. This whole DCOM business is Microsoft's stuff, not KEPWare's. "BillGatesMustDie"(C) Sorry, but there is no way around it - and for a good reason.
 
Last edited:
Thanks for the links! I found a few more settings that needed to be changed. Unfortunately, I am unable to make one of the changes. I should be able to select "The interactive user" on the following screen, but it's greyed out. It's time to hit Google again. :)

KEPware%20Enhanced%20OPC-DDE%20Properties.PNG
 
No, you can't. The KEPServer should run as WinNT service for all this to work. Which, if already bought a license, should not be a problem (you won't have 2 hours timeout). Or you would have to specify a valid user name and password to run KEPServer under, but you have to make sure it is started before you can connect to it.
 

Similar Topics

Does anyone know where I can find some example C++ code for reading and writing to RSLinx OPC server. I'm just playing around and don't want to...
Replies
1
Views
4,908
I have a Win10 64 bit host for my OPC DA server, which is Indusoft (Studio,Scada.OPC.3). Locally OPC works, Matrikon OPC Explorer. On my Win7...
Replies
5
Views
1,145
Hello, I am trying to connect kepServerEx v5 in parallel with RSLinx Classic lite but kepserver will not connect to the PLC if RSLinx is active...
Replies
4
Views
2,089
Hi! We have an existing RSView32 (project made by others). It is already configured as an OPC server. Is it possible for a CLX5380 or S71500 to...
Replies
2
Views
1,484
Hello everyone ! Is there any PLC module (vendor is irrelevant at this point), that acts as an OPC client and can be used to request data from...
Replies
17
Views
5,649
Back
Top Bottom