/// <summary>
 /// Смена описания цифрового датчика
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void digitalIO_LabelChange(object sender, DigitalIO.LabelChangeEventArgs e)
 {
     if (e.IsInput)
     {
         for (int i = 0; i < _engine.Parameters.DINSensors.Count + 1; i++)
         {
             if (i == _engine.Parameters.DINSensors.Count)
             {
                 Kontel.Relkon.DebuggerParameters.SensorLabels m_caption = new DebuggerParameters.SensorLabels();
                 m_caption.Number  = e.Index;
                 m_caption.Caption = e.Text;
                 Kontel.Relkon.DebuggerParameters.DigitalSensorDescription m_sensor = new DebuggerParameters.DigitalSensorDescription();
                 m_sensor.Labels.Add(m_caption);
                 m_sensor.Name = "DIN" + e.Key;
                 _engine.Parameters.DINSensors.Add(m_sensor);
                 break;
             }
             if (_engine.Parameters.DINSensors[i].Name == ("DIN" + e.Key))
             {
                 if ((e.Text != null) && (e.Text != ""))
                 {
                     bool m_exit = false;
                     for (int j = 0; j < _engine.Parameters.DINSensors[i].Labels.Count; j++)
                     {
                         if (_engine.Parameters.DINSensors[i].Labels[j].Number == e.Index)
                         {
                             _engine.Parameters.DINSensors[i].Labels[j].Caption = e.Text; m_exit = true;
                             break;
                         }
                     }
                     if (!m_exit)
                     {
                         Kontel.Relkon.DebuggerParameters.SensorLabels m_caption = new DebuggerParameters.SensorLabels();
                         m_caption.Number  = e.Index;
                         m_caption.Caption = e.Text;
                         _engine.Parameters.DINSensors[i].Labels.Add(m_caption);
                     }
                 }
                 else
                 {
                     for (int j = 0; j < _engine.Parameters.DINSensors[i].Labels.Count; j++)
                     {
                         if (_engine.Parameters.DINSensors[i].Labels[j].Number == e.Index)
                         {
                             _engine.Parameters.DINSensors[i].Labels.Remove(_engine.Parameters.DINSensors[i].Labels[j]); break;
                         }
                     }
                 }
                 if (_engine.Parameters.DINSensors[i].Labels.Count == 0)
                 {
                     _engine.Parameters.DINSensors.Remove(_engine.Parameters.DINSensors[i]);
                 }
                 break;
             }
         }
     }
     else
     {
         for (int i = 0; i < _engine.Parameters.DOUTSensors.Count + 1; i++)
         {
             if (i == _engine.Parameters.DOUTSensors.Count)
             {
                 Kontel.Relkon.DebuggerParameters.SensorLabels m_caption = new DebuggerParameters.SensorLabels();
                 m_caption.Number  = e.Index;
                 m_caption.Caption = e.Text;
                 Kontel.Relkon.DebuggerParameters.DigitalSensorDescription m_sensor = new DebuggerParameters.DigitalSensorDescription();
                 m_sensor.Labels.Add(m_caption);
                 m_sensor.Name = "DOUT" + e.Key;
                 _engine.Parameters.DOUTSensors.Add(m_sensor);
                 break;
             }
             if (_engine.Parameters.DOUTSensors[i].Name == ("DOUT" + e.Key))
             {
                 if ((e.Text != null) && (e.Text != ""))
                 {
                     bool m_exit = false;
                     for (int j = 0; j < _engine.Parameters.DOUTSensors[i].Labels.Count; j++)
                     {
                         if (_engine.Parameters.DOUTSensors[i].Labels[j].Number == e.Index)
                         {
                             _engine.Parameters.DOUTSensors[i].Labels[j].Caption = e.Text; m_exit = true;
                             break;
                         }
                     }
                     if (!m_exit)
                     {
                         Kontel.Relkon.DebuggerParameters.SensorLabels m_caption = new DebuggerParameters.SensorLabels();
                         m_caption.Number  = e.Index;
                         m_caption.Caption = e.Text;
                         _engine.Parameters.DOUTSensors[i].Labels.Add(m_caption);
                     }
                 }
                 else
                 {
                     for (int j = 0; j < _engine.Parameters.DOUTSensors[i].Labels.Count; j++)
                     {
                         if (_engine.Parameters.DOUTSensors[i].Labels[j].Number == e.Index)
                         {
                             _engine.Parameters.DOUTSensors[i].Labels.Remove(_engine.Parameters.DOUTSensors[i].Labels[j]); break;
                         }
                     }
                 }
                 if (_engine.Parameters.DOUTSensors[i].Labels.Count == 0)
                 {
                     _engine.Parameters.DOUTSensors.Remove(_engine.Parameters.DOUTSensors[i]);
                 }
                 break;
             }
         }
     }
 }
 /// <summary>
 /// Обновление входов и выходов цифровых
 /// </summary>
 /// <param name="Sender"></param>
 private void RefreshInterfaseDigital(object Marker, byte[] Buffer, bool Error)
 {
     if (Buffer != null && !Error && _IsOpen)
     {
         Match m;
         m = Regex.Match((string)Marker, "DIN_(\\d+)");
         if (((m != null) && (m.Length != 0)) && (_inVarsDigital.ContainsKey(Convert.ToInt32(m.Groups[1].Value))))
         {
             if (digitalIO.InVars[Convert.ToInt32(m.Groups[1].Value)].PrimaryValue != Buffer[0])
             {
                 digitalIO.ChangeStatePictures(true, Convert.ToInt32(m.Groups[1].Value), Buffer[0]);
                 foreach (Kontel.Relkon.DebuggerParameters.DigitalSensorDescription dsd in _engine.Parameters.DINSensors)
                 {
                     if (dsd.Name == "DIN" + Convert.ToInt32(m.Groups[1].Value))
                     {
                         dsd.Value = Buffer;
                         return;
                     }
                 }
                 Kontel.Relkon.DebuggerParameters.DigitalSensorDescription dsd1 = new DebuggerParameters.DigitalSensorDescription();
                 ControllerIOVar CurentValue1 = _solution.Vars.GetIOVar("IN" + Convert.ToInt32(m.Groups[1].Value));
                 if (CurentValue1 == null)
                 {
                     return;
                 }
                 dsd1.Name       = "D" + CurentValue1.Name;
                 dsd1.MemoryType = CurentValue1.Memory;
                 dsd1.Address    = CurentValue1.Address;
                 dsd1.Value      = Buffer;
                 _engine.Parameters.DINSensors.Add(dsd1);
                 return;
             }
         }
         m = Regex.Match((string)Marker, "DOUT_(\\d+)");
         if (((m != null) && (m.Length != 0)) && (_outVarsDigital.ContainsKey(Convert.ToInt32(m.Groups[1].Value))))
         {
             if (digitalIO.OutVars[Convert.ToInt32(m.Groups[1].Value)].PrimaryValue != Buffer[0])
             {
                 digitalIO.ChangeStatePictures(false, Convert.ToInt32(m.Groups[1].Value), Buffer[0]);
                 foreach (Kontel.Relkon.DebuggerParameters.DigitalSensorDescription dsd in _engine.Parameters.DOUTSensors)
                 {
                     if (dsd.Name == "DOUT" + Convert.ToInt32(m.Groups[1].Value))
                     {
                         dsd.Value = Buffer;
                         return;
                     }
                 }
                 Kontel.Relkon.DebuggerParameters.DigitalSensorDescription dsd1 = new DebuggerParameters.DigitalSensorDescription();
                 ControllerIOVar CurentValue1 = _solution.Vars.GetIOVar("OUT" + Convert.ToInt32(m.Groups[1].Value));
                 if (CurentValue1 == null)
                 {
                     return;
                 }
                 dsd1.Name       = "D" + CurentValue1.Name;
                 dsd1.MemoryType = CurentValue1.Memory;
                 dsd1.Address    = CurentValue1.Address;
                 dsd1.Value      = Buffer;
                 _engine.Parameters.DOUTSensors.Add(dsd1);
                 return;
             }
         }
     }
 }