| View previous topic :: View next topic |
| Author |
Message |
ndeckard
Joined: 05 Feb 2010 Posts: 4 Location: Beech Creek, Pa
|
Posted: Fri Feb 05, 2010 3:37 pm Post subject: Using OPC DA Wrapper 2.02 with C# |
|
|
I am currently trying to write a client using the OPCAutomation reference methods in C# and I am having issues. When I run my application I get a "Specified array was not of the expected type." error on the OPCItems.AddItems line. I have tried diffenent datatypes, but was unsuccessful. Thank you in advance for you suggestions. Here is my code.
namespace ReecoHMIApp
{
public partial class Form1 : Form
{
public OPCAutomation.OPCServer AnOPCServer;
public OPCAutomation.OPCServer ConnectedOPCServer;
public OPCAutomation.OPCGroups ConnectedServerGroup;
public OPCAutomation.OPCGroup ConnectedGroup;
public string Groupname;
int ItemCount;
Array OPCItemIDs = Array.CreateInstance(typeof(string),10);
Array ItemServerHandles = Array.CreateInstance(typeof(long),10);
Array ItemServerErrors;
Array ClientHandles = Array.CreateInstance(typeof(long), 10);
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, System.EventArgs e)
{
string IOServer = "RSLinx OPC Server";
string IOGroup = "Reeco_HMI";
object RequestedDataTypes = new object[10];
object AccessPaths = new object[10];
ConnectedOPCServer = new OPCAutomation.OPCServer();
ConnectedOPCServer.Connect(IOServer,"");
ConnectedGroup = ConnectedOPCServer.OPCGroups.Add(IOGroup);
ConnectedGroup.UpdateRate = 500;
ConnectedGroup.IsSubscribed = ConnectedGroup.IsActive;
ItemCount = 1;
OPCItemIDs.SetValue("[Reeco]Central_Chamber_Temp",1);
ClientHandles.SetValue(1,1);
ConnectedGroup.OPCItems.DefaultIsActive = true;
ConnectedGroup.OPCItems.AddItems(ItemCount, ref OPCItemIDs, ref ClientHandles, out ItemServerHandles, out ItemServerErrors, RequestedDataTypes, AccessPaths);
} |
|
| Back to top |
|
 |
Randy
Joined: 27 Feb 2003 Posts: 3532 Location: OPC Foundation
|
Posted: Fri Feb 05, 2010 4:02 pm Post subject: |
|
|
| Does Visual Studio intellisense show you the parameter datatypes in the popup bubble? |
|
| Back to top |
|
 |
ndeckard
Joined: 05 Feb 2010 Posts: 4 Location: Beech Creek, Pa
|
Posted: Fri Feb 05, 2010 4:17 pm Post subject: |
|
|
Randy,
Here is what I get.
OPCAutomation.OPCItems.AddItems(int, ref System.Array, ref System.Array, out System.Array, out System.Array, object, object)
also in the Object Browser I get the following:
void AddItems(int NumItems, ref System.Array ItemIDs, ref System.Array ClientHandles, out System.Array ServerHandles, out System.Array Errors, object RequestedDataTypes, object AccessPaths) |
|
| Back to top |
|
 |
Randy
Joined: 27 Feb 2003 Posts: 3532 Location: OPC Foundation
|
Posted: Fri Feb 05, 2010 5:51 pm Post subject: |
|
|
System.Array ItemIDs <== String[]
System.Array ClientHandles <== Int32[]
System.Array ServerHandles <== Int32[]
System.Array Errors <== Int32[]
System.Array RequestedDataTypes <== Int16[]
System.Array AccessPaths <== String[] |
|
| Back to top |
|
 |
ndeckard
Joined: 05 Feb 2010 Posts: 4 Location: Beech Creek, Pa
|
Posted: Fri Feb 05, 2010 6:48 pm Post subject: |
|
|
Randy,
It works perfect! Thank you very much. Here is my code after the changes.
| Code: |
namespace ReecoHMIApp
{
public partial class Form1 : Form
{
public OPCAutomation.OPCServer AnOPCServer;
public OPCAutomation.OPCServer ConnectedOPCServer;
public OPCAutomation.OPCGroups ConnectedServerGroup;
public OPCAutomation.OPCGroup ConnectedGroup;
public string Groupname;
int ItemCount;
Array OPCItemIDs = Array.CreateInstance(typeof(string),10);
Array ItemServerHandles = Array.CreateInstance(typeof(Int32),10);
Array ItemServerErrors = Array.CreateInstance(typeof(Int32),10);
Array ClientHandles = Array.CreateInstance(typeof(Int32), 10);
Array RequestedDataTypes = Array.CreateInstance(typeof(Int16), 10);
Array AccessPaths = Array.CreateInstance(typeof(string), 10);
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, System.EventArgs e)
{
string IOServer = "RSLinx OPC Server";
string IOGroup = "Reeco_HMI";
ConnectedOPCServer = new OPCAutomation.OPCServer();
ConnectedOPCServer.Connect(IOServer,"");
ConnectedGroup = ConnectedOPCServer.OPCGroups.Add(IOGroup);
ConnectedGroup.UpdateRate = 500;
ConnectedGroup.IsSubscribed = ConnectedGroup.IsActive;
ItemCount = 1;
OPCItemIDs.SetValue("[Reeco]Central_Chamber_Temp",1);
ClientHandles.SetValue(1,1);
ConnectedGroup.OPCItems.DefaultIsActive = true;
ConnectedGroup.OPCItems.AddItems(ItemCount, ref OPCItemIDs, ref ClientHandles, out ItemServerHandles, out ItemServerErrors, RequestedDataTypes, AccessPaths);
|
|
|
| Back to top |
|
 |
Michel
Joined: 07 Mar 2003 Posts: 129 Location: 4CE Industry - Montpellier, France
|
Posted: Sun Mar 07, 2010 8:39 am Post subject: Why using the Automation Wrapper ? |
|
|
Hello,
just a related question.
Why do you want to use the Automation wrapper instead of the OPC .Net API ?
Regards,
Michel |
|
| Back to top |
|
 |
ndeckard
Joined: 05 Feb 2010 Posts: 4 Location: Beech Creek, Pa
|
Posted: Mon Mar 08, 2010 2:59 pm Post subject: |
|
|
Michel,
Thanks for the reply. To answer your question, I am not to familiar with OPC .Net API. I have used the automation wrapper in some vb6 apps and I wanted to do the same using c#. Would using the api be easier and more efficient? I am learning this opc stuff on my own and I am not a OPC memeber. Is there any documentation or examples I can learn from?
Regards,
Neal |
|
| Back to top |
|
 |
Michel
Joined: 07 Mar 2003 Posts: 129 Location: 4CE Industry - Montpellier, France
|
Posted: Mon Mar 08, 2010 3:09 pm Post subject: |
|
|
Hello,
With .Net applications OPC .Net API is clearly more efficient.
1- Let's say with the .Net API you'll ahve less software layer to go through.
In OPC .Net app using Auto Wrapper
Your App-->Automation-->..Net-->COM Interop-->OPC COM Server
In OPC .Net app using .Net API
You App-->COM Interop-->OPC COM Sever
2-OPC .Net API allows you to create DA, AE, HDA, DX, XML DA etc. All with security support.
3- OPC .Net API is provide and specify by the OPC Foundation
For my point of view. The OPC .Net API is the best choice for OPC Client dev in .Net world.
Regards,
Michel |
|
| Back to top |
|
 |
Dobipt
Joined: 17 Aug 2010 Posts: 11
|
Posted: Wed Aug 18, 2010 3:08 pm Post subject: What about Java? |
|
|
Hello Michel,
This is an old post but I have a question related.
I want to develop Java application that need to be an OPC Client to interoperate with other technologies in the same application, and my OPC Server is a classic one (DA and AE are available - TAC OPC Sever).
I googled it and I just found Java SDK from Unified Automation that uses OPC UA.
I'm trying to configure the UaGateway from Unified Automation and I'm not getting success. And I was wondering after reading this post if there is a good Java SDK client for OPC Classic.
Do you have any suggestion?
Thanks!
Regards,
Fábio |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group
|