Exemplo n.º 1
0
        /// <summary>
        /// 写入数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>;
        private void btnWriteDataItem_Click(object sender, RoutedEventArgs e)
        {
            string message = null;

            if (!opcClienthelper.IsConnected)
            {
                message = DateTime.Now.ToString(dateString) + "请先连接服务器" + System.Environment.NewLine;
                asyncUpMessage(message);
                return;
            }
            OpcDataItem opcDataItem = null;
            OpcResult   opcResult   = OpcResult.Unknow;

            if (Equals(null, opcClienthelper.OpcDataItems) || opcClienthelper.OpcDataItems.Count < 1)
            {
                message = DateTime.Now.ToString(dateString) + "没有数据点" + System.Environment.NewLine;
            }
            else
            {
                opcDataItem = opcClienthelper.OpcDataItems.FirstOrDefault().Clone() as OpcDataItem;
                //bool newValue = (DateTime.Now.Millisecond % 2) == 0 ? true : false;
                //bool newValue = !tmpValue;
                //tmpValue = newValue;
                //System.Diagnostics.Debug.Print(tmpValue.ToString());
                opcResult = opcClienthelper.Write(opcDataItem, 1);
                message   = DateTime.Now.ToString(dateString) + "写入完成 " + opcResult + " " + (opcDataItem == null ? " " : opcDataItem.ToString()) + System.Environment.NewLine;
            }
            asyncUpMessage(message);
        }