Beispiel #1
0
    /// <summary>
    /// Start a serial connection
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btn_connect_serial_Click(object sender, EventArgs e)
    {
        //If communication port is not initialized yet, initialize
        if (!CommHandler.initialized)
        {
            CommHandler.InitSerial(cmb_comport.SelectedItem.ToString(), int.Parse(cmb_baudrate.SelectedItem.ToString()));
        }

        // If port is open, close it. Else, open the port.
        if (CommHandler.IsOpen())
        {
            if (CommHandler.Close())
            {
                btn_comm_serialSend.Enabled = false;
                btn_comm_CANconnect.Enabled = true;
            }
        }
        else
        {
            if (CommHandler.Open())
            {
                btn_comm_serialSend.Enabled = true;
                btn_comm_CANconnect.Enabled = false;
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Start a CAN buss connection
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void btn_comm_CANconnect_Click(object sender, EventArgs e)
    {
        //If communication port is not initialized yet, initialize
        if (!CommHandler.initialized)
        {
            string ip;
            int    port;

            try
            {
                ip   = IPAddress.Parse(txt_comm_CANip.Text).ToString();
                port = Int32.Parse(txt_comm_CANport.Text);
            }
            catch (Exception CANConnectExeption)
            {
                MessageBox.Show("Please enter a valid IP address and port number", "caption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            CommHandler.InitCAN(ip, port);
        }

        // If port is open, close it. Else, open the port.
        if (CommHandler.IsOpen())
        {
            if (CommHandler.Close())
            {
                btn_comm_CANsend.Enabled       = false;
                btn_comm_serialConnect.Enabled = true;
            }
        }

        else
        {
            if (CommHandler.Open())
            {
                btn_comm_CANsend.Enabled       = true;
                btn_comm_serialConnect.Enabled = false;
            }
        }

        //bgw_aegirMessageRequest.RunWorkerAsync();
    }