Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            // receive DataREF over port
            using (UDPReceiver receiver = new UDPReceiver(IPAddress.Any, 49004))
                using (XplaneUDPSender sender = new XplaneUDPSender(IPAddress.Parse("127.0.0.1"), 49000))
                {
                    // data package, should be enabled in xplane
                    XplaneDATAPacket throttleOff = new XplaneDATAPacket(25, 0, 0, 0, 0, 0, 0, 0, 0);
                    XplaneDATAPacket throttleOn  = new XplaneDATAPacket(25, 1, 0, 0, 0, 0, 0, 0, 0);

                    // data ref, does not need to be enabled in xplane to edit
                    XplaneDREFPacket batteryOn  = new XplaneDREFPacket(1, "sim/cockpit/electrical/battery_on");
                    XplaneDREFPacket batteryOff = new XplaneDREFPacket(0, "sim/cockpit/electrical/battery_on");

                    while (true)
                    {
                        //drefReceiver.Listen(true);  <-- blocks thread

                        if (Console.KeyAvailable)
                        {
                            var key = Console.ReadKey();
                            if (key.Key == ConsoleKey.O)
                            {
                                // these three statements do the same
                                sender.Send(batteryOff);
                                //sender.WriteDref(batteryOff);
                                //sender.WriteDref(0, "sim/cockpit/electrical/battery_on");

                                Console.WriteLine("Battery Off");
                            }
                            if (key.Key == ConsoleKey.P)
                            {
                                sender.Send(batteryOn);
                                Console.WriteLine("Battery On");
                            }
                            if (key.Key == ConsoleKey.K)
                            {
                                sender.Send(throttleOff);
                            }
                            if (key.Key == ConsoleKey.L)
                            {
                                sender.Send(throttleOn);
                            }

                            if (key.Key == ConsoleKey.Escape)
                            {
                                break;
                            }
                        }
                    }
                }

            Environment.Exit(0);
        }
 /// <summary>
 /// Write reference value to xplane
 /// </summary>
 public void WriteDref(XplaneDREFPacket packet)
 {
     Send(packet);
 }
        /// <summary>
        /// Write reference value to xplane
        /// </summary>
        /// <param name="value"></param>
        /// <param name="drefPath"></param>
        public void WriteDref(float value, string drefPath)
        {
            var packet = new XplaneDREFPacket(value, drefPath);

            Send(packet);
        }