예제 #1
0
        public bool SaveAllToFile(System.Windows.Forms.ProgressBar progressBar)
        {
            if (ParamDocument == null)
            {
                return(false);
            }

            progressBar.Maximum = 0;
            for (int i = 0; i < this.Messages.Count; i++)
            {
                DeviceBase.CMessage message = this.Messages[i];
                if (message.Type == 1)
                {
                    progressBar.Maximum++;
                }
            }

            for (int i = 0; i < this.Messages.Count; i++)
            {
                DeviceBase.CMessage message = this.Messages[i];
                if (message.Type == 1)
                {
                    DeviceBase.CMessage msgClone = message.Clone();
                    if (!ExchangeMessage(msgClone, new AutoResetEvent(false)))
                    {
                        return(false);
                    }

                    progressBar.Value++;
                }
            }

            for (int i = 0; i < this.Messages.Count; i++)
            {
                DeviceBase.CMessage message = this.Messages[i];
                if (message.Type == 1)
                {
                    for (int j = 0; j < message.Vars.Count; j++)
                    {
                        DeviceBase.CVar Var      = message.Vars[j];
                        Object          VarValue = RTDB.GetVarValue(this.Name, Var.Name);
                        if (VarValue != null)
                        {
                            this.SetParamValue(Var, VarValue);
                        }
                    }
                }
            }

            this.SaveParameterFile();

            return(true);
        }
예제 #2
0
        public bool SaveAllToDevice(System.Windows.Forms.ProgressBar progressBar)
        {
            if (ParamDocument == null)
            {
                return(false);
            }

            List <CMessage> readMessageList = new List <CMessage>();

            progressBar.Maximum = 0;
            XmlNodeList varList = ParamDocument.SelectNodes("/Device/Message/Var");

            foreach (XmlNode varNode in varList)
            {
                String VarName  = varNode.Attributes["Name"].Value;
                String RefValue = varNode.Attributes["Value"].Value;

                DeviceBase.CVar Var      = this.GetVar(VarName);
                Object          VarValue = RTDB.GetVarValue(this.Name, VarName);

                if (VarValue != null && VarValue.ToString() == RefValue)
                {
                    continue;
                }

                if (readMessageList.IndexOf((CMessage)Var.OwnerMessage) < 0)
                {
                    readMessageList.Add((CMessage)Var.OwnerMessage);
                }

                progressBar.Maximum++;
            }

            foreach (XmlNode varNode in varList)
            {
                String VarName  = varNode.Attributes["Name"].Value;
                String RefValue = varNode.Attributes["Value"].Value;

                DeviceBase.CVar Var      = this.GetVar(VarName);
                Object          VarValue = RTDB.GetVarValue(this.Name, VarName);

                if (VarValue != null && VarValue.ToString() == RefValue)
                {
                    continue;
                }

                if (!WriteVar(Var, RefValue, new AutoResetEvent(false)))
                {
                    return(false);
                }

                progressBar.Value++;
            }

            foreach (CMessage readMessage in readMessageList)
            {
                this.AddUpdateMessage(readMessage);
            }

            return(true);
        }