Beispiel #1
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            bool bRet;

            if (m_bStart) // was started
            {
                panelPID.Enabled = false;
                m_bStart         = false; // starting flag
                timer1.Enabled   = false; // disable timer
                adamModbus.Disconnect();  // disconnect slave
                buttonStart.Text = "Start";
            }
            else        // was stoped
            {
                if (adamModbus.Connect(m_szIP, ProtocolType.Tcp, m_iPort))
                {
                    m_iCount = 0; // reset the reading counter

                    if (cbxLoop.SelectedIndex >= 0)
                    {
                        RefreshPIDValue();
                    }
                    else
                    {
                        // PID
                        m_loopBase = PID_Loop.Loop0;
                        bRet       = (adamModbus.Pid().ModbusRefreshBuffer(PID_Loop.Loop0) && adamModbus.Pid().ModbusRefreshBuffer(PID_Loop.Loop1));

                        if (bRet)
                        {
                            m_pv1LblHigh[0] = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop0, PID_Addr.Sv1HighLimit);
                            m_pv1LblHigh[1] = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop1, PID_Addr.Sv1HighLimit);
                            m_pv1LblLow[0]  = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop0, PID_Addr.Sv1LowLimit);
                            m_pv1LblLow[1]  = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop1, PID_Addr.Sv1LowLimit);
                            m_pv2LblHigh[0] = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop0, PID_Addr.Sv2HighLimit);
                            m_pv2LblHigh[1] = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop1, PID_Addr.Sv2HighLimit);
                            m_pv2LblLow[0]  = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop0, PID_Addr.Sv2LowLimit);
                            m_pv2LblLow[1]  = adamModbus.Pid().GetBufferFloat(PID_Loop.Loop1, PID_Addr.Sv2LowLimit);
                            RefreshPIDStatic();
                        }
                        else
                        {
                            MessageBox.Show("Failed to refresh data!", "Error");
                            return;
                        }
                    }
                    //
                    panelPID.Enabled = true;
                    timer1.Enabled   = true; // enable timer
                    buttonStart.Text = "Stop";
                    m_bStart         = true; // starting flag
                }
                else
                {
                    MessageBox.Show("Connect to " + m_szIP + " failed", "Error");
                }
            }
        }
Beispiel #2
0
 private void cbxLoop_SelectedIndexChanged(object sender, EventArgs e)
 {
     timer1.Enabled = false;
     m_loopBase     = (PID_Loop)cbxLoop.SelectedIndex;
     adamTrend1.ClearGraph();
     if (!RefreshPIDStatic())
     {
         MessageBox.Show("Hi-Lo range Setting is invalid!", "Error");
     }
     timer1.Enabled = true;
 }
Beispiel #3
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            bool bRet;

            if (m_bStart) // was started
            {
                panelPID.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
                    //
                    if (cbxLoop.SelectedIndex >= 0)
                    {
                        RefreshPIDValue();
                    }
                    else
                    {
                        // PID
                        m_loopBase = PID_Loop.Loop0;
                        if (m_AsciiProtocol)
                        {
                            bRet = (adamCom.Pid(m_iAddr).AsciiRefreshBuffer(PID_Loop.Loop0) && adamCom.Pid(m_iAddr).AsciiRefreshBuffer(PID_Loop.Loop1));
                        }
                        else
                        {
                            bRet = (adamCom.Pid(m_iAddr).ModbusRefreshBuffer(PID_Loop.Loop0) && adamCom.Pid(m_iAddr).ModbusRefreshBuffer(PID_Loop.Loop1));
                        }
                        if (bRet)
                        {
                            m_pv1LblHigh[0] = adamCom.Pid(m_iAddr).GetBufferFloat(PID_Loop.Loop0, PID_Addr.Sv1HighLimit);
                            m_pv1LblHigh[1] = adamCom.Pid(m_iAddr).GetBufferFloat(PID_Loop.Loop1, PID_Addr.Sv1HighLimit);
                            m_pv1LblLow[0]  = adamCom.Pid(m_iAddr).GetBufferFloat(PID_Loop.Loop0, PID_Addr.Sv1LowLimit);
                            m_pv1LblLow[1]  = adamCom.Pid(m_iAddr).GetBufferFloat(PID_Loop.Loop1, PID_Addr.Sv1LowLimit);
                            m_pv2LblHigh[0] = adamCom.Pid(m_iAddr).GetBufferFloat(PID_Loop.Loop0, PID_Addr.Sv2HighLimit);
                            m_pv2LblHigh[1] = adamCom.Pid(m_iAddr).GetBufferFloat(PID_Loop.Loop1, PID_Addr.Sv2HighLimit);
                            m_pv2LblLow[0]  = adamCom.Pid(m_iAddr).GetBufferFloat(PID_Loop.Loop0, PID_Addr.Sv2LowLimit);
                            m_pv2LblLow[1]  = adamCom.Pid(m_iAddr).GetBufferFloat(PID_Loop.Loop1, PID_Addr.Sv2LowLimit);
                            RefreshPIDStatic();
                        }
                        else
                        {
                            MessageBox.Show("Failed to refresh data!", "Error");
                            adamCom.CloseComPort();
                            return;
                        }
                    }
                    //
                    panelPID.Enabled = true;
                    timer1.Enabled   = true; // enable timer
                    buttonStart.Text = "Stop";
                    m_bStart         = true; // starting flag
                }
                else
                {
                    MessageBox.Show("Failed to open COM port!", "Error");
                }
            }
        }