コード例 #1
0
 private void AddParam(int index, Service.DataParamOutput addedParam)
 {
     addedParam.Address = index * 2;
     for (int i = index; i < ListDataParams.Count; i++)
     {
         ListDataParams[i].Address += 2;
     }
     ListDataParams.Insert(index, addedParam);
 }
コード例 #2
0
        private void ParamsSerialTextOut_CurrentCellChanged(object sender, System.EventArgs e)
        {
            DataGrid dataGrid = (DataGrid)sender;

            if (dataGrid.CurrentItem != null)
            {
                SelectedParam = (Service.DataParamOutput)((DataGrid)sender).CurrentItem;
            }
        }
コード例 #3
0
 private void AddParam_Click(object sender, RoutedEventArgs e)
 {
     Service.DataParam addedParam = new Service.DataParam();
     if (new SelectDataParamOutput(SparkWindow.setting.GetListInputParams(), addedParam).ShowDialog() == true)
     {
         Service.DataParamOutput addParam = new Service.DataParamOutput()
         {
             ID             = addedParam.ID,
             Title          = addedParam.Title,
             ParamUnitTitle = addedParam.ParamUnit.Title
         };
         AddParam(ListDataParams.Count, addParam);
     }
 }
コード例 #4
0
        private void RemoveParam_Click(object sender, RoutedEventArgs e)
        {
            if (SelectedParam == null)
            {
                return;
            }
            int index = ListDataParams.IndexOf(SelectedParam);

            ListDataParams.Remove(SelectedParam);
            for (int i = index; i < ListDataParams.Count; i++)
            {
                ListDataParams[i].Address -= 2;
            }
            SelectedParam = null;
        }
コード例 #5
0
        private void InsertParam_Click(object sender, RoutedEventArgs e)
        {
            if (SelectedParam == null)
            {
                return;
            }
            int index = ListDataParams.IndexOf(SelectedParam);

            Service.DataParam addedParam = new Service.DataParam();
            if (new SelectDataParamOutput(SparkWindow.setting.GetListInputParams(), addedParam).ShowDialog() == true)
            {
                Service.DataParamOutput addParam = new Service.DataParamOutput()
                {
                    ID             = addedParam.ID,
                    Title          = addedParam.Title,
                    ParamUnitTitle = addedParam.ParamUnit.Title
                };
                AddParam(index, addParam);
            }
        }
コード例 #6
0
ファイル: Deserialize.cs プロジェクト: byGriS/Spark
        public static Setting Setting(string data, SettingUnits settingUnits)
        {
            Setting setting = new Setting();

            string[] lines     = data.Split('\n');
            int      indexLine = 0;
            int      version   = lines[indexLine] != "" ? Convert.ToInt32(lines[indexLine]) : 0;

            indexLine++;
            int countInput  = Convert.ToInt32(lines[indexLine++]);
            int countOutput = Convert.ToInt32(lines[indexLine++]);
            int countWindow = Convert.ToInt32(lines[indexLine++]);

            setting.Title = lines[indexLine++];
            if (version >= 10509)
            {
                setting.Field = lines[indexLine++];
                setting.Bush  = lines[indexLine++];
                setting.Well  = lines[indexLine++];
            }
            if (version >= 10511)
            {
                setting.NKTmm = Convert.ToInt32(lines[indexLine++]);
            }
            if (version >= 10515)
            {
                setting.LengthPlan = Convert.ToDouble(lines[indexLine++]);
                setting.SpeedPlan  = Convert.ToDouble(lines[indexLine++]);
                setting.WaterPlan  = Convert.ToDouble(lines[indexLine++]);
            }

            #region Input
            for (int i = 0; i < countInput; i++)
            {
                string[] dataInput = lines[indexLine++].Split(new string[] { "#," }, StringSplitOptions.None);

                Service.Input input = (Service.Input)(Activator.CreateInstance("Service", "Service." + dataInput[0]).Unwrap());
                ((Service.InputCommon)input).Title     = dataInput[1];
                ((Service.InputCommon)input).IsUsed    = Convert.ToBoolean(dataInput[2]);
                ((Service.InputCommon)input).InputType = (Service.InputType)Enum.Parse(typeof(Service.InputType), dataInput[3]);
                if (input.GetType() == typeof(Service.InputSerial))
                {
                    ((Service.InputSerial)input).PortName       = dataInput[4];
                    ((Service.InputSerial)input).BaudRate       = Convert.ToInt32(dataInput[5]);
                    ((Service.InputSerial)input).DataBits       = Convert.ToInt32(dataInput[6]);
                    ((Service.InputSerial)input).Parity         = (Parity)Enum.Parse(typeof(Parity), dataInput[7]);
                    ((Service.InputSerial)input).StopBits       = (StopBits)Enum.Parse(typeof(StopBits), dataInput[8]);
                    ((Service.InputSerial)input).Handshake      = (Handshake)Enum.Parse(typeof(Handshake), dataInput[9]);
                    ((Service.InputSerial)input).ReadBufferSize = Convert.ToInt32(dataInput[10]);
                    ((Service.InputSerial)input).ReadTimeout    = Convert.ToInt32(dataInput[11]);
                    ((Service.InputSerial)input).Dtr            = Convert.ToBoolean(dataInput[12]);
                    ((Service.InputSerial)input).Rts            = Convert.ToBoolean(dataInput[13]);
                    ((Service.InputSerial)input).SymbolSplitter = dataInput[14];
                    ((Service.InputCommon)input).IDSlave        = Convert.ToInt32(dataInput[15]);
                }
                else
                {
                    ((Service.InputEthernet)input).IPSlave = dataInput[4];
                    ((Service.InputEthernet)input).Port    = Convert.ToInt32(dataInput[5]);
                    ((Service.InputCommon)input).IDSlave   = Convert.ToInt32(dataInput[6]);
                }
                int countParam = Convert.ToInt32(lines[indexLine++]);
                for (int j = 0; j < countParam; j++)
                {
                    string[]          dataParam = lines[indexLine++].Split(new string[] { "#," }, StringSplitOptions.None);
                    Service.DataParam param     = new Service.DataParam()
                    {
                        ID        = Convert.ToInt32(dataParam[0]),
                        Title     = dataParam[1],
                        ParamType = settingUnits.GetParamTypeByTitle(dataParam[2]),
                        SlaveID   = Convert.ToInt32(dataParam[4]),
                        Address   = Convert.ToDouble(dataParam[5]),
                        Type      = (Service.ModbusType)Enum.Parse(typeof(Service.ModbusType), dataParam[6]),
                        Command   = (Service.ModbusCommandInput)Enum.Parse(typeof(Service.ModbusCommandInput), dataParam[7]),
                        AlarmMin  = Convert.ToSingle(dataParam[8]),
                        AlarmMax  = Convert.ToSingle(dataParam[9]),
                        IsRight   = Convert.ToBoolean(dataParam[10]),
                        ColorLine = new SolidColorBrush((Color)ColorConverter.ConvertFromString(dataParam[11]))
                    };
                    param.ParamUnit = settingUnits.GetUnitByTitle(param.ParamType, dataParam[3]);
                    ((Service.InputCommon)input).ListDataParams.Add(param);
                }
                setting.Inputs.Add(input);
            }
            #endregion

            #region Outputs
            for (int i = 0; i < countOutput; i++)
            {
                string[]      dataInput = lines[indexLine++].Split(new string[] { "#," }, StringSplitOptions.None);
                Service.Input input     = (Service.Input)(Activator.CreateInstance("Service", "Service." + dataInput[0]).Unwrap());
                ((Service.InputCommon)input).Title     = dataInput[1];
                ((Service.InputCommon)input).IsUsed    = Convert.ToBoolean(dataInput[2]);
                ((Service.InputCommon)input).InputType = (Service.InputType)Enum.Parse(typeof(Service.InputType), dataInput[3]);
                if (input.GetType() == typeof(Service.InputSerial))
                {
                    ((Service.InputSerial)input).PortName       = dataInput[4];
                    ((Service.InputSerial)input).BaudRate       = Convert.ToInt32(dataInput[5]);
                    ((Service.InputSerial)input).DataBits       = Convert.ToInt32(dataInput[6]);
                    ((Service.InputSerial)input).Parity         = (Parity)Enum.Parse(typeof(Parity), dataInput[7]);
                    ((Service.InputSerial)input).StopBits       = (StopBits)Enum.Parse(typeof(StopBits), dataInput[8]);
                    ((Service.InputSerial)input).Handshake      = (Handshake)Enum.Parse(typeof(Handshake), dataInput[9]);
                    ((Service.InputSerial)input).ReadBufferSize = Convert.ToInt32(dataInput[10]);
                    ((Service.InputSerial)input).ReadTimeout    = Convert.ToInt32(dataInput[11]);
                    ((Service.InputSerial)input).Dtr            = Convert.ToBoolean(dataInput[12]);
                    ((Service.InputSerial)input).Rts            = Convert.ToBoolean(dataInput[13]);
                    ((Service.InputSerial)input).SymbolSplitter = dataInput[14];
                    ((Service.InputCommon)input).IDSlave        = Convert.ToInt32(dataInput[15]);
                }
                else
                {
                    ((Service.InputEthernet)input).IPSlave = dataInput[4];
                    ((Service.InputEthernet)input).Port    = Convert.ToInt32(dataInput[5]);
                    ((Service.InputCommon)input).IDSlave   = Convert.ToInt32(dataInput[6]);
                }
                int countParam = Convert.ToInt32(lines[indexLine++]);
                for (int j = 0; j < countParam; j++)
                {
                    string[] dataParam            = lines[indexLine++].Split(new string[] { "#," }, StringSplitOptions.None);
                    Service.DataParamOutput param = new Service.DataParamOutput()
                    {
                        ID      = Convert.ToInt32(dataParam[0]),
                        Title   = dataParam[1],
                        Address = Convert.ToDouble(dataParam[2]),
                    };
                    try {
                        param.ParamUnitTitle = dataParam[3];
                    } catch { }

                    ((Service.InputCommon)input).ListDataParamsOut.Add(param);
                }
                setting.Outputs.Add(input);
            }
            #endregion

            #region Windows
            for (int i = 0; i < countWindow; i++)
            {
                SparkControls.WindowIndicators window = new SparkControls.WindowIndicators();
                window.Title = lines[indexLine++];
                int countIndi = Convert.ToInt32(lines[indexLine++]);
                for (int j = 0; j < countIndi; j++)
                {
                    string[] dataIndi            = lines[indexLine++].Split(new string[] { "#," }, StringSplitOptions.None);
                    int      countDataParam      = Convert.ToInt32(dataIndi[0]);
                    SparkControls.Indicator indi = (SparkControls.Indicator)(Activator.CreateInstance("SparkControls", dataIndi[1]).Unwrap());
                    indi.Size     = new System.Windows.Size(Convert.ToDouble(dataIndi[2]), Convert.ToDouble(dataIndi[3]));
                    indi.Location = new System.Windows.Point(Convert.ToDouble(dataIndi[4]), Convert.ToDouble(dataIndi[5]));
                    indi.CountDot = Convert.ToInt32(dataIndi[6]);
                    if (indi.GetType() == typeof(SparkControls.IndiGraph))
                    {
                        ((SparkControls.IndiGraph)indi).GraphSetting.AxisSizeFont   = Convert.ToInt32(dataIndi[7]);
                        ((SparkControls.IndiGraph)indi).GraphSetting.LegendSizeFont = Convert.ToInt32(dataIndi[8]);
                        ((SparkControls.IndiGraph)indi).GraphSetting.LegendVis      = Convert.ToBoolean(dataIndi[9]);
                        ((SparkControls.IndiGraph)indi).GraphSetting.LineWidth      = Convert.ToInt32(dataIndi[10]);
                        ((SparkControls.IndiGraph)indi).GraphSetting.LegendPos      = (OxyPlot.LegendPosition)Enum.Parse(typeof(OxyPlot.LegendPosition), dataIndi[11]);
                        if (dataIndi.Length > 13)
                        {
                            indi.MinValue = Convert.ToDouble(dataIndi[12]);
                            indi.MaxValue = Convert.ToDouble(dataIndi[13]);
                        }
                    }
                    else
                    {
                        if (dataIndi.Length > 8)
                        {
                            indi.MinValue = Convert.ToDouble(dataIndi[7]);
                            indi.MaxValue = Convert.ToDouble(dataIndi[8]);
                        }
                    }
                    if (indi.GetType() == typeof(SparkControls.IndiSendStart))
                    {
                        ((SparkControls.IndiSendStart)indi).Input = setting.GetInputByTitle(dataIndi[9]);
                    }
                    if (indi.GetType() == typeof(SparkControls.IndiSendSoOn))
                    {
                        ((SparkControls.IndiSendSoOn)indi).Input = setting.GetInputByTitle(dataIndi[9]);
                    }
                    if (indi.GetType() == typeof(SparkControls.IndiInputStatus))
                    {
                        ((SparkControls.IndiInputStatus)indi).TimerInterval = Convert.ToInt32(dataIndi[9]);
                        ((SparkControls.IndiInputStatus)indi).Input         = setting.GetInputByTitle(dataIndi[10]);
                    }
                    for (int p = 0; p < countDataParam; p++)
                    {
                        Service.DataParam param = setting.GetParamByID(Convert.ToInt32(lines[indexLine++]));
                        if (param != null)
                        {
                            indi.DataParams.Add(param);
                        }
                    }
                    window.ListIndicators.Add(indi);
                }
                setting.Windows.Add(window);
            }
            #endregion

            return(setting);
        }