예제 #1
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if ((string)button.Content == "Connect")
            {
                portName = comboBox.SelectedValue.ToString();
                if (portName == "KvaserCAN")
                {
                    kvaser = new KvaserCAN(this);

                    startCanMsgDump();

                    this.button.Content = "Disconnect";
                }
                else
                {
                    mySerial = new MySerial(portName);
                    if (mySerial.myComPort.IsOpen)
                    {
                        this.button.Content = "Disconnect";
                    }
                    else
                    {
                        intoTerminal("Ei õnnestunud");
                    }
                }

                richTextBox.Focus();
            }
            else
            {
                try
                {
                    if (portName == "KvaserCAN")
                    {
                        lock (_locker) runCan = false;
                        kvaser.deinitCan();
                    }
                    else
                    {
                        mySerial.myComPort.Close();
                    }
                    intoTerminal(portName + " Disconnected!");
                    button.Content = "Connect";
                }
                catch (NullReferenceException)
                {
                    intoTerminal(portName + " pole ühendatud");
                }
            }
        }
예제 #2
0
        private void bProgram_Click(object sender, RoutedEventArgs e)
        {
            if (runCan)
            {
                //lock (_locker) runCan = false; //stops msgDump

                Thread fwth = new Thread(() =>
                {
                    KvaserCAN kvaserB = new KvaserCAN(this);
                    kvaserB.FWSend();
                });
                fwth.Start();
            }
            else
            {
                mySerial.FWSend();
            }
        }