我正在编写一个连接到远程服务器并读取数据等的 OPC 客户端。我正在使用 advosol 的 BGServer 类。问题是,当我在 Visual Studio 中运行程序时,添加组时出现以下错误。
“HRESULT 异常:0x80040202”
我的问题类似于(http://stackoverflow.com/questions/5978721/opc-server-access-remotely-using-opcda-net-tools),但是,我知道 DCom 设置配置正确,因为当我运行通过双击我连接的.exe 相同的代码,可以毫无问题地添加一个组。
因此,我猜测 Visual Studio 在一些奇怪的用户/组下运行,并且搞砸了 dcom 权限(主要是回调)。
编辑:代码
BGServer server;
private void Form1_Load(object sender, EventArgs e)
{
server = new BGServer(this);
server.Connect(new OPC.Common.Host() { HostName = "xp-devbox2", UserName = "OPCUser", Password = "OPCUser" }, "FactoryTalk Gateway", null, ServerConnected);
}
void ServerConnected(BGException ex, object tag)
{
if (ex != null)
{
label1.Text = ex.Message;
}
else
{
//we've connected to the server. let's start subscribing to stuff!
server.AddGroup("Tuner DataGroup", true, 1000, 0, null, null, new OnBGSrvAddGroup(GroupAdded));
}
}
private BGGroup dGroup;
void GroupAdded(BGException ex, BGGroup group, object tag)
{
if (ex != null)
{
label1.Text = ex.Message;
}
else label1.Text = "Group Added";
}