public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // int iIdx; adamCtl = new AdamControl(); m_iSlot = 2; // the slot index of the module m_iCount = 0; // the counting start from 0 m_bStart = false; adamCtl = new AdamControl(); m_Adam5000Type = Adam5000Type.Adam5024; // the sample is for ADAM-5024 m_iChTotal = AnalogOutput.GetChannelTotal(m_Adam5000Type); m_byRange = new byte[m_iChTotal]; for (iIdx = 0; iIdx < m_iChTotal; iIdx++) { cbxChannel.Items.Add(iIdx.ToString()); } txtModule.Text = m_Adam5000Type.ToString(); }
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (m_bStart) { timer1.Enabled = false; // disable timer adamCtl.CloseDevice(); adamCtl = null; } }
/// <summary> /// Used for change I/O module /// </summary> /// <returns></returns> public bool FreeResource() { if (m_bStartFlag) { m_bStartFlag = false; this.tabControl1.Enabled = false; this.tabControl1.Visible = false; timer1.Enabled = false; m_adamCtl.Configuration().SYS_SetLocateModule(m_idxID, 0); m_adamCtl = null; } return(true); }
public bool OpenDevice() { m_adamCtl = new AdamControl(AdamType.Apax5000); if (m_adamCtl.OpenDevice()) { if (!m_adamCtl.Configuration().SYS_SetDspChannelFlag(false)) { this.StatusBar_IO.Text = "SYS_SetDspChannelFlag(false) Failed! "; return(false); } if (!m_adamCtl.Configuration().GetSlotInfo(out m_szSlots)) { this.StatusBar_IO.Text = "GetSlotInfo() Failed! "; return(false); } } return(true); }
public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // m_iSlot = 1; // the slot index of the module m_iCount = 0; // the counting start from 0 m_bStart = false; adamCtl = new AdamControl(); //m_Adam5000Type = Adam5000Type.Adam5013; // the sample is for ADAM-5013 //m_Adam5000Type = Adam5000Type.Adam5017; // the sample is for ADAM-5017 m_Adam5000Type = Adam5000Type.Adam5018; // the sample is for ADAM-5018 m_iChTotal = AnalogInput.GetChannelTotal(m_Adam5000Type); txtModule.Text = m_Adam5000Type.ToString(); // if (m_Adam5000Type == Adam5000Type.Adam5013) { chkboxCh3.Visible = false; txtAIValue3.Visible = false; chkboxCh4.Visible = false; txtAIValue4.Visible = false; chkboxCh5.Visible = false; txtAIValue5.Visible = false; chkboxCh6.Visible = false; txtAIValue6.Visible = false; chkboxCh7.Visible = false; txtAIValue7.Visible = false; } else if (m_Adam5000Type == Adam5000Type.Adam5018) { chkboxCh7.Visible = false; txtAIValue7.Visible = false; } }
public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // m_iSlot = 4; // the slot index of the module m_iCount = 0; // the counting start from 0 m_bStart = false; adamCtl = new AdamControl(); m_Adam5000Type = Adam5000Type.Adam5017UH; // the sample is for ADAM-5017UH m_iChTotal = AnalogInput.GetChannelTotal(m_Adam5000Type); m_byRange = new byte[m_iChTotal]; txtModule.Text = m_Adam5000Type.ToString(); }
/// <summary> /// Refresh I/O modules of this controller and show controller information /// </summary> /// <param name="e"></param> private void AfterSelect_LocalDevice(TreeNode e) { this.treeView1.SelectedNode = this.treeView1.Nodes[0]; //CE bug exception uint uiVer; string szTemp = ""; string szVer = ""; ThreadStart newStart = new ThreadStart(ShowWaitMsg); Thread waitThread = new Thread(newStart); waitThread.Start(); try { m_adamCtl = new AdamControl(AdamType.Apax5000); //Get APAX-Driver Version if (m_adamCtl.Configuration().SYS_GetVersion(out uiVer)) { szTemp = uiVer.ToString("X00000000"); if (szTemp.Length >= 3) { szVer = szTemp.Insert(szTemp.Length - 2, "."); } else { szVer = szTemp; } statusBar1.Text = " APAX-Driver Version:" + szVer + "."; } else { statusBar1.Text = " Get APAX-Driver Version failed! Please upgrade the driver. ApiErr:" + m_adamCtl.Configuration().ApiLastError.ToString(); MessageBox.Show("Please make sure latest APAX-Driver has been installed."); return; } if (m_adamCtl.OpenDevice()) { if (!m_adamCtl.Configuration().SYS_SetDspChannelFlag(false)) { statusBar1.Text = "SYS_SetDspChannelFlag(false) Failed! "; } treeView1.Nodes[0].Nodes.Clear(); treeView1.BeginUpdate(); if (m_adamCtl.Configuration().GetSlotInfo(out m_szSlotInfo)) { for (int i = 0; i < m_szSlotInfo.Length; i++) { if (m_szSlotInfo[i].Length > 0) { TreeNode tNode = new TreeNode(m_szSlotInfo[i].ToString() + "(S" + i.ToString() + ")"); tNode.Tag = (byte)i; e.Nodes.Add(tNode); } } } e.ExpandAll(); treeView1.EndUpdate(); if (!RefreshConfiguration()) { MessageBox.Show("Get controller information failed!\nPlease check the device!", "Error"); } } } catch { MessageBox.Show("Open local driver failed!", "Error"); } }
// Global object static void Main(string[] args) { string DEVICE_DO = "5046"; string DEVICE_DI = "5040"; AdamControl m_adamCtl = null; Apax5000Config m_aConf; string[] m_szSlots; // Container of all solt device type m_adamCtl = new AdamControl(AdamType.Apax5000); if (!m_adamCtl.OpenDevice()) { Console.WriteLine("Не смог открыть устройства.."); Console.ReadKey(); return; } if (!m_adamCtl.Configuration().GetSlotInfo(out m_szSlots)) { Console.WriteLine("Не прочитать список устройства.."); Console.ReadKey(); return; } Console.WriteLine("Список устройств на шине"); for (int i = 0; i < m_szSlots.Length; i++) { Console.Write(i.ToString() + "=" + m_szSlots[i] + " "); if ((i + 1) % 4 == 0) { Console.WriteLine(); } } //Console.WriteLine("Состояние каждого устройства"); for (int i = 0; i < m_szSlots.Length; i++) { if (m_szSlots[i] == null) { continue; } bool DO = false; bool flag = true; _HardwareIOType type = _HardwareIOType.None; if (DEVICE_DO.Equals(m_szSlots[i])) { type = _HardwareIOType.DO; DO = true; flag = false; } if (DEVICE_DI.Equals(m_szSlots[i])) { type = _HardwareIOType.DI; flag = false; } if (flag) { continue; } if (i > 0) { Console.Write("Press any key..."); Console.ReadKey(); } Console.Write("Устройство номер=" + i.ToString() + " тип=" + m_szSlots[i]); Console.WriteLine(DO ? " DO" : " DI"); if (!m_adamCtl.Configuration().GetModuleConfig(i, out m_aConf)) { Console.WriteLine("Ошибка чтения конфигурации"); continue; } Console.WriteLine(" Имя модуля=" + m_aConf.GetModuleName() + " Каналов=" + m_aConf.byChTotal.ToString()); int iChannelTotal = 24; bool[] bVal = null; if (type == _HardwareIOType.DO) { if (!m_adamCtl.DigitalOutput().GetValues(i, iChannelTotal, out bVal)) { Console.WriteLine("ApiErr:" + m_adamCtl.DigitalOutput().ApiLastError.ToString()); continue; } } if (type == _HardwareIOType.DI) { if (!m_adamCtl.DigitalInput().GetValues(i, iChannelTotal, out bVal)) { Console.WriteLine("ApiErr:" + m_adamCtl.DigitalOutput().ApiLastError.ToString()); continue; } } for (int j = 0; j < bVal.Length; j++) { Console.Write(bVal[j].ToString() + " "); if ((j + 1) % 12 == 0) { Console.WriteLine(); } bVal[j] = !bVal[j]; } if (type == _HardwareIOType.DO) { if (!m_adamCtl.DigitalOutput().SetValues(i, bVal)) { Console.WriteLine("ApiErr:" + m_adamCtl.DigitalOutput().ApiLastError.ToString()); continue; } } } Console.Write("Press any key..."); Console.ReadKey(); }