/// <summary> /// Get Channel information "Range" column /// </summary> /// <returns></returns> private bool RefreshRanges() { try { int iChannelTotal = this.m_aConf.HwIoTotal[m_tmpidx]; if (m_adamSocket.Configuration().GetModuleConfig(m_idxID, out m_aConf)) { m_adamSocket.Configuration().GetModuleCurrentRange(Convert.ToInt32(m_idxID), m_aConf); m_usRanges = m_aConf.wChRange; // Update Range column for (int i = 0; i < iChannelTotal; i++) { listViewChInfo.Items[i].SubItems[4].Text = AnalogOutput.GetRangeName(m_usRanges[i]).ToString(); } } else { StatusBar_IO.Text += "GetModuleConfig(Error:" + m_adamSocket.Modbus().LastError.ToString() + ") Failed! "; } return(true); } catch { return(false); } }
/// <summary> /// Init Channel Information /// </summary> /// <param name="m_aConf">apax 5000 device object</param> private void InitialDataTabPages() { int i = 0, idx = 0; byte type = (byte)_HardwareIOType.AO; //APAX-5028 is AO module ListViewItem lvItem; string[] strRanges; for (i = 0; i < m_aConf.HwIoType.Length; i++) { if (m_aConf.HwIoType[i] == type) { idx = i; } } m_tmpidx = idx; if (m_tmpidx == 0) { m_usRanges_supAO = m_aConf.wHwIoType_0_Range; } else if (m_tmpidx == 1) { m_usRanges_supAO = m_aConf.wHwIoType_1_Range; } else if (m_tmpidx == 2) { m_usRanges_supAO = m_aConf.wHwIoType_2_Range; } else if (m_tmpidx == 3) { m_usRanges_supAO = m_aConf.wHwIoType_3_Range; } else// if(idxType==3) { m_usRanges_supAO = m_aConf.wHwIoType_4_Range; } //init range combobox strRanges = new string[m_aConf.HwIoType_TotalRange[m_tmpidx]]; for (i = 0; i < strRanges.Length; i++) { strRanges[i] = AnalogOutput.GetRangeName(m_usRanges_supAO[i]); } SetRangeComboBox(strRanges); listViewChInfo.BeginUpdate(); listViewChInfo.Items.Clear(); for (i = 0; i < m_aConf.HwIoTotal[m_tmpidx]; i++) { lvItem = new ListViewItem(_HardwareIOType.AO.ToString()); //Type lvItem.SubItems.Add(i.ToString()); //Ch lvItem.SubItems.Add("*****"); //Value lvItem.SubItems.Add("*****"); //Range lvItem.SubItems.Add("*****"); //Start up lvItem.SubItems.Add("*****"); //Safety Value listViewChInfo.Items.Add(lvItem); } listViewChInfo.EndUpdate(); }
private void RefreshAdam5000Information() { int iIdx; byte byCode; Adam5000Type adamType; adamType = (Adam5000Type)cbxModuleType.SelectedItem; // AI information txtAITotal.Text = AnalogInput.GetChannelTotal(adamType).ToString(); listViewAI.Items.Clear(); for (iIdx = 0; iIdx < AnalogInput.GetRangeTotal(adamType); 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)); // range name } // AO information txtAOTotal.Text = AnalogOutput.GetChannelTotal(adamType).ToString(); listViewAO.Items.Clear(); for (iIdx = 0; iIdx < AnalogOutput.GetRangeTotal(adamType); 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)Adam5080_CounterMode.Bi_Direction))); // mode name listViewCounter.Items[0].SubItems.Add(Counter.GetUnitName(adamType, (byte)Adam5080_CounterMode.Bi_Direction)); // unit name listViewCounter.Items.Add(new ListViewItem(Counter.GetModeName(adamType, (byte)Adam5080_CounterMode.Up_Down))); // mode name listViewCounter.Items[1].SubItems.Add(Counter.GetUnitName(adamType, (byte)Adam5080_CounterMode.Up_Down)); // unit name listViewCounter.Items.Add(new ListViewItem(Counter.GetModeName(adamType, (byte)Adam5080_CounterMode.Frequency))); // mode name listViewCounter.Items[2].SubItems.Add(Counter.GetUnitName(adamType, (byte)Adam5080_CounterMode.Frequency)); // unit name } // alarm listViewAlarm.Items.Clear(); for (iIdx = 0; iIdx < Alarm.GetModeTotal(adamType); iIdx++) { byCode = Alarm.GetModeCode(adamType, iIdx); listViewAlarm.Items.Add(new ListViewItem(Alarm.GetModeName(adamType, byCode))); // mode name } }
public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // m_bStart = false; // the action stops at the beginning m_szIP = "172.18.3.93"; // modbus slave IP address m_iPort = 502; // modbus TCP port is 502 adamModbus = new AdamSocket(); adamModbus.SetTimeout(1000, 1000, 1000); // set timeout for TCP adamModbus.AdamSeriesType = AdamType.Adam6200; adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort); m_Adam6000Type = Adam6000Type.Adam6224; // the sample is for ADAM-6224 m_iAoChTotal = AnalogOutput.GetChannelTotal(m_Adam6000Type); m_iAoRangeTotal = AnalogOutput.GetRangeTotal(m_Adam6000Type, Adam6000_RangeFormat.Ushort); m_iDiTotal = DigitalInput.GetChannelTotal(m_Adam6000Type); m_DiValueStartAddr = 1; m_iAoValueStartAddr = 1; txtModule.Text = m_Adam6000Type.ToString(); m_usRange = new ushort[m_iAoChTotal]; m_usAoValue = new ushort[m_iAoChTotal]; InitialDiDgViewModbusGeneralRow(m_DiValueStartAddr, m_iDiTotal, ref dgViewDiChannelInfo); InitialAoDgViewModbusGeneralRow(m_iAoValueStartAddr, m_iAoChTotal, ref dgViewAoChannelInfo); for (int i = 0; i < m_iAoChTotal; i++) { cbxAoChannel.Items.Add(i.ToString()); } cbxAoChannel.Items.Add("All"); if (m_Adam6000Type == Adam6000Type.Adam6224) { for (int i_iIndex = 0; i_iIndex < m_iAoRangeTotal; i_iIndex++) { ushort usRangeCode = AnalogOutput.GetRangeCode2Byte(m_Adam6000Type, i_iIndex); string strRangeName = AnalogOutput.GetRangeName(m_Adam6000Type, usRangeCode); cbxAoOutputRange.Items.Add(new ComboItem(strRangeName, usRangeCode)); } } }
private bool RefreshAoModbusValue(int i_AoValueStart, int i_AoChTotal, ref DataGridView dgViewModbus) { int iIdx; int[] iValueData; string szRange, szFormat; if (adamModbus.Modbus().ReadInputRegs(i_AoValueStart, i_AoChTotal, out iValueData)) { for (iIdx = 0; iIdx < i_AoChTotal; iIdx++) { szRange = AnalogOutput.GetRangeName(m_Adam6000Type, m_usRange[iIdx]); szFormat = AnalogOutput.GetFloatFormat(m_Adam6000Type, m_usRange[iIdx]); m_usAoValue[iIdx] = Convert.ToUInt16(iValueData[iIdx]); dgViewModbus.Rows[iIdx].Cells[3].Value = m_usAoValue[iIdx].ToString(); dgViewModbus.Rows[iIdx].Cells[4].Value = m_usAoValue[iIdx].ToString("X04"); dgViewModbus.Rows[iIdx].Cells[5].Value = AnalogOutput.GetScaledValue(m_Adam6000Type, m_usRange[iIdx], m_usAoValue[iIdx]).ToString(szFormat); dgViewModbus.Rows[iIdx].Cells[6].Value = szRange; } return(true); } return(false); }
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 } }
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { string strSelPageName = tabControl1.TabPages[tabControl1.SelectedIndex].Text; int idx; float fHigh = 0, fLow = 0, fVal = 0; ushort usVal; StatusBar_IO.Text = ""; m_adamSocket.Disconnect(); m_adamSocket.Connect(m_adamSocket.GetIP(), protoType, portNum); if (strSelPageName == "Module Information") { m_iFailCount = 0; m_iScanCount = 0; } else if (strSelPageName == "AO") { RefreshRanges(); RefreshAoStartupValues(); RefreshSafetySetting(); chbxEnableSafety.Checked = m_bIsEnableSafetyFcn; //Set AO info idx = 0; //initial index if (m_adamSocket.AnalogOutput().GetCurrentValue(m_idxID, idx, out usVal)) { AnalogOutput.GetRangeHighLow(m_usRanges[idx], out fHigh, out fLow); fVal = AnalogOutput.GetScaledValue(m_usRanges[idx], usVal); RefreshOutputPanel(fHigh, fLow, fVal); } else { this.StatusBar_IO.Text += "GetValues() filed!"; } //synchronize channel status for (int i = 0; i < listViewChInfo.Items.Count; i++) { if (i == idx) { listViewChInfo.Items[i].Selected = true; } else { listViewChInfo.Items[i].Selected = false; } } string szTemp = AnalogOutput.GetRangeName(m_usRanges[idx]); for (int i = 0; i < cbxRange.Items.Count; i++) { if (szTemp == cbxRange.Items[i].ToString()) { cbxRange.SelectedIndex = i; break; } } } if (tabControl1.SelectedIndex == 0) { this.timer1.Enabled = false; } else { this.timer1.Enabled = true; } }
/// <summary> /// Init Channel Information /// </summary> /// <param name="aConf">apax 5000 device object</param> private void InitialDataTabPages() { int i = 0, idx = 0; byte type = (byte)_HardwareIOType.AO; //APAX-5028 is AO module ListViewItem lvItem; string[] strRanges; for (i = 0; i < m_aConf.HwIoType.Length; i++) { if (m_aConf.HwIoType[i] == type) { idx = i; } } m_tmpidx = idx; if (m_tmpidx == 0) { m_adamSocket.Configuration().GetModuleTotalRange((int)m_idxID, m_aConf, 0); m_usRanges_supAO = m_aConf.wHwIoType_0_Range; } else if (m_tmpidx == 1) { m_adamSocket.Configuration().GetModuleTotalRange((int)m_idxID, m_aConf, 1); m_usRanges_supAO = m_aConf.wHwIoType_1_Range; } else if (m_tmpidx == 2) { m_adamSocket.Configuration().GetModuleTotalRange((int)m_idxID, m_aConf, 2); m_usRanges_supAO = m_aConf.wHwIoType_2_Range; } else if (m_tmpidx == 3) { m_adamSocket.Configuration().GetModuleTotalRange((int)m_idxID, m_aConf, 3); m_usRanges_supAO = m_aConf.wHwIoType_3_Range; } else { m_adamSocket.Configuration().GetModuleTotalRange((int)m_idxID, m_aConf, 4); m_usRanges_supAO = m_aConf.wHwIoType_4_Range; } //init range combobox strRanges = new string[m_aConf.HwIoType_TotalRange[m_tmpidx]]; for (i = 0; i < strRanges.Length; i++) { strRanges[i] = AnalogOutput.GetRangeName(m_usRanges_supAO[i]); } SetRangeComboBox(strRanges); listViewChInfo.BeginUpdate(); listViewChInfo.Items.Clear(); for (i = 0; i < m_aConf.HwIoTotal[m_tmpidx]; i++) { lvItem = new ListViewItem(_HardwareIOType.AO.ToString()); //Type lvItem.SubItems.Add(i.ToString()); //Ch if (m_adamType == AdamType.Apax5070) { lvItem.SubItems.Add(Convert.ToString(m_usStart + i)); //Modbus address } else { lvItem.SubItems.Add("*****"); } lvItem.SubItems.Add("*****"); //Value lvItem.SubItems.Add("*****"); //Range lvItem.SubItems.Add("*****"); //Start up lvItem.SubItems.Add("*****"); //Safety Value listViewChInfo.Items.Add(lvItem); } listViewChInfo.EndUpdate(); }