Ejemplo n.º 1
0
        /// <summary>
        /// 根据提供的nodeID及字符串,写入对应值到OPC Server
        /// </summary>
        /// <param name="nodeID"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool WriteStrDataToOpcServer(string nodeID, string data)
        {
            if (!opcContected)
            {
                opcContected = m_uaClient.ConnectOpcServerWithPwd(xmlSettings.URL, xmlSettings.UserName, xmlSettings.Password);
            }
            bool  retValue = false;
            short value    = Convert.ToInt16(data);

            try
            {
                //retValue = m_uaClient.WriteNode<short>(nodeID, value);
                retValue = m_uaClient.WriteDataToOpcServer <short>(nodeID, value);
                if (retValue)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(LogFile.Error, $"{nodeID}:{ex.Message}");
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 设置DB203站点接受是否完成
        /// </summary>
        /// <param name="i"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public bool WriteDataToOpcServer(int i, byte data)
        {
            OpcUaClient.UaClient uaClient = new OpcUaClient.UaClient();

            bool   isContected = uaClient.ConnectOpcServerWithPwd(xmlSettings.URL, xmlSettings.UserName, xmlSettings.Password);
            bool   retVal      = false;
            string nodeId      = "";

            switch (i)
            {
            case 1:
                nodeId = xmlSettings.Receive_1;
                break;

            case 2:
                nodeId = xmlSettings.Receive_2;
                break;

            case 3:
                nodeId = xmlSettings.Receive_3;
                break;

            case 4:
                nodeId = xmlSettings.Receive_4;
                break;

            case 5:
                nodeId = xmlSettings.Receive_5;
                break;

            case 6:
                nodeId = xmlSettings.Receive_6;
                break;

            case 7:
                nodeId = xmlSettings.Receive_7;
                break;

            case 8:
                nodeId = xmlSettings.Receive_8;
                break;

            case 9:
                nodeId = xmlSettings.Receive_9;
                break;

            case 10:
                nodeId = xmlSettings.Receive_10;
                break;
            }

            if (isContected && !string.IsNullOrEmpty(nodeId))
            {
                retVal = uaClient.WriteDataToOpcServer <byte>(nodeId, data);
            }
            return(retVal);
        }