private void OnSerialPortSelected()
        {
            Microsoft.Networking.SerialPort port = (SerialPort)SerialPorts.SelectedItem;
            if (port == null)
            {
                return;
            }

            int baudRate = 0;

            int.TryParse(BaudRate.Text, out baudRate);

            try
            {
                port.Connect(port.Id, baudRate);
                SerialConnectButton.Content = "Disconnect";
                OnPortConnected(port);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error Connecting", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Example #2
0
        void Run()
        {
            if (udpAddress != null)
            {
                UdpPort udp = new UdpPort();
                udp.Connect(udpAddress);

                IPEndPoint remote = udp.WaitForOneMessage(TimeSpan.FromSeconds(10));
                if (remote == null)
                {
                    Console.WriteLine("### Error: not getting any messages from " + udpAddress);
                    return;
                }
                port = udp;
            }
            else if (comPortName != null)
            {
                SerialPort serial = new SerialPort();
                serial.Connect(comPortName, DefaultComBaudRate);
                port = serial;
            }
            if (proxyAddress != null)
            {
                proxyPort = new UdpPort();
                proxyPort.Connect(new IPEndPoint(udpAddress.Address, 0), proxyAddress);
                proxyChannel = new MavlinkChannel();
                proxyChannel.MessageReceived += OnProxyMessageReceived;
                proxyChannel.Start(proxyPort);
            }

            MavlinkChannel channel = new MavlinkChannel();
            channel.MessageReceived += OnMessageReceived;
            channel.Start(port);
        }