Esempio n. 1
0
 public void SetChannel(ChannelElement c)
 {
     Channel = c;
     this.ulbChannelName.Text   = string.IsNullOrEmpty(c.Text) ? c.Name : c.Text;
     Channel.ShowOrHideChanged += Channel_ShowOrHideChanged;
     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;
         }
     }
     //设置曲线
 }
Esempio n. 2
0
 private void ucbDeviceAddress_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ucbChannel.SelectedItem != null && ucbDeviceAddress.SelectedItem != null)
     {
         ChannelElement channel = (ChannelElement)ucbChannel.SelectedItem;
         channel.BindingArress = ucbDeviceAddress.SelectedItem.ToString() == "空"?"": ucbDeviceAddress.SelectedItem.ToString();
     }
 }
Esempio n. 3
0
 private void utbChannelName_TextChanged(object sender, EventArgs e)
 {
     if (ucbChannel.SelectedItem != null)
     {
         ChannelElement channel = (ChannelElement)ucbChannel.SelectedItem;
         channel.Text = utbChannelName.Text;
     }
 }
Esempio n. 4
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;
            }
        }
Esempio n. 5
0
 private void ucbChannel_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ucbChannel.SelectedItem != null)
     {
         ChannelElement channel = (ChannelElement)ucbChannel.SelectedItem;
         utbChannelName.Text = channel.Text;
         if (string.IsNullOrEmpty(channel.BindingArress.Trim()))
         {
             ucbDeviceAddress.SelectedIndex = 0;
         }
         else
         {
             for (int i = 0; i < ucbDeviceAddress.Items.Count; i++)
             {
                 if (ucbDeviceAddress.Items[i].ToString() == channel.BindingArress.Trim())
                 {
                     ucbDeviceAddress.SelectedIndex = i;
                     break;
                 }
             }
         }
     }
 }
Esempio n. 6
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);
            }
        }
Esempio n. 7
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);
                    }
                }
            }
        }
Esempio n. 8
0
 public void SetChannel(ChannelElement c)
 {
     Channel = c;
     Channel.ShowOrHideChanged += Channel_ShowOrHideChanged;
     chart1.Titles[0].Text      = string.IsNullOrEmpty(c.Text)?c.Name:c.Text;
 }