1

我正在使用带有 Visual Studio 2012 的 OPC Foundation .NET API。当我尝试连接时,我收到此错误:

无法将“OpcCom.Factory”类型的对象转换为“Opc.IFactory”类型

...在new Opc.Da.Server(此代码中的指令:

private void button1_Click(object sender, EventArgs e)
{
    Opc.Da.Server plcServer = null;

    string serverUrl = "opcda://localhost/RSLinx OPC Server";

    plcServer = new Opc.Da.Server(new OpcCom.Factory(), new Opc.URL(serverUrl));
    plcServer.Connect();
}
4

2 回答 2

0

The problem was the version of rslinx i am using, the rslinx installed the opc .net api version 1.3 (i didn't know this) and then i installed the opc .net api 2.0 to make my opc client, so when i added the references i didn't notice that i have 2 versions of the dll's, i only picked the first i saw in the list.

At the end i was using the OpcNetApi.dll 2.0 and the OpcNetApi.Com.dll 1.3. And that's why it was throwing that error.

于 2013-08-15T22:02:46.643 回答
0

它抛出此错误是因为 for 的接口需要Opc.Da.Server一个Opc.IFactory,但从中返回的内容OpcCom.Factory()并未实现该接口。

于 2013-08-14T16:17:02.697 回答