private void buttonStart_Click(object sender, EventArgs e) { bool[] DOStatus; Adam_AIAlarmMode mode; if (m_bStart) // was started { m_bStart = false; timer1.Enabled = false; adamCom.CloseComPort(); buttonStart.Text = "Start"; } else { if (adamCom.OpenComPort()) { // set COM port state, 9600,N,8,1 adamCom.SetComPortState(Baudrate.Baud_9600, Databits.Eight, Parity.None, Stopbits.One); // set COM port timeout adamCom.SetComPortTimeout(500, 500, 0, 500, 0); m_iCount = 0; // reset the reading counter // get module config if (!adamCom.Configuration(m_iAddr).GetModuleConfig(out m_adamConfig)) { adamCom.CloseComPort(); MessageBox.Show("Failed to get module config!", "Error"); return; } // detect alarm // for ADAM-4011, ADAM-4011D, or ADAM-4012 if (m_Adam4000Type != Adam4000Type.Adam4013) { if (adamCom.Alarm(m_iAddr).GetModeAlarmDO(2, out mode, out DOStatus)) { m_DOStatus[0] = DOStatus[0]; m_DOStatus[1] = DOStatus[1]; txtMode.Text = mode.ToString(); if (mode == Adam_AIAlarmMode.Disable) // alarm is disabled { buttonDO0.Enabled = true; buttonDO1.Enabled = true; } else { buttonDO0.Enabled = false; buttonDO1.Enabled = false; } } } // timer1.Enabled = true; // enable timer buttonStart.Text = "Stop"; m_bStart = true; // starting flag } else { MessageBox.Show("Failed to open COM port!", "Error"); } } }
private void RefreshAlarmButton() { bool[] bDO; Adam4000_CounterAlarmMode byMode; if (adamCom.Alarm(m_iAddr).GetModeAlarmDO(out byMode, out bDO)) { if (byMode == Adam4000_CounterAlarmMode.Disable) { btnLowAlarm.Text = "DO-0"; btnHighAlarm.Text = "DO-1"; btnHighAlarm.Enabled = true; btnLowAlarm.Enabled = true; btnClearLatch.Enabled = false; } else if (byMode == Adam4000_CounterAlarmMode.Latch) { btnLowAlarm.Text = "Low alarm"; btnHighAlarm.Text = "High alarm"; btnHighAlarm.Enabled = false; btnLowAlarm.Enabled = false; btnClearLatch.Enabled = true; } else if (byMode == Adam4000_CounterAlarmMode.Momentary) { btnLowAlarm.Text = "Low alarm"; btnHighAlarm.Text = "High alarm"; btnHighAlarm.Enabled = false; btnLowAlarm.Enabled = false; btnClearLatch.Enabled = false; } } else { MessageBox.Show("GetModeAlarmDO() failed"); } }
private void RefreshAlarmButton() { bool[] bAlarm, bDO; int iChannel; iChannel = cbxChannel.SelectedIndex; if (adamCom.Alarm(m_iAddr).GetEnableAlarmDO(out bAlarm, out bDO)) { if (bAlarm[iChannel]) // alarm enabled { btnAlarm.Text = "Ch-" + iChannel.ToString() + " alarm"; btnAlarm.Enabled = false; } else { btnAlarm.Text = "DO-" + iChannel.ToString(); btnAlarm.Enabled = true; } } else { MessageBox.Show("GetEnableAlarmDO() failed", "Error"); } }