Beispiel #1
0
 private void buttonStart_Click(object sender, System.EventArgs e)
 {
     if (m_bStart)               // was started
     {
         m_bStart       = false; // starting flag
         timer1.Enabled = false; // disable timer
         adamCom.CloseComPort(); // close the COM port
         buttonStart.Text = "Start";
     }
     else                // was stoped
     {
         if (adamCom.OpenComPort())
         {
             // set COM port state
             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
             timer1.Enabled   = true;          // enable timer
             buttonStart.Text = "Stop";
             m_bStart         = true;          // starting flag
         }
         else
         {
             MessageBox.Show("Open COM port failed", "Error");
         }
     }
 }
Beispiel #2
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");
                }
            }
        }
Beispiel #3
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");
         }
     }
 }
Beispiel #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");
         }
     }
 }
        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!");
            }
        }
Beispiel #6
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            Socket svrSocket;

            if (buttonStart.Text == "Start")
            {
                m_com          = new AdamCom(2);
                m_com.Checksum = false;                                                               // set the checksum disbale, if the checksum must be applied, set it to true
                m_com.SetComPortState(Baudrate.Baud_9600, Databits.Eight, Parity.None, Stopbits.One); // 9600, N, 8, 1
                m_com.SetComPortTimeout(m_SerialTimeout, m_SerialTimeout, 0, m_SerialTimeout, 0);
                if (!m_com.OpenComPort())
                {
                    MessageBox.Show("Failed to open COM!", "Error");
                    return;
                }
                m_SvrSocket = new UDPSocketServer();
                m_SvrSocket.Create(m_ListenPort);
                svrSocket              = m_SvrSocket.ServerSocket();
                m_SvrStream            = new SocketStream(ref svrSocket, m_UDPSendTimeout, m_UDPRecvTimeout);
                buttonStart.Text       = "Stop";
                m_UDPRecv              = 0;
                m_UDPSent              = 0;
                m_SerialSent           = 0;
                m_SerialRecv           = 0;
                textBoxUDPRecv.Text    = m_UDPRecv.ToString();
                textBoxUDPSent.Text    = m_UDPSent.ToString();
                textBoxSerialSent.Text = m_SerialSent.ToString();
                textBoxSerialRecv.Text = m_SerialRecv.ToString();
                timer1.Enabled         = true;
            }
            else
            {
                timer1.Enabled = false;
                m_SvrSocket.Terminate();
                m_com.CloseComPort();
                buttonStart.Text = "Start";
            }
        }
Beispiel #7
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;
            }
        }
Beispiel #8
0
 private void buttonStart_Click(object sender, EventArgs e)
 {
     if (m_bStart) // was started
     {
         panelCount.Enabled = false;
         m_bStart           = false;
         timer1.Enabled     = false;
         if (m_b5000)
         {
             adamCom.CloseComPort();
         }
         else
         {
             adamSocket.Disconnect();
         }
         buttonStart.Text = "Start";
     }
     else
     {
         if (m_b5000)
         {
             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 (RefreshMode())
                 {
                     cbxChannel.SelectedIndex = 0;
                     if (m_byMode != (byte)Adam5080_CounterMode.Frequency)
                     {
                         panelCount.Enabled = true;
                     }
                     timer1.Enabled   = true; // enable timer
                     buttonStart.Text = "Stop";
                     m_bStart         = true; // starting flag
                 }
                 else
                 {
                     adamCom.CloseComPort();
                 }
             }
             else
             {
                 MessageBox.Show("Failed to open COM port!", "Error");
             }
         }
         else
         {
             if (adamSocket.Connect(AdamType.Adam5000Tcp, m_szIP, ProtocolType.Tcp))
             {
                 m_iCount = 0; // reset the reading counter
                 //
                 if (RefreshMode())
                 {
                     cbxChannel.SelectedIndex = 0;
                     if (m_byMode != (byte)Adam5080_CounterMode.Frequency)
                     {
                         panelCount.Enabled = true;
                     }
                     timer1.Enabled   = true; // enable timer
                     buttonStart.Text = "Stop";
                     m_bStart         = true; // starting flag
                 }
                 else
                 {
                     adamSocket.Disconnect();
                 }
             }
             else
             {
                 MessageBox.Show("Failed to connect to " + m_szIP + "!", "Error");
             }
         }
     }
 }
Beispiel #9
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");
                }
            }
        }