Beispiel #1
0
        private void btOpen_Click(object sender, EventArgs e)
        {
            switch(cbDevice.SelectedIndex)
            {
                case (int)CONNECTON_TYPES.USB:
                    try
                    {

                        serial.PortName = cbPort.SelectedItem.ToString();
                        serial.BaudRate = 115200;
                        serial.Open();
                        serial.DiscardInBuffer();
                        serial.DiscardOutBuffer();

                        System.Threading.Thread.Sleep(100);
                        serial.DtrEnable = true;
                        System.Threading.Thread.Sleep(100);
                        serial.DtrEnable = false;
                        System.Threading.Thread.Sleep(100);

                        this.Text = nazev_aplikace + " - " + serial.PortName.ToString();

                    }
                    catch (Exception x)
                    {
                        MessageBox.Show(x.Message);
                        return;
                    }
                    break;

                case (int)CONNECTON_TYPES.PEAK:
                    TPCANStatus stsResult;
                    m_PcanHandle = 0x51;

                    // Connects a selected PCAN-Basic channel
                    //
                    stsResult = PCANBasic.Initialize(
                        m_PcanHandle,
                        TPCANBaudrate.PCAN_BAUD_100K,
                        TPCANType.PCAN_TYPE_ISA,
                        (UInt32)100,
                        (UInt16)3);

                    if (stsResult != TPCANStatus.PCAN_ERROR_OK)
                    {
                        MessageBox.Show(GetFormatedError(stsResult));
                        return;
                    }

                    this.Text = nazev_aplikace + " - PEAK";
                    tReader.Start();
                    // Sets the connection status of the main-form
                    //

                    break;

                case (int)CONNECTON_TYPES.VSCP:
                    vscp = new vscp_daemon_iface();
                    if (!vscp.Open(tbIp.Text, 9598))
                    {
                        MessageBox.Show("Server error!");
                        return;
                    }
                    if (!vscp.Login(tbUser.Text, tbPass.Text))
                    {
                        MessageBox.Show("Login or password failure");
                        return;
                    }
                    tReader.Start();
                    break;
                default:
                    break;

            }

            btClose.Enabled = true;
            btOpen.Enabled = false;
            btSend.Enabled = true;
        }
Beispiel #2
0
        private void btOpen_Click(object sender, EventArgs e)
        {
            switch (cbDevice.SelectedIndex)
            {
            case (int)CONNECTON_TYPES.USB:
                try
                {
                    serial.PortName = cbPort.SelectedItem.ToString();
                    serial.BaudRate = 115200;
                    serial.Open();
                    serial.DiscardInBuffer();
                    serial.DiscardOutBuffer();

                    System.Threading.Thread.Sleep(100);
                    serial.DtrEnable = true;
                    System.Threading.Thread.Sleep(100);
                    serial.DtrEnable = false;
                    System.Threading.Thread.Sleep(100);

                    this.Text = nazev_aplikace + " - " + serial.PortName.ToString();
                }
                catch (Exception x)
                {
                    MessageBox.Show(x.Message);
                    return;
                }
                break;


            case (int)CONNECTON_TYPES.PEAK:
                TPCANStatus stsResult;
                m_PcanHandle = 0x51;

                // Connects a selected PCAN-Basic channel
                //
                stsResult = PCANBasic.Initialize(
                    m_PcanHandle,
                    TPCANBaudrate.PCAN_BAUD_100K,
                    TPCANType.PCAN_TYPE_ISA,
                    (UInt32)100,
                    (UInt16)3);

                if (stsResult != TPCANStatus.PCAN_ERROR_OK)
                {
                    MessageBox.Show(GetFormatedError(stsResult));
                    return;
                }

                this.Text = nazev_aplikace + " - PEAK";
                tReader.Start();
                // Sets the connection status of the main-form
                //

                break;

            case (int)CONNECTON_TYPES.VSCP:
                vscp = new vscp_daemon_iface();
                if (!vscp.Open(tbIp.Text, 9598))
                {
                    MessageBox.Show("Server error!");
                    return;
                }
                if (!vscp.Login(tbUser.Text, tbPass.Text))
                {
                    MessageBox.Show("Login or password failure");
                    return;
                }
                tReader.Start();
                break;

            default:
                break;
            }



            btClose.Enabled = true;
            btOpen.Enabled  = false;
            btSend.Enabled  = true;
        }