我正在编写一个从OPC服务器读取数据的代码。
public void setOPC()
{
int count = 1;
try
{
opcServer = new OPCServer();
opcServer.Connect("OPCTechs.SiemensNet30DA", "");
opcServer.OPCGroups.DefaultGroupIsActive = true;
opcServer.OPCGroups.DefaultGroupDeadband = 0f;
opcServer.OPCGroups.DefaultGroupUpdateRate = 10;
opcGroup = opcServer.OPCGroups.Add("MP");
opcGroup.IsSubscribed = false;
opcGroup.OPCItems.DefaultIsActive = false;
int[] h = new int[844];
for (int i = 69; i >= 60; i--, count++)
{
h[count] = opcGroup.OPCItems.AddItem("HH1001.B" + i, count).ServerHandle;
}
for (int i = 69; i >= 60; i--, count++)
{
h[count] = opcGroup.OPCItems.AddItem("GF1001OP190.B" + i, count).ServerHandle;
}
}在上面的代码中,当它执行第二个循环时&到达行
h[count] = opcGroup.OPCItems.AddItem("GF1001OP190.B" + i, count).ServerHandle;它给出了错误
Exception from HRESULT: 0x0040007如果它成功地执行了第一个循环AddItem,为什么它会给第二个循环带来问题?
发布于 2016-03-11 04:53:17
opcGroup.OPCItems.AddItem("GF1001OP190.B" + i, count).ServerHandle;它将在OPCItems上获得OPCItems,而不是在特定的项目上。但是,您应该获得特定项目的ServerHandle,而不是整个项目。
试一试
opcGroup.OPCItems.AddItem("GF1001OP190.B" + i, count);
h[count] = opcGroup.OPCItems[count].ServerHandle;https://stackoverflow.com/questions/35932243
复制相似问题