/// <summary> /// Однократное чтение /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bAdd_Click(object sender, EventArgs e) { try { this.bWrite.Enabled = false; this.bRead.Enabled = false; this.bTimerRead.Enabled = false; this.ddlMemoryType.Enabled = false; this.tbStartAddress.Enabled = false; this.tbReadingSize.Enabled = false; _readAddress = _Address; _readSize = _Size; _readMemory = GetMemoryType(this.ddlMemoryType.Text); _engine.AddReadItem(_readAddress, _readMemory, _readSize, "memory_one", StatusCallBack, CallBack); this.pbStatus.Visible = true; } catch { this.bWrite.Enabled = true; this.bTimerRead.Enabled = true; this.bRead.Enabled = true; this.ddlMemoryType.Enabled = true; this.tbStartAddress.Enabled = true; this.tbReadingSize.Enabled = true; this.pbStatus.Visible = false; } finally { } }
/// <summary> /// Добавление переменной структуры на опрос /// </summary> /// <param name="m_row"></param> private void AddRowToAsk(DataRow m_row) { if (this._IsReading) { try { _engine.AddReadItem((int)m_row[6], GetMemoryType(m_row[5].ToString()), (int)m_row[7], m_row, null, CallBack); } catch { } } }
/// <summary> /// Составление запросов на опрос процессов /// </summary> private void AddedReadItems() { if (!_IsReading) { for (int i = 0; i < this.dgProcess.Rows.Count; i++) { ProjectProcess m_p = this._solution.GetProcessByName((string)this.dgProcess.Rows[i].Cells[0].Value); //_engine.AddReadItem(_engine.Parameters.ProcessorType == ProcessorType.MB90F347 ? (m_p.Address + 6) : (m_p.Address + 5), MemoryType.XRAM, _engine.Parameters.ProcessorType == ProcessorType.MB90F347 ? 4 : 2, this.dgProcess.Rows[i], null, CallBack); _engine.AddReadItem(m_p.Address + 4, MemoryType.XRAM, 4, this.dgProcess.Rows[i], null, CallBack); } _IsReading = true; } }
/// <summary> /// Составление опросов датчиков /// </summary> private void AddedReadItems() { IList <int> m_key; if (this.tabControl1.SelectedPage != null && this.tabControl1.SelectedPage.Name == "tpDigital") { //Запуск стандартных датчиков //Запуск на четние цифровых датчиков m_key = _inVarsDigital.Keys; for (int i = 0; i < _inVarsDigital.Count; i++) { if (this.cbDefault.Checked || _engine.Parameters.ProcessorType == ProcessorType.AT89C51ED2 || i > 3) { try { _engine.AddReadItem(_inVarsDigital[m_key[i]].Address, _inVarsDigital[m_key[i]].Memory, _inVarsDigital[m_key[i]].Size, "DIN_" + m_key[i], null, RefreshInterfaseDigital); } catch { } } } m_key = _outVarsDigital.Keys; for (int i = 0; i < _outVarsDigital.Count; i++) { if (this.cbDefault.Checked || _engine.Parameters.ProcessorType == ProcessorType.AT89C51ED2 || i > 3) { try { _engine.AddReadItem(_outVarsDigital[m_key[i]].Address, _outVarsDigital[m_key[i]].Memory, _outVarsDigital[m_key[i]].Size, "DOUT_" + m_key[i], null, RefreshInterfaseDigital); } catch { } } } //Запуск на чтение аналоговых датчиков Kontel.Relkon.Classes.ControllerVar m_var; for (int i = 0; i < this.ascInputs.Length; i++) { if (this.cbDefault.Checked || _engine.Parameters.ProcessorType == ProcessorType.AT89C51ED2 || i > 7) { m_var = _solution.Vars.GetIOVar(this.ascInputs[i].SensorName); try { _engine.AddReadItem(m_var.Address, m_var.Memory, m_var.Size, this.ascInputs[i], null, RefreshInterfaseAnalog); } catch { } } } for (int i = 0; i < this.ascOutputs.Length; i++) { if (this.cbDefault.Checked || _engine.Parameters.ProcessorType == ProcessorType.AT89C51ED2 || i > 1) { m_var = _solution.Vars.GetIOVar(this.ascOutputs[i].SensorName); try { _engine.AddReadItem(m_var.Address, m_var.Memory, m_var.Size, this.ascOutputs[i], null, RefreshInterfaseAnalog); } catch { } } } } else { //Запуск датчиков с открытой вкладки for (int i = 0; i < tpBloks.Count; i++) { TD.SandDock.TabPage tp = tpBloks[tpBloks.Keys[i]]; if (this.tabControl1.SelectedPage != null && tp.Name == this.tabControl1.SelectedPage.Name && tp.Name != "") { ((DisplayBlock)tp.Controls[0]).AddedReadItems(); break; } } } }
/// <summary> /// Событтие при двойном щелчке по дереву не прочитаннх переменных /// (формировани запроса на их чтение) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tvVars_NodeMouseDoubleClick(object sender, System.Windows.Forms.TreeNodeMouseClickEventArgs e) { if ((e.Node.Nodes.Count == 0) && ((e.Node.Text.CompareTo("Системные переменные") != 0) && (e.Node.Text.CompareTo("Пользовательские переменные") != 0) && (e.Node.Text.CompareTo("Заводские установки") != 0))) { Kontel.Relkon.Classes.ControllerVar m_newVar = _solution.Vars.GetVarByName(e.Node.Text); if (m_newVar == null) { return; } if (!_vars.ContainsKey(e.Node.Text)) { _vars.Add(e.Node.Text, m_newVar); //Добавление записи с читаемой переменной Int64 m_Max = 0; Int64 m_Min = 0; if (m_newVar.HasSign) { switch (m_newVar.Size) { case 1: m_Max = sbyte.MaxValue; m_Min = sbyte.MinValue; break; case 2: m_Max = Int16.MaxValue; m_Min = Int16.MinValue; break; case 4: m_Max = Int32.MaxValue; m_Min = Int32.MinValue; break; default: m_Max = sbyte.MaxValue; m_Min = sbyte.MinValue; break; } } else { switch (m_newVar.Size) { case 1: m_Max = Byte.MaxValue; m_Min = Byte.MinValue; break; case 2: m_Max = UInt16.MaxValue; m_Min = UInt16.MinValue; break; case 4: m_Max = UInt32.MaxValue; m_Min = UInt32.MinValue; break; default: m_Max = Byte.MaxValue; m_Min = Byte.MinValue; break; } } DataRow m_row = this.Table.NewRow(); m_row[0] = m_newVar.Name; m_row[2] = m_Max; m_row[3] = m_Min; m_row[4] = m_newVar.Size; m_row[5] = m_newVar.Address; m_row[6] = m_newVar.Memory; m_row[7] = ("0x00000000".Insert("0x00000000".Length - ("" + AppliedMath.DecToHex(m_newVar.Address)).Length, "" + AppliedMath.DecToHex(m_newVar.Address))).Substring(0, 10); m_row[8] = new byte[m_newVar.Size]; m_row[9] = m_newVar.Real; this.BuildDisplayValue(m_row); this.Table.Rows.Add(m_row); //Запоминаем что читаем эту переменную в параметры отладчика Kontel.Relkon.DebuggerParameters.VarDescription m_VarDescription = new Kontel.Relkon.DebuggerParameters.VarDescription(); m_VarDescription.Address = m_newVar.Address; m_VarDescription.MemoryType = m_newVar.Memory; m_VarDescription.Name = m_newVar.Name; m_VarDescription.Size = m_newVar.Size; m_VarDescription.Real = m_newVar.Real; m_VarDescription.Type = e.Node.Parent.Index; _engine.Parameters.ReadingVars.Add(m_VarDescription); //Добавление переменной на опрос if (this._IsReading) { for (int i = 0; i < this.Table.Rows.Count; i++) { if (this.Table.Rows[i][0].ToString() == m_newVar.Name) { try { _engine.AddReadItem(m_newVar.Address, m_newVar.Memory, m_newVar.Size, this.Table.Rows[i], null, CallBack); } catch { } } } } } this.tvVars.Nodes.Remove(e.Node); } }