コード例 #1
0
 /// <summary>
 /// Событие при потере фокуса полем "Начальный адрес"
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void StartAddress_Leave(object sender, EventArgs e)
 {
     try
     {
         if (this.tbStartAddress.Text[0] == '0' && this.tbStartAddress.Text[1] == 'x')
         {
             _Address          = AppliedMath.HexToDec(this.tbStartAddress.Text);
             _HexAddressCoding = true;
         }
         else
         {
             _Address          = int.Parse(this.tbStartAddress.Text);
             _HexAddressCoding = false;
         }
     }
     catch
     {
         SetValues();
         return;
     }
     if (this._Address == 0 && this.ddlMemoryType.Text == "SD Card")
     {
         this._Address = 1;
     }
     if (this._Address >= MaxMemoryValue())
     {
         this._Address = MaxMemoryValue() - 1;
     }
     if (this._Size + this._Address > MaxMemoryValue())
     {
         this._Size = MaxMemoryValue() - this._Address;
     }
     _engine.Parameters.ViewMemoryAddress = _Address;
     this.SetValues();
 }
コード例 #2
0
 /// <summary>
 /// Событие при смене типа памяти
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MemoryType_SelectedValueChanged(object sender, EventArgs e)
 {
     _Address = AppliedMath.HexToDec(this.tbStartAddress.Text);
     if (this._Address == 0 && this.ddlMemoryType.Text == "SD Card")
     {
         this._Address = 1;
     }
     if (this._Address >= MaxMemoryValue())
     {
         this._Address = MaxMemoryValue() - 1;
     }
     if (this._Size + this._Address > MaxMemoryValue())
     {
         this._Size = MaxMemoryValue() - this._Address;
     }
     this.SetValues();
     _engine.Parameters.ViewMemoryType = GetMemoryType(this.ddlMemoryType.Text);
 }
コード例 #3
0
        /// <summary>
        /// Событие при потере фокуса полем "Размер считывания"
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReadingSize_Leave(object sender, EventArgs e)
        {
            try
            {
                if (this.tbReadingSize.Text[0] == '0' && this.tbReadingSize.Text[1] == 'x')
                {
                    this._Size     = AppliedMath.HexToDec(this.tbReadingSize.Text);
                    _HexSizeCoding = true;
                }
                else
                {
                    _Size          = int.Parse(this.tbReadingSize.Text);
                    _HexSizeCoding = false;
                }
            }
            catch
            {
                SetValues();
                return;
            }
            if (this._Size == 0)
            {
                this._Size = 1;
            }
            int m_size = 32767 / this.heMemory.SymbolHeight * this.heMemory.SegmentSize;

            if (this._Size > m_size)
            {
                this._Size = m_size;
            }
            if (this._Size + _Address > MaxMemoryValue())
            {
                this._Size = MaxMemoryValue() - this._Address;
            }
            _engine.Parameters.ReadingSize = _Size;
            this.SetValues();
        }
コード例 #4
0
        /// <summary>
        /// Записть измененного знаячения при завершении редактирования ячейки
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgv_askStructs_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            //Определение правильности введенного значения
            bool m_error = false;
            //Определение изменяемой переменной
            DataRow m_CurrentRow = (DataRow)this.DisplayVarsTable.Rows[this.dgv_askStructs.CurrentRow.Index];

            //Определения правльности входных данных. Формирование массива для записи
            Byte[] m_Vars         = new Byte[4];
            Byte[] m_WriteVars    = new Byte[(int)m_CurrentRow[7]];
            int    m_SignValue    = 0;
            String m_CurrentValue = "";

            if (this.dgv_askStructs[e.ColumnIndex, e.RowIndex].Value.ToString().Trim() != "")
            {
                if (this.codingType == 10)
                {
                    m_CurrentValue = (String)(this.dgv_askStructs[e.ColumnIndex, e.RowIndex].Value);
                }
                else
                {
                    if ((int)m_CurrentRow[7] == 4)
                    {
                        m_CurrentValue = Convert.ToString((UInt32)(AppliedMath.HexToDec((String)this.dgv_askStructs[e.ColumnIndex, e.RowIndex].Value)));
                    }
                    else
                    {
                        m_CurrentValue = Convert.ToString(AppliedMath.HexToDec((String)this.dgv_askStructs[e.ColumnIndex, e.RowIndex].Value));
                    }
                    if (this.dgv_askStructs[e.ColumnIndex, e.RowIndex].Value.ToString().Contains("-"))
                    {
                        m_error = true;
                    }
                }
                try { long i = long.Parse(m_CurrentValue); }
                catch { m_error = true; }
            }
            else
            {
                m_error = true;
            }
            if ((!m_error) && ((Convert.ToInt64(m_CurrentValue) <= (long)m_CurrentRow[8]) && (Convert.ToInt64(m_CurrentValue) >= (long)m_CurrentRow[9])))
            {
                //Преобразование
                if (!((long)m_CurrentRow[9] < 0 || (int)m_CurrentRow[7] == 4))
                {
                    UInt32 m_Value = 0;
                    m_Value = Convert.ToUInt32(m_CurrentValue);
                    for (int i = 0; i < 4; i++)
                    {
                        m_Vars[i] = (Byte)(m_Value % 256);
                        m_Value   = m_Value / 256;
                    }
                    Array.Reverse(m_Vars);
                    m_SignValue = AppliedMath.BytesToInt(m_Vars);
                }
                else
                {
                    m_SignValue = Convert.ToInt32(m_CurrentValue);
                }
                m_Vars = AppliedMath.IntToBytes(m_SignValue);
                Array.Reverse(m_Vars);
                for (int i = 0; i < m_WriteVars.Length; i++)
                {
                    m_WriteVars[i] = m_Vars[i];
                }
                if (!_engine.Parameters.InverseByteOrder)
                {
                    Array.Reverse(m_WriteVars);
                }
            }
            else
            {
                m_error = true;
            }
            if (m_error)
            {
                this.dgv_askStructs[e.ColumnIndex, e.RowIndex].Value = this._EditCellText;
            }
            else
            {
                //Запись переменной в память
                _engine.AddWriteItem((int)m_CurrentRow[6], GetMemoryType(m_CurrentRow[5].ToString()), m_WriteVars, "vars_write_" + m_CurrentRow[1].ToString() + "_" + m_CurrentRow[0].ToString(), null, null);
            }
            this._EditRow = null;
        }
コード例 #5
0
 /// <summary>
 /// Событие при оканчании редактирования значения переменной
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgVars_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         //Определение правильности введенного значения
         bool m_error = false;
         //Определение изменяемой переменной
         Kontel.Relkon.Classes.ControllerVar m_newVar = _solution.Vars.GetVarByName((String)this.dgVars[0, e.RowIndex].Value);
         DataRow m_CurrentRow = (DataRow)this.Table.Rows[this.dgVars.CurrentRow.Index];
         for (int i = 0; i < this.Table.Rows.Count; i++)
         {
             if ((String)this.Table.Rows[i][0] == this._EditVar)
             {
                 m_CurrentRow = (DataRow)this.Table.Rows[i];
                 break;
             }
         }
         //Определения правльности входных данных. Формирование массива для записи
         Byte[] m_Vars      = new Byte[4];
         Byte[] m_WriteVars = new Byte[m_newVar.Size];
         int    m_SignValue = 0;
         if (m_newVar is ControllerUserVar && ((ControllerUserVar)m_newVar).Array)
         {
             String m_ArrayVar   = (String)this.dgVars[e.ColumnIndex, e.RowIndex].Value;
             String m_CurrentVar = "";
             for (int i = 0; i < m_newVar.Size; i++)
             {
                 if (m_ArrayVar.IndexOf(' ') > 0)
                 {
                     m_CurrentVar = m_ArrayVar.Substring(0, m_ArrayVar.IndexOf(' '));
                     m_ArrayVar   = m_ArrayVar.Substring(m_ArrayVar.IndexOf(' ') + 1);
                 }
                 else
                 {
                     m_CurrentVar = m_ArrayVar;
                     m_ArrayVar   = "";
                 }
                 if (this.codingType == 16)
                 {
                     try { if (!((Convert.ToInt64(Convert.ToByte(AppliedMath.HexToDec(m_CurrentVar))) <= long.Parse(m_CurrentRow[2].ToString())) && ((Convert.ToInt64(Convert.ToByte(AppliedMath.HexToDec(m_CurrentVar)))) >= long.Parse(m_CurrentRow[3].ToString()))))
                           {
                               m_error = true;
                           }
                     }
                     catch { m_error = true; }
                     if ((AppliedMath.IsValidHexNumber(m_CurrentVar)) && (!m_error))
                     {
                         m_WriteVars[i] = Convert.ToByte(AppliedMath.HexToDec(m_CurrentVar));
                     }
                     else
                     {
                         m_error = true; break;
                     }
                 }
                 else
                 {
                     if ((AppliedMath.IsValidDecNumber(m_CurrentVar)) && ((Convert.ToInt64(m_CurrentVar) <= long.Parse(m_CurrentRow[2].ToString())) && (Convert.ToInt64(m_CurrentVar) >= long.Parse(m_CurrentRow[3].ToString()))))
                     {
                         m_WriteVars[i] = Convert.ToByte(m_CurrentVar);
                     }
                     else
                     {
                         m_error = true; break;
                     }
                 }
                 if ((m_ArrayVar.Trim() == "") && (i < m_newVar.Size - 1))
                 {
                     m_error = true;
                     break;
                 }
             }
         }
         else
         {
             String m_CurrentValue = "";
             if (this.codingType == 10)
             {
                 m_CurrentValue = (String)(this.dgVars[e.ColumnIndex, e.RowIndex].Value);
             }
             else
             {
                 if (m_newVar.Size == 4)
                 {
                     m_CurrentValue = Convert.ToString((UInt32)(AppliedMath.HexToDec((String)this.dgVars[e.ColumnIndex, e.RowIndex].Value)));
                 }
                 else
                 {
                     m_CurrentValue = Convert.ToString(AppliedMath.HexToDec((String)this.dgVars[e.ColumnIndex, e.RowIndex].Value));
                 }
             }
             try { long i = long.Parse(m_CurrentValue); }
             catch { m_error = true; }
             if ((!m_error) && ((Convert.ToInt64(m_CurrentValue) <= long.Parse(m_CurrentRow[2].ToString())) && (Convert.ToInt64(m_CurrentValue) >= long.Parse(m_CurrentRow[3].ToString()))))
             {
                 //Преобразование
                 if (this.codingType == 10)
                 {
                     if (m_newVar.HasSign)
                     {
                         m_SignValue = Convert.ToInt32(this.dgVars[e.ColumnIndex, e.RowIndex].Value);
                     }
                     else
                     {
                         if (m_newVar.Size == 4)
                         {
                             UInt32 m_Value = 0;
                             m_Value = Convert.ToUInt32(this.dgVars[e.ColumnIndex, e.RowIndex].Value);
                             for (int i = 0; i < 4; i++)
                             {
                                 m_Vars[i] = (Byte)(m_Value % 256);
                                 m_Value   = m_Value / 256;
                             }
                             Array.Reverse(m_Vars);
                             m_SignValue = AppliedMath.BytesToInt(m_Vars);
                         }
                         else
                         {
                             m_SignValue = Convert.ToInt32(this.dgVars[e.ColumnIndex, e.RowIndex].Value);
                         }
                     }
                 }
                 else
                 {
                     m_SignValue = Convert.ToInt32(AppliedMath.HexToDec((String)this.dgVars[e.ColumnIndex, e.RowIndex].Value));
                 }
                 m_Vars = AppliedMath.IntToBytes(m_SignValue);
                 //закоментированный вариант корректно опрашивает только с обратным порядокм байт
                 //if (_engine.Parameters.InverseByteOrder) Array.Reverse(m_Vars);
                 //for (int i = 0; i < m_WriteVars.Length; i++) m_WriteVars[i] = m_Vars[i];
                 for (int i = 0; i < m_WriteVars.Length; i++)
                 {
                     m_WriteVars[i] = m_Vars[i + (4 - m_WriteVars.Length)];
                 }
                 if (_engine.Parameters.InverseByteOrder)
                 {
                     Array.Reverse(m_WriteVars);
                 }
             }
             else
             {
                 m_error = true;
             }
         }
         if (m_error)
         {
             this.dgVars[e.ColumnIndex, e.RowIndex].Value = this._EditCellText;
         }
         else
         {
             //Запись переменной в память
             _engine.AddWriteItem(m_newVar.Address, m_newVar.Memory, m_WriteVars, "vars_write_" + m_newVar.Name, null, null);
         }
         this._EditVar = "";
     }
     catch (Exception ex)
     {
         this.dgVars[e.ColumnIndex, e.RowIndex].Value = this._EditCellText;
         this._EditVar = "";
         Utils.ErrorMessage("dgVars_CellEndEdit: " + ex.Message);
         return;
     }
 }