예제 #1
0
        public bool Connect()
        {
            if (ValueBag.Connected)
            {
                return(false);
            }
            try
            {
                FSUIPCConnection.Open();
                ValueBag.Clear();
                ValueBag.Connected = true;
                FsxiConnected?.Invoke(this, EventArgs.Empty);
                FsxiValueBagUpdated?.Invoke(this, EventArgs.Empty);

                updateThread = new Thread(new ParameterizedThreadStart(ThreadFunc));
                updateThread.Start(this);
                return(true);
            }
            catch (FSUIPCException)
            {
                return(false);
            }
            catch (Exception e)
            {
                log.Error(e);
                return(false);
            }
        }
예제 #2
0
        private void threadTick()
        {
            if (!ValueBag.Connected)
            {
                return;
            }
            try
            {
                FSUIPCConnection.Process();
                ValueBag.Paused = ipcPaused.Value == 1;
                if (ValueBag.Paused)
                {
                    ValueBag.TrueAirSpeed  = 0;
                    ValueBag.Lat           = 0;
                    ValueBag.Lng           = 0;
                    ValueBag.XVelocity     = 0;
                    ValueBag.YVelocity     = 0;
                    ValueBag.ZVelocity     = 0;
                    ValueBag.XAcceleration = 0;
                    ValueBag.YAcceleration = 0;
                    ValueBag.ZAcceleration = 0;
                    ValueBag.PitchVelocity = 0;
                    ValueBag.RollVelocity  = 0;
                    ValueBag.YawVelocity   = 0;
                }
                else
                {
                    ValueBag.TrueAirSpeed  = (double)ipcTrueAirSpeed.Value / 128d;
                    ValueBag.Lat           = ipcLat.Value;
                    ValueBag.Lng           = ipcLng.Value;
                    ValueBag.XVelocity     = ipcXVelocity.Value;
                    ValueBag.YVelocity     = ipcYVelocity.Value;
                    ValueBag.ZVelocity     = ipcZVelocity.Value;
                    ValueBag.XAcceleration = ipcXAcceleration.Value;
                    ValueBag.YAcceleration = ipcYAcceleration.Value;
                    ValueBag.ZAcceleration = ipcZAcceleration.Value;
                    ValueBag.PitchVelocity = ipcPitchVelocity.Value * 180d / Math.PI;
                    ValueBag.RollVelocity  = ipcRollVelocity.Value * 180d / Math.PI;
                    ValueBag.YawVelocity   = ipcYawVelocity.Value * 180d / Math.PI;
                }

                FsxiValueBagUpdated?.Invoke(this, EventArgs.Empty);
            }
            catch (FSUIPCException ex) when(ex.FSUIPCErrorCode == FSUIPCError.FSUIPC_ERR_SENDMSG)
            {
                Disconnect();
            }
            catch (Exception)
            {
                // In case of bad data conversion
            }
        }
예제 #3
0
 public bool Disconnect()
 {
     if (!ValueBag.Connected)
     {
         return(false);
     }
     try
     {
         FSUIPCConnection.Close();
         updateThread.Abort();
         updateThread = null;
         ValueBag.Clear();
         ValueBag.Connected = false;
         FsxiDisconnected?.Invoke(this, EventArgs.Empty);
         FsxiValueBagUpdated?.Invoke(this, EventArgs.Empty);
         return(true);
     }
     catch (FSUIPCException)
     {
         return(false);
     }
 }