Пример #1
0
        public void SetChannel(ChannelElement c, ChannelAlarm channelAlarm)
        {
            ChannelAlarm = channelAlarm;
            Channel      = c;
            Channel.ShowOrHideChanged += Channel_ShowOrHideChanged;
            this.ulbChannelName.Text   = string.IsNullOrEmpty(c.Text) ? c.Name : c.Text;
            for (int i = 0; i < this.Controls.Count; i++)
            {
                if (this.Controls[i].GetType() == typeof(Sunny.UI.UILabel))
                {
                    UILabel label = (UILabel)this.Controls[i];
                    label.SetStyle(GasMonitorManager.MainForm.Style);
                    label.ForeColor = Color.White;
                }
                else if (this.Controls[i].GetType() == typeof(Sunny.UI.UILine))
                {
                    UILine line = (UILine)this.Controls[i];
                    line.SetStyle(GasMonitorManager.MainForm.Style);
                    line.ForeColor = Color.Red;
                }
                else if (this.Controls[i].GetType() == typeof(Sunny.UI.UISymbolLabel))
                {
                    UISymbolLabel line = (UISymbolLabel)this.Controls[i];
                    line.SetStyle(GasMonitorManager.MainForm.Style);
                    line.ForeColor   = Color.White;
                    line.SymbolColor = Color.Green;
                }
            }
            //配置报价参数
            if (channelAlarm != null)
            {
                ParaAlarm O2Alarm  = channelAlarm.ParaAlarms.Find(x => x.Name == "O2");
                ParaAlarm COAlarm  = channelAlarm.ParaAlarms.Find(x => x.Name == "CO");
                ParaAlarm CO2Alarm = channelAlarm.ParaAlarms.Find(x => x.Name == "CO2");
                ParaAlarm H2SAlarm = channelAlarm.ParaAlarms.Find(x => x.Name == "H2S");
                this.ucbO2Enable.Checked  = O2Alarm != null && O2Alarm.Enable == "1" ? true : false;
                this.ucbCO2Enable.Checked = CO2Alarm != null && CO2Alarm.Enable == "1" ? true : false;
                this.ucbCOEnable.Checked  = COAlarm != null && COAlarm.Enable == "1" ? true : false;
                this.ucbH2SEnable.Checked = H2SAlarm != null && H2SAlarm.Enable == "1" ? true : false;
                decimal Low  = 0;
                decimal High = 0;
                uudCOLow.Value  = decimal.TryParse(COAlarm.Low, out Low) ? Low : 0;
                uudCOHigh.Value = decimal.TryParse(COAlarm.High, out High) ? High : 0;

                uudCO2Low.Value  = decimal.TryParse(CO2Alarm.Low, out Low) ? Low : 0;
                uudCO2High.Value = decimal.TryParse(CO2Alarm.High, out High) ? High : 0;

                uudH2SLow.Value  = decimal.TryParse(H2SAlarm.Low, out Low) ? Low : 0;
                uudH2SHigh.Value = decimal.TryParse(H2SAlarm.High, out High) ? High : 0;

                uudO2Low.Value  = decimal.TryParse(O2Alarm.Low, out Low) ? Low : 0;
                uudO2High.Value = decimal.TryParse(O2Alarm.High, out High) ? High : 0;
            }
        }
Пример #2
0
        public bool WriterConfig()
        {
            try
            {
                XmlDocument doc = new XmlDocument();

                doc.Load(Application.StartupPath + "/config.xml");
                XmlNode list = doc.SelectSingleNode("/Config");
                foreach (XmlNode item in list.ChildNodes)
                {
                    if (item.Name == "SerialPort")
                    {
                        item["BaudRate"].InnerText = SerialPort.BaudRate;
                        item["CheckBit"].InnerText = SerialPort.CheckBit;
                        item["DataBits"].InnerText = SerialPort.DataBits;
                        item["Port"].InnerText     = SerialPort.Port;
                        item["StopBit"].InnerText  = SerialPort.StopBit;
                        item["CollectFaultsInternal"].InnerText = SerialPort.CollectFaultsInternal;
                        item["CollectFaultsNumber"].InnerText   = SerialPort.CollectFaultsNumber;
                        item["ContinueCollect"].InnerText       = SerialPort.ContinueCollect;
                        item["OffsetInterval"].InnerText        = SerialPort.OffsetInterval;
                        item["PackMaxSize"].InnerText           = SerialPort.PackMaxSize;
                        item["ReadTimeout"].InnerText           = SerialPort.ReadTimeout;
                        item["RSTSendPreKeeyTime"].InnerText    = SerialPort.RSTSendPreKeeyTime;
                        item["RTSEnable"].InnerText             = SerialPort.RTSEnable;
                        item["RTSSendAfterKeeyTime"].InnerText  = SerialPort.RTSSendAfterKeeyTime;
                        item["WriteTimeout"].InnerText          = SerialPort.WriteTimeout;
                        item["ModbusType"].InnerText            = SerialPort.ModbusType;
                    }
                    else if (item.Name == "MQTT")
                    {
                        item["Account"].InnerText             = MQTT.Account;
                        item["ClientID"].InnerText            = MQTT.ClientID;
                        item["CommandSubTopic"].InnerText     = MQTT.CommandSubTopic;
                        item["DataPublicTopic"].InnerText     = MQTT.DataPublicTopic;
                        item["PassiveSubTopic"].InnerText     = MQTT.PassiveSubTopic;
                        item["Password"].InnerText            = MQTT.Password;
                        item["Port"].InnerText                = MQTT.Port;
                        item["PublicType"].InnerText          = MQTT.PublicType;
                        item["ServerIP"].InnerText            = MQTT.ServerIP;
                        item["UpdateCycle"].InnerText         = MQTT.UpdateCycle;
                        item["UpdateCycleSubTopic"].InnerText = MQTT.UpdateCycleSubTopic;
                    }
                    if (item.Name == "Channels")
                    {
                        for (int i = 0; i < item.ChildNodes.Count; i++)
                        {
                            if (item.ChildNodes[i].Name == "Channel")
                            {
                                ChannelElement channelElement = Channels[i];
                                item.ChildNodes[i]["DeviceAddress"].InnerText = channelElement.BindingArress;
                                item.ChildNodes[i]["ChannelID"].InnerText     = channelElement.Id;
                                item.ChildNodes[i]["ChannelName"].InnerText   = channelElement.Name;
                                item.ChildNodes[i]["ChannelText"].InnerText   = channelElement.Text;
                            }
                        }
                    }
                    if (item.Name == "ChannelAlarms")
                    {
                        XmlNodeList alarmList = item.SelectNodes("Alarm");
                        for (int i = 0; i < alarmList.Count; i++)
                        {
                            XmlNode      alarmNode    = alarmList[i];
                            ChannelAlarm channelAlarm = this.ChannelAlarms[i];
                            alarmNode.Attributes["ChanelID"].Value = channelAlarm.ChanelID;
                            for (int j = 0; j < alarmNode.ChildNodes.Count; j++)
                            {
                                XmlNode paraNode = alarmList[i].ChildNodes[j];
                                paraNode.Attributes["Enable"].Value = channelAlarm.ParaAlarms[j].Enable;
                                paraNode.Attributes["Name"].Value   = channelAlarm.ParaAlarms[j].Name;
                                paraNode["AlarmHigh"].InnerText     = channelAlarm.ParaAlarms[j].High;
                                paraNode["AlarmLow"].InnerText      = channelAlarm.ParaAlarms[j].Low;
                            }
                        }
                    }
                }

                doc.Save(Application.StartupPath + "/config.xml");

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Пример #3
0
        public void ReadConfig()
        {
            AdminUser          = new Admin();
            AdminUser.UserName = "******";
            AdminUser.Password = "******";
            ModbusPara         = new List <ModbusPara>();
            SerialPort         = new SerialPortConfig();
            MQTT     = new MQTTConfig();
            Channels = new List <ChannelElement>();
            XmlDocument doc = new XmlDocument();

            doc.Load(Application.StartupPath + "/config.xml");
            XmlNode list = doc.SelectSingleNode("/Config");

            foreach (XmlNode item in list.ChildNodes)
            {
                if (item.Name == "SerialPort")
                {
                    SerialPort.BaudRate = item["BaudRate"].InnerText.Trim();
                    SerialPort.CheckBit = item["CheckBit"].InnerText.Trim();
                    SerialPort.DataBits = item["DataBits"].InnerText.Trim();
                    SerialPort.Port     = item["Port"].InnerText.Trim();
                    SerialPort.StopBit  = item["StopBit"].InnerText.Trim();
                    SerialPort.CollectFaultsInternal = item["CollectFaultsInternal"].InnerText.Trim();
                    SerialPort.CollectFaultsNumber   = item["CollectFaultsNumber"].InnerText.Trim();
                    SerialPort.ContinueCollect       = item["ContinueCollect"].InnerText.Trim();
                    SerialPort.OffsetInterval        = item["OffsetInterval"].InnerText.Trim();
                    SerialPort.PackMaxSize           = item["PackMaxSize"].InnerText.Trim();
                    SerialPort.ReadTimeout           = item["ReadTimeout"].InnerText.Trim();
                    SerialPort.RSTSendPreKeeyTime    = item["RSTSendPreKeeyTime"].InnerText.Trim();
                    SerialPort.RTSEnable             = item["RTSEnable"].InnerText.Trim();
                    SerialPort.RTSSendAfterKeeyTime  = item["RTSSendAfterKeeyTime"].InnerText.Trim();
                    SerialPort.WriteTimeout          = item["WriteTimeout"].InnerText.Trim();
                    SerialPort.ModbusType            = item["ModbusType"].InnerText.Trim();
                }
                else if (item.Name == "MQTT")
                {
                    MQTT.Account             = item["Account"].InnerText.Trim();
                    MQTT.ClientID            = item["ClientID"].InnerText.Trim();
                    MQTT.CommandSubTopic     = item["CommandSubTopic"].InnerText.Trim();
                    MQTT.DataPublicTopic     = item["DataPublicTopic"].InnerText.Trim();
                    MQTT.PassiveSubTopic     = item["PassiveSubTopic"].InnerText.Trim();
                    MQTT.Password            = item["Password"].InnerText.Trim();
                    MQTT.Port                = item["Port"].InnerText.Trim();
                    MQTT.PublicType          = item["PublicType"].InnerText.Trim();
                    MQTT.ServerIP            = item["ServerIP"].InnerText.Trim();
                    MQTT.UpdateCycle         = item["UpdateCycle"].InnerText.Trim();
                    MQTT.UpdateCycleSubTopic = item["UpdateCycleSubTopic"].InnerText.Trim();
                }
                else if (item.Name == "Admin")
                {
                    AdminUser.UserName = item["UserName"].InnerText.Trim();
                    AdminUser.Password = item["Password"].InnerText.Trim();
                }
                if (item.Name == "Channels")
                {
                    foreach (XmlNode subNode in item.ChildNodes)
                    {
                        if (subNode.Name == "Channel")
                        {
                            ChannelElement channelElement = new ChannelElement();
                            channelElement.BindingArress = subNode["DeviceAddress"].InnerText.Trim();
                            channelElement.Id            = subNode["ChannelID"].InnerText.Trim();
                            channelElement.Name          = subNode["ChannelName"].InnerText.Trim();
                            channelElement.Text          = subNode["ChannelText"].InnerText.Trim();
                            Channels.Add(channelElement);
                        }
                    }
                }
                if (item.Name == "Modbus")
                {
                    foreach (XmlNode subNode in item.ChildNodes)
                    {
                        if (subNode.Name == "ModbusParaItem")
                        {
                            ModbusPara paraElement = new ModbusPara();
                            paraElement.Name          = subNode.Attributes["Name"].Value.Trim();
                            paraElement.StartRegister = string.IsNullOrEmpty(subNode.Attributes["StartRegister"].Value.Trim())?0:int.Parse(subNode.Attributes["StartRegister"].Value.Trim());

                            paraElement.RegisterNum = string.IsNullOrEmpty(subNode.Attributes["RegisterNum"].Value.Trim()) ? 0 : int.Parse(subNode.Attributes["RegisterNum"].Value.Trim());
                            paraElement.Enable      = string.IsNullOrEmpty(subNode.Attributes["Enable"].Value.Trim()) ? 0 : int.Parse(subNode.Attributes["Enable"].Value.Trim());
                            paraElement.ModbusCode  = subNode.Attributes["ModbusCode"].Value.Trim();

                            ModbusPara.Add(paraElement);
                        }
                    }
                }
                if (item.Name == "ChannelAlarms")
                {
                    XmlNodeList alarmList = item.SelectNodes("Alarm");
                    foreach (XmlNode alarmNode in alarmList)
                    {
                        ChannelAlarm channelAlarm = new ChannelAlarm();
                        channelAlarm.ParaAlarms = new List <ParaAlarm>();
                        channelAlarm.ChanelID   = alarmNode.Attributes["ChanelID"].Value.Trim();
                        foreach (XmlNode paraNode in alarmNode.ChildNodes)
                        {
                            channelAlarm.ParaAlarms.Add(new ParaAlarm {
                                Enable = paraNode.Attributes["Enable"].Value.Trim(),
                                Name   = paraNode.Attributes["Name"].Value.Trim(),
                                High   = paraNode["AlarmHigh"].InnerText.Trim(),
                                Low    = paraNode["AlarmLow"].InnerText.Trim()
                            });
                        }
                        this.ChannelAlarms.Add(channelAlarm);
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// 传入读取的数据,data, 报警 alarm,报警状态 ,alarmstatus
        /// </summary>
        /// <param name="data"></param>
        /// <param name="alarm"></param>
        /// <param name="alarmStatu"></param>
        public void SetReadData(ReceiveItem data, ReceiveItem alarm, ReceiveItem alarmtatus)
        {
            ChannelAlarm channelAlarm = GasMonitorManager.Config.ChannelAlarms.Find(x => int.Parse(x.ChanelID) == int.Parse(this.Channel.Id));

            uledTime.Text = ScadaHexByteOperator.GetDateTime(data.DateTime).Value.ToString("HH:mm:ss");
            ///设置值
            switch (data.Name)
            {
            case "CO":
                uledCO.Text  = data.Value.ToString();
                uslabCO.Text = data.Name + "/" + data.Unit;

                //系统报警优先
                if (alarmtatus.Value.ToString() == "0")    //无报警
                {
                    uledbubCO.Color   = Color.Green;
                    uiLedAlarmCO.Text = "";
                }
                else if (alarmtatus.Value.ToString() == "1")    //低报警
                {
                    uledbubCO.Color   = Color.Yellow;
                    uiLedAlarmCO.Text = alarm.Value.ToString();
                }
                else if (alarmtatus.Value.ToString() == "2")    //高报警
                {
                    uledbubCO.Color   = Color.Red;
                    uiLedAlarmCO.Text = alarm.Value.ToString();
                }
                //设置曲线
                if (channelAlarm != null)
                {
                    ParaAlarm paraAlarm = channelAlarm.ParaAlarms.Find(x => x.Name.Trim().ToUpper() == "CO" && x.Enable == "1");
                    //表示系统报警开启
                    if (paraAlarm != null)
                    {
                        float high = Convert.ToSingle(paraAlarm.High);
                        float low  = Convert.ToSingle(paraAlarm.Low);
                        float v    = Convert.ToSingle(data.Value);
                        if (v <= low)
                        {
                            uledbubCO.Color   = Color.Yellow;
                            uiLedAlarmCO.Text = alarm.Value.ToString();
                        }
                        else if (v >= high)
                        {
                            uledbubCO.Color   = Color.Red;
                            uiLedAlarmCO.Text = alarm.Value.ToString();
                        }
                    }
                }
                break;

            case "EX":
                uledEX.Text  = data.Value.ToString();
                uslabEX.Text = data.Name + "/" + data.Unit;
                if (alarmtatus.Value.ToString() == "0")    //无报警
                {
                    uledbubEX.Color   = Color.Green;
                    uiLedAlarmEX.Text = "";
                }
                else if (alarmtatus.Value.ToString() == "1")    //低报警
                {
                    uledbubEX.Color   = Color.Yellow;
                    uiLedAlarmEX.Text = alarm.Value.ToString();
                }
                else if (alarmtatus.Value.ToString() == "2")    //高报警
                {
                    uledbubEX.Color   = Color.Red;
                    uiLedAlarmEX.Text = alarm.Value.ToString();
                }
                if (channelAlarm != null)
                {
                    ParaAlarm paraAlarm = channelAlarm.ParaAlarms.Find(x => x.Name.Trim().ToUpper() == "EX" && x.Enable == "1");
                    if (paraAlarm != null)
                    {
                        //表示系统报警开启
                        float high = Convert.ToSingle(paraAlarm.High);
                        float low  = Convert.ToSingle(paraAlarm.Low);
                        float v    = Convert.ToSingle(data.Value);
                        if (v <= low)
                        {
                            uledbubEX.Color   = Color.Yellow;
                            uiLedAlarmEX.Text = alarm.Value.ToString();
                        }
                        else if (v >= high)
                        {
                            uledbubEX.Color   = Color.Red;
                            uiLedAlarmEX.Text = alarm.Value.ToString();
                        }
                    }
                }

                break;

            case "H2S":
                uledH2S.Text  = data.Value.ToString();
                uslabH2S.Text = data.Name + "/" + data.Unit;
                if (alarmtatus.Value.ToString() == "0")    //无报警
                {
                    uledbubH2S.Color   = Color.Green;
                    uiLedAlarmH2S.Text = "";
                }
                else if (alarmtatus.Value.ToString() == "1")    //低报警
                {
                    uledbubH2S.Color   = Color.Yellow;
                    uiLedAlarmH2S.Text = alarm.Value.ToString();
                }
                else if (alarmtatus.Value.ToString() == "2")    //高报警
                {
                    uledbubH2S.Color   = Color.Red;
                    uiLedAlarmH2S.Text = alarm.Value.ToString();
                }
                if (channelAlarm != null)
                {
                    ParaAlarm paraAlarm = channelAlarm.ParaAlarms.Find(x => x.Name.Trim().ToUpper() == "H2S" && x.Enable == "1");
                    //表示系统报警开启
                    if (paraAlarm != null)
                    {
                        float high = Convert.ToSingle(paraAlarm.High);
                        float low  = Convert.ToSingle(paraAlarm.Low);
                        float v    = Convert.ToSingle(data.Value);
                        if (v <= low)
                        {
                            uledbubH2S.Color   = Color.Yellow;
                            uiLedAlarmH2S.Text = alarm.Value.ToString();
                        }
                        else if (v >= high)
                        {
                            uledbubH2S.Color   = Color.Red;
                            uiLedAlarmH2S.Text = alarm.Value.ToString();
                        }
                    }
                }
                break;

            case "O2":
                uledO2.Text  = data.Value.ToString();
                uslabO2.Text = data.Name + "/" + data.Unit;
                if (alarmtatus.Value.ToString() == "0")    //无报警
                {
                    uledbubO2.Color   = Color.Green;
                    uiLedAlarmO2.Text = "";
                }
                else if (alarmtatus.Value.ToString() == "1")    //低报警
                {
                    uledbubO2.Color   = Color.Yellow;
                    uiLedAlarmO2.Text = alarm.Value.ToString();
                }
                else if (alarmtatus.Value.ToString() == "2")    //高报警
                {
                    uledbubO2.Color   = Color.Red;
                    uiLedAlarmO2.Text = alarm.Value.ToString();
                }

                if (channelAlarm != null)
                {
                    ParaAlarm paraAlarm = channelAlarm.ParaAlarms.Find(x => x.Name.Trim().ToUpper() == "H2S" && x.Enable == "1");
                    //表示系统报警开启
                    if (paraAlarm != null)
                    {
                        float high = Convert.ToSingle(paraAlarm.High);
                        float low  = Convert.ToSingle(paraAlarm.Low);
                        float v    = Convert.ToSingle(data.Value);
                        if (v <= low)
                        {
                            uledbubO2.Color   = Color.Yellow;
                            uiLedAlarmO2.Text = alarm.Value.ToString();
                        }
                        else if (v >= high)
                        {
                            uledbubO2.Color   = Color.Red;
                            uiLedAlarmO2.Text = alarm.Value.ToString();
                        }
                    }
                }
                break;
            }
            if (!string.IsNullOrEmpty(data.Value) && data.Value != "-9999")
            {
                uiLedDeviceStatus.Color = Color.Green;
            }

            int index = this.chart1.Series["Series" + data.Name].Points.AddXY(ScadaHexByteOperator.GetDateTime(data.DateTime).Value.ToString("mm:ss"), data.Value);

            if (data.Value == "-9999")
            {
                this.chart1.Series["Series" + data.Name].Points[index].IsEmpty = true;
            }
            if (this.chart1.Series["Series" + data.Name].Points.Count > 200)
            {
                this.chart1.Series["Series" + data.Name].Points.RemoveAt(0);
            }
            if (this.chart1.Series["Series" + data.Name].Points.Count > 0)
            {
                if (this.chart1.Series["Series" + data.Name].YAxisType == System.Windows.Forms.DataVisualization.Charting.AxisType.Primary)
                {
                    this.chart1.ChartAreas[this.chart1.Series["Series" + data.Name].ChartArea].AxisY.Maximum = this.chart1.Series["Series" + data.Name].Points.FindMaxByValue().YValues[0] + this.chart1.Series["Series" + data.Name].Points.FindMaxByValue().YValues[0] / 10.0d;
                }
                else
                {
                    this.chart1.ChartAreas[this.chart1.Series["Series" + data.Name].ChartArea].AxisY2.Maximum = this.chart1.Series["Series" + data.Name].Points.FindMaxByValue().YValues[0] + this.chart1.Series["Series" + data.Name].Points.FindMaxByValue().YValues[0] / 10.0d;
                }
            }
        }