private void btnApplySelRange_Click(object sender, EventArgs e) { RefreshRanges(); if (!CheckControllable()) { return; } timer1.Enabled = false; bool bRet = true; if (listViewChInfo.SelectedIndices.Count == 0 && !chkApplyAll.Checked) { MessageBox.Show("Please select the target channel in the listview!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); bRet = false; } if (bRet) { int iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx]; ushort[] usRanges = new ushort[m_usRanges.Length]; Array.Copy(m_usRanges, 0, usRanges, 0, m_usRanges.Length); if (chkApplyAll.Checked) { for (int i = 0; i < usRanges.Length; i++) { usRanges[i] = AnalogInput.GetRangeCode2Byte(cbxRange.SelectedItem.ToString()); } } else { for (int i = 0; i < listViewChInfo.SelectedIndices.Count; i++) { usRanges[listViewChInfo.SelectedIndices[i]] = AnalogInput.GetRangeCode2Byte(cbxRange.SelectedItem.ToString()); } } if (m_adamCtl.AnalogInput().SetRanges(this.m_idxID, iChannelTotal, usRanges)) { RefreshRanges(); } else { MessageBox.Show("Set ranges failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } timer1.Enabled = true; }
private void RefreshAdam6000Information() { byte byCode; ushort usCode; int intAdamType; Adam6000Type adamType; adamType = (Adam6000Type)cbxModuleType.SelectedItem; intAdamType = (int)adamType; // AI information txtAITotal.Text = AnalogInput.GetChannelTotal(adamType).ToString(); listViewAI.Items.Clear(); if ((intAdamType == 6017) || ((intAdamType >= 6217) && (intAdamType <= 6224))) { for (int iIdx = 0; iIdx < AnalogInput.GetRangeTotal(adamType, Adam6000_RangeFormat.Ushort); iIdx++) { usCode = AnalogInput.GetRangeCode2Byte(adamType, iIdx); listViewAI.Items.Add(new ListViewItem("0x" + usCode.ToString("X04"))); // range code listViewAI.Items[iIdx].SubItems.Add(AnalogInput.GetRangeName(adamType, usCode)); // range name listViewAI.Items[iIdx].SubItems.Add(AnalogInput.GetUnitName(adamType, usCode)); // unit name } } else { for (int iIdx = 0; iIdx < AnalogInput.GetRangeTotal(adamType, Adam6000_RangeFormat.Byte); iIdx++) { byCode = AnalogInput.GetRangeCode(adamType, iIdx); listViewAI.Items.Add(new ListViewItem("0x" + byCode.ToString("X02"))); // range code listViewAI.Items[iIdx].SubItems.Add(AnalogInput.GetRangeName(adamType, byCode)); // range name listViewAI.Items[iIdx].SubItems.Add(AnalogInput.GetUnitName(adamType, byCode)); // unit name } } // AO information txtAOTotal.Text = AnalogOutput.GetChannelTotal(adamType).ToString(); listViewAO.Items.Clear(); if ((intAdamType >= 6217) && (intAdamType <= 6224)) { for (int iIdx = 0; iIdx < AnalogOutput.GetRangeTotal(adamType, Adam6000_RangeFormat.Ushort); iIdx++) { usCode = AnalogOutput.GetRangeCode2Byte(adamType, iIdx); listViewAO.Items.Add(new ListViewItem("0x" + usCode.ToString("X04"))); // range code listViewAO.Items[iIdx].SubItems.Add(AnalogInput.GetRangeName(adamType, usCode)); // range name listViewAO.Items[iIdx].SubItems.Add(AnalogInput.GetUnitName(adamType, usCode)); // unit name } } else { for (int iIdx = 0; iIdx < AnalogInput.GetRangeTotal(adamType, Adam6000_RangeFormat.Byte); iIdx++) { byCode = AnalogOutput.GetRangeCode(adamType, iIdx); listViewAO.Items.Add(new ListViewItem("0x" + byCode.ToString("X02"))); // range code listViewAO.Items[iIdx].SubItems.Add(AnalogOutput.GetRangeName(adamType, byCode)); // range name listViewAO.Items[iIdx].SubItems.Add(AnalogOutput.GetUnitName(adamType, byCode)); // range name } } // DIO txtDITotal.Text = DigitalInput.GetChannelTotal(adamType).ToString(); txtDOTotal.Text = DigitalOutput.GetChannelTotal(adamType).ToString(); // counter txtCounterTotal.Text = Counter.GetChannelTotal(adamType).ToString(); listViewCounter.Items.Clear(); if (Counter.GetModeTotal(adamType) > 0) { listViewCounter.Items.Add(new ListViewItem(Counter.GetModeName(adamType, (byte)Adam6051_CounterMode.Counter))); // mode name listViewCounter.Items[0].SubItems.Add(Counter.GetUnitName(adamType, (byte)Adam6051_CounterMode.Counter)); // unit name listViewCounter.Items.Add(new ListViewItem(Counter.GetModeName(adamType, (byte)Adam6051_CounterMode.Frequency))); // mode name listViewCounter.Items[1].SubItems.Add(Counter.GetUnitName(adamType, (byte)Adam6051_CounterMode.Frequency)); // unit name } // alarm listViewAlarm.Items.Clear(); for (int iIdx = 0; iIdx < Alarm.GetModeTotal(adamType); iIdx++) { byCode = Alarm.GetModeCode(adamType, iIdx); listViewAlarm.Items.Add(new ListViewItem(Alarm.GetModeName(adamType, byCode))); // mode name } }