AdvancedHMI Software

General Category => Support Questions => Topic started by: sarclimber on August 14, 2016, 06:41:10 PM

Title: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on August 14, 2016, 06:41:10 PM
I am trying to use OPCDACom in Visual Studio Community to read the tags I have set up in Red Lion's OPCWorx OPC Server.  When I run the application the connection to the OPC server is working, or at least it does not show an error in Visual Studio once I figured out the OPC server address.  My question is the what to put into the PLCAddressValue field.  I am not currently connected to a PLC, only a Red Lion G3 HMI with tags resident in the HMI.  I tried putting the HMI tag name in the address field and a cannot connect error occurred.  My ultimate goal is to have an application which monitors data from multiple HMI's and will change button colors based on tag values.  The HMI's will be connected to IDEC PLC's and the tags will be mapped to the HMI's.  The tag name in the PLC is the same as the mapped tag name in the HMI so I am not sure it will have an effect when I am actually connected to the PLC.  All hardware will be connected via a wireless network.  Any suggestions would be very appreciated.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Archie on August 15, 2016, 08:15:39 AM
Since there are so many variations in the different OPC servers specify address, the technique I use is to use an OPC Browser or OPC Test Client to let it browse the available addresses, then copy that into the PLCAddressValue property.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on August 15, 2016, 04:12:55 PM
Thanks......used an OPC test client and found the tags in the HMI.  Example address is "HMI1.test".  Now getting an OPC connect error whenever I put a tag address in the PLC address field and run the application.  I am not sure the server path is correct as none of the test clients show me what I understand to be a path.  I have tried the complete path to where the OPCWorx config file is located with no change.  Is there a particular format or a way to find the server path? 
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Archie on August 15, 2016, 04:59:21 PM
The Server Name is specific to the vendor and can be the most difficult to find. The OPC browser may give you a list of available servers and the specific name. If the server is on the same PC, then the OPCServerPath should remain at its default of opcda://localhost

Some OPC servers also require a topic.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on August 15, 2016, 05:15:17 PM
OK, changed path to opcda://localhost.  This did change when I get the connect error.  I am using a pilot light connected to a Boolean tag in the HMI.  As soon as I launch the application a message appears in the pilot light that says cannot connect to OPC server and it gives the specific server name I was able to find in several different opc test clients.  I am beginning to think I am missing something that Visual Studio requires?  Do you know if Red Lion OPCWorx server requires a topic?  Tanks again for all your help.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Archie on August 15, 2016, 06:32:09 PM
I have never used OPCWorx, so I will take a stab in the dark. I found this in a reference manual:

"You will find the OPCWorx servers listed as RedLionControls.name, where name is the type of server(s) you’ve configured, and have set active"

The AdvancedHMI is already setup for OPC, so it is just a matter of getting the ServerName and Topic (if needed) correct.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: bachphi on August 15, 2016, 07:26:39 PM
It's unclear to me how it's connected. Can you ping from your laptop to PC and PLC?
Is the RedLion OPC server running on the PC?
If that is the case, see the pic in this msg :http://advancedhmi.com/forum/index.php?topic=598.msg5723#msg5723
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on August 16, 2016, 08:40:24 AM
You nailed it Archie.  I had been using cut and paste to enter the server name after browsing it in several OPC test clients.  After reading your post I saw the lack of spaces in "RedLionControls".  The test clients had spaces and so did my entry in Visual Studio.  Removed spaces and all is talking.  Just for info bachphi, yes the OPC server is running on the PC and the pc is on the same network as the HMI, no plc is connected yet.  Now the real fun begins.  Thanks for all the help.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on November 15, 2016, 01:07:42 PM
Finally getting back to this project and I am having what I believe to be a problem with Visual Basic (maybe??)  but maybe someone can point out my error.  For instance when I drop a BasicIndicator onto my form and assign a plc tag to "PLCAddressSelectColor2" I get a "Object reference not set to an instance of an object" displaying in the indicator when the project is run.  I am using the Red Lion OPCWorx server and verified that the tag I am using is available via a OPC explorer program.  I have the OpcDaCom component in my form with the OPCserver set to what the explorer program is using and the path set to opcda://localhost as the Red Lion server is on the same pc that runs the program.  All my internet forum searching points to trying to set a value into something that is "nothing" which I do not understand as I am not writing any code for this BasicIndicator...just trying to set the background color based on a plc tag value.  Once again I have confirmed that the tag value is available via the OPC explorer.

I am in new territory here so any ideas would be appreciated.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on November 15, 2016, 04:35:05 PM
More info on above question...

There are two exceptions being thrown when I debug the application.

'Opc.NotConnectedException'
'System.NullReferenceException'

Since I can see the OPC server tags with an OPC explorer I believe the problem to be in my OpcDaCom configuration.

OPCGroup is blank, I tried setting a group based on the OPC explorer with no change, red Lion OPCWorx does not show any groups
OPCServer is RedLionControls.G3OPCServer.1  this matches the OPC explorer
OPCServerPath is opcda://localhost  application and server are on same pc
OPCTopic is blank

Thanks for any thoughts.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Archie on November 15, 2016, 05:49:36 PM
This is sounding like an OPC and OpcDaCom problem which can be quite difficult to troubleshoot. We need to figure out where the exception is coming from. What version of Visual Studio are you using?

This might be a good place to start:

- In Solution Explorer, expand down the AdvancedHMIDrivers project
- Look for OpcDaCom.vb , right click and select View Code
- Go to line 524 and look for this code:

    Private Sub DataChangedCallBack(ByVal clientHandle As Object, ByVal requestHandle As Object, ByVal values() As Opc.Da.ItemValueResult)
        For i = 0 To values.Length - 1


- To the left of line 525, click in the left margin to insert a break point
- Run the application
- When and if it stops at the breakpoint, use F10 to step through the code and see how far it gets
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on November 15, 2016, 06:06:10 PM
Visual Studio Community 2015  Ver 14.0.25425.01 Update 3

Did not stop at the breakpoint
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Archie on November 15, 2016, 06:21:21 PM
Ctrl+Alt+E will open an Exception Setting window which will probably be at the bottom. Add a check to the box Common Language Runtime exception. Then run the application again
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on November 16, 2016, 04:15:50 PM
OK, tried that with no change.  Just for grins I reinstalled AdvancedHMI in a different location and built a very simple program using only a basic indicator.  The PLCAddressVisible property was set to a plc address Boolean tag that I can browse with an opc explorer.  When I first ran the program I got a "CoCreateInstanceEx: Class Not registered" error in the basic indicator and then it went to "Object reference not set to an instance of an object" error.

Tried debugging this simple program and it did not get to the breakpoint either.

Thanks for your time.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Godra on November 16, 2016, 04:33:17 PM
Your issue might also be related to DCOM permissions.

If you search this forum for "dcom" you will find several OPC related topics mentioning those.

And bunch of resources on the Internet for the same.

Could you post pictures of your OPC explorer and server tags and anything else related?
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Archie on November 16, 2016, 05:17:41 PM
What makes OPC so difficult is its complexity and reliance on multiple vendors software. For example the OpcDaCom of AdvancedHMI has to work with the libraries supplied by the OPC Foundation which in turn must work with a 3rd party OPC server.

Your first message CoCreateInstanceEx is related to the Windows COM interface and as Godra mentioned this could be a DCOM issue.

I'm not sure why you did not get a program break after setting it to break on all Common Language Exceptions, unless of course the problem is outside of AdvancedHMI. The next step I would take is to put a break point at line 421, which should be this:

 If DLL Is Nothing Then CreateDLLInstance()

This is where the first contact with the driver occurs. If it hits that break point, then use F10 to step through until you get an exception.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on November 16, 2016, 06:58:25 PM
Thanks for the new idea on DCOM but no luck there either.  Since the application is running on a network that is not connected to the outside world I turned off Windows Firewall and opened up DCOM to everybody for everything...no change.

The opc explorer screenshot shows a "group" on the Matrikon explorer but I am using Red Lion OPCWorx and it does not show a group as shown in the OPCWorx screenshot.  As an example I am using a plc address of "Summit.AZ1" and putting that into the PLCAddress field.  I tried adding the server name into the  PLCAddress field even though it seemed redundant and it had no effect.

Just as a sanity check I verified that I can view the remote Red Lion HMI in a browser window using the Red Lions web browser feature and it works fine which further confirms my network connectivity.


Just prior to posting this I saw your reply Archie.  The program did stop at line 421 and using F10 it stopped again at line 94..

DLL.Url = New Opc.Url(m_OPCServerPath & "/" & m_OPCServer)

Since I am somewhat sure that my OPCServer address in OpcDaCom is correct this is going to send me in a new direction.  The pc I am using to develop this application is different from the one I am attempting to run it on for reasons to verbose to mention here.  I am going to have to take the pc which runs the application home and download Visual Studio and redo all your debugging suggestions while I am attempting to connect to the OPC server and remote Red Lion in real-time.  I will report back with results.

If there are any more ideas please post and in the meantime I will work on getting Visual Studio downloaded/installed.

Thanks for all the help, I would be totally lost without everybodys help.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Archie on November 16, 2016, 07:46:47 PM
When you reach this line of code with F10:

DLL.Url = New Opc.Url(m_OPCServerPath & "/" & m_OPCServer)

Before pressing F10 again, hover over m_OPCServerPath and m_OPCServer to see what their values are. This seems to be looking like it's not finding the server to connect to.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Godra on November 16, 2016, 08:18:57 PM
Also, try using BasicLabel control for testing (it is usually the simplest yet powerful choice).

The tag name Summit.LiftRunning, as the explorer shows it, is what you should have in the PLCAddressValue field of the BasicLabel. Put it also in the PLCAddressKeypad field, which will allow you to change the value by clicking the control.

For comparison, if Matrikon.OPC.Simulation.1 server is installed as well then try testing its tags in the PLCAddressValue field of the BasicLabel (Bucket Brigade.Boolean would be an example tag and you would have to change the server name in the OpcDaCom driver).


And, for the sake of double-checking, can you read this article for verification:

https://www.softwaretoolbox.com/dcom/html/dcom_for_windows_7-_8-_-_server_2008.html

If it is Windows 10 then try finding related article somewhere on the web.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on November 17, 2016, 03:37:59 PM
Once again you guys pointed me in the right direction!  Went through the DCOM link Godra sent and verified all settings and ended making some changes.  Also discovered that OPCEnum was not showing up in Component Services.  It was not installed for some reason.  Installed and set the security policies correctly Ran the application and got a OPC error in the BasicLabel control.  That was progress.  Checked OPCEnum in Services and it was not started.  Fixed that and now BasicLabel changes colors based on tag from remote HMI.  All of that is probably basic knowledge but I had to learn it the hard way.

My brain hurts.

You guys are a wealth of knowledge...thanks!!
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on November 17, 2016, 04:05:47 PM
Well, not sure why but not working again.  Getting "Failed OPC Read ( OPCDACom)" now.  Will go through troubleshooting steps from last posts and report back.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on November 18, 2016, 11:07:26 AM
More info...

When I first made the changes to DCOM and installed OPCEnum the application worked.  No changes were made and when I attempted to run program again I am getting the "Failed OPC Read (OPCDACom)" exception.  Running in debug mode throws an exception at line 482, if I am correct the reason is that in line 481 "values(0).ResultID" is {E_FAIL} when I hover over it.  The application does start and seems to run for about 2 seconds before it throws the exception.

I have rebooted computer and made sure OPCEnum service is running, network connectivity has been verified, all DCOM security settings I changed are still there.  The Matrikon OPC Explorer is still running and finds the HMI tags no problem.

For what it is worth my network is wireless and does not have blazing speed.  Is it possible that the application needs more time to read the data tags over the network?  I do not understand why it was working and now it is not.  What now?
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Godra on November 18, 2016, 12:45:26 PM
There are a few different things you can try:

1) Install MatrikonOPC Simulator and test AHMI with it (if it works continuously that would indicate that AHMI is functional, if it works for a while and then stops that could indicate some sort of intermittent communication even though it's on the same computer)
2) Download one of the previous releases of AHMI and give it a try
3) Create a new user account and try all the testing again under this account
4) Try cleaning all the temporary files from the computer (DO THESE STEPS AT OWN RISK-> close all open applications, press Logo+R and in the Run box type %temp% and then delete all temporary files that you see in this user temp folder. If you open Windows Explorer then you can browse to Windows/Temp folder and delete all files there as well. Whatever files you cannot delete just skip them). Without promoting it, the CCleaner free app might help with some removal as well.
5) If you have access to another computer then attempt tests on it

Whatever steps you can do might just help you in troubleshooting this issue.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on November 18, 2016, 06:03:22 PM
No luck with temp files.  Having trouble locating an older version of AHMI to download, can you point me in the right direction?

Thanks.
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Godra on November 18, 2016, 08:39:40 PM
You can find m, n, p versions here:

https://sourceforge.net/projects/advancedhmi/files/advancedhmi/3.5/
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Archie on November 19, 2016, 02:29:48 PM
Not sure if this would make any difference, but here is something to try:

- Edit OpcdaCom.vb
- Go to about line 425 and look for this code:

SubscriptionState.UpdateRate = 5

- Change the 5 to a 500
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: sarclimber on November 21, 2016, 07:26:23 PM
Everything seems to be working now.  Older versions of AHMI had same problem.  Installed Matrikon OPCSimulator and it worked good pointing to a problem outside of AHMI.  I noticed awhile back that OPCWorx did not show up as a service when I was changing DCOM settings.  Red Lion tech support stated that OPCWorx does not run as a service but rather as an application.  This got me to thinking the problem had to be an access issue.  While digging through the security settings for various programs looking for clues I found a setting for "ALL APPLICATION PACKAGES".  I added this to the group/user name security settings for OPCWorx and Visual Studio and and gave it full access and the "Failed OPC Read (OPCDACom)" error is fixed.

Thank you Archie and Godra for your continued support!  Now I will see what else I can break! 
Title: Re: Connect to Red Lion OpcWorx Server Tags?
Post by: Archie on November 21, 2016, 07:42:56 PM
Glad to hear you got it working. Every time I see OPC mentioned, it makes me cringe because I know more chance than not it can be a long drawn out process to troubleshoot. So it's good to hear you figured it out without too much pain.