【问题标题】:OPC Server add items error HResultOPC Server 添加项目错误 HResult
【发布时间】:2016-03-11 04:28:59
【问题描述】:

我正在编写一个从 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,为什么它会给第二个循环带来问题?

【问题讨论】:

    标签: c# opc


    【解决方案1】:
    opcGroup.OPCItems.AddItem("GF1001OP190.B" + i, count).ServerHandle;
    

    它将获取 OPCItems 上的 ServerHandle,但不会获取特定项目上的 ServerHandle。但是您应该在特定项目而不是整个项目上获取 ServerHandle。

    试试

    opcGroup.OPCItems.AddItem("GF1001OP190.B" + i, count);
    h[count] = opcGroup.OPCItems[count].ServerHandle;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      • 1970-01-01
      • 2018-01-24
      • 1970-01-01
      • 2017-07-22
      • 2021-09-19
      相关资源
      最近更新 更多