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"); } } }