コード例 #1
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            bool[]           DOStatus;
            Adam_AIAlarmMode mode;

            if (m_bStart) // was started
            {
                panelAO.Enabled    = false;
                panelAlarm.Enabled = false;
                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
                    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;
                        }
                    }
                    //
                    panelAO.Enabled    = true;
                    panelAlarm.Enabled = true;
                    timer1.Enabled     = true; // enable timer
                    buttonStart.Text   = "Stop";
                    m_bStart           = true; // starting flag
                }
                else
                {
                    MessageBox.Show("Failed to open COM port!", "Error");
                }
            }
        }
コード例 #2
0
 private void buttonStart_Click(object sender, EventArgs e)
 {
     if (m_bStart) // was started
     {
         panelLED.Enabled   = false;
         panelCount.Enabled = false;
         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;
             }
             // LED panel
             panelLED.Enabled = true;
             RefreshLEDSource();
             // Counter panel
             if (m_adamConfig.TypeCode == (byte)Adam4080_CounterMode.Counter)
             {
                 panelCount.Enabled       = true;
                 cbxChannel.SelectedIndex = 0;
                 RefreshAlarmButton();
             }
             else
             {
                 panelCount.Enabled = false;
             }
             timer1.Enabled   = true; // enable timer
             buttonStart.Text = "Stop";
             m_bStart         = true; // starting flag
         }
         else
         {
             MessageBox.Show("Failed to open COM port!", "Error");
         }
     }
 }
コード例 #3
0
        public VoltageController(VM_MSConfig msConfig)
        {
            Config           = msConfig;
            m_iCom           = 3;                      // using COM4
            m_iAddr          = 1;                      // the slave address is 1
            m_iCount         = 0;                      // the counting start from 0
            m_bStart         = false;
            m_Adam4000Type   = Adam4000Type.Adam4019P; // the sample is for ADAM-4019P
            m_iChTotal       = AnalogInput.GetChannelTotal(m_Adam4000Type);
            m_byRange        = new byte[m_iChTotal];
            adamCom          = new AdamCom(m_iCom);
            adamCom.Checksum = false; // disbale checksum

            Module = m_Adam4000Type.ToString();

            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();
                    LogHelper.WriteErrorLog("Failed to get module config!");
                    return;
                }
                //
                RefreshChannelEnable();
                RefreshChannelRange();
                //
                m_bStart = true; // starting flag
            }
            else
            {
                LogHelper.WriteErrorLog("Failed to open COM port!");
            }
        }
コード例 #4
0
 private void buttonStart_Click(object sender, EventArgs e)
 {
     if (m_bStart) // was started
     {
         tabControl1.Enabled = false;
         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;
             }
             //
             RefreshChannelEnable();
             //
             tabControl1.Enabled = true;
             timer1.Enabled      = true; // enable timer
             buttonStart.Text    = "Stop";
             m_bStart            = true; // starting flag
         }
         else
         {
             MessageBox.Show("Failed to open COM port!", "Error");
         }
     }
 }
コード例 #5
0
        public void Open()
        {
            adamCom          = new AdamCom(SerialPortNumber);
            adamCom.Checksum = Checksum;

            bool opened = false;

            try
            {
                if (!adamCom.IsOpen)
                {
                    opened = adamCom.OpenComPort();
                }

                if (!opened)
                {
                    return;
                }

                // set COM port state, 9600,N,8,1
                adamCom.SetComPortState(Baudrate.Baud_9600, Databits.Eight, Parity.None, Stopbits.One, FlowControl.None);
                // set COM port timeout
                adamCom.SetComPortTimeout(500, 1000, 0, 1000, 0);

                if (!adamCom.Configuration(address).GetModuleConfig(out config))
                {
                    opened = false;
                    adamCom.CloseComPort();
                    return;
                }
            }
            finally
            {
                Opened = opened;
            }
        }