コード例 #1
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            F4SharedMem.FlightData curData = null;
            try { curData = _smReader.GetCurrentData(); } catch { }
            DrawingData drawingData = null;

            try { drawingData = curData != null ? curData.DrawingData : null; } catch { }

            StringData stringData = null;

            try { stringData = curData != null ? curData.StringData : null; } catch { }

            var stringDataData = stringData != null ? stringData.data : null;

            _HUDCommands = drawingData != null && !(string.IsNullOrWhiteSpace(drawingData.HUD_commands))
                                ? drawingData.HUD_commands
                                : "";

            _RWRCommands = drawingData != null && !(string.IsNullOrWhiteSpace(drawingData.RWR_commands))
                                ? drawingData.RWR_commands
                                : "";

            _HMSCommands = drawingData != null && !(string.IsNullOrWhiteSpace(drawingData.HMS_commands))
                                ? drawingData.HMS_commands
                                : "";

            var cockpitArtDir = stringDataData != null && stringDataData.Any(sd => sd.strId == (uint)StringIdentifier.ThrCockpitdir)
                                ? stringDataData.Where(sd => sd.strId == (uint)StringIdentifier.ThrCockpitdir).First().value
                                : "";

            _fontDir = string.IsNullOrWhiteSpace(cockpitArtDir) ? "" : Path.Combine(cockpitArtDir, "3DFont");

            Process(_HUDCommands, "HUD", txtHUD, lblHUDDataSize, pbHUD, ref _HUDImage);
            Draw(_HUDImage, _HUDCommands, pbHUD);
            Process(_RWRCommands, "RWR", txtRWR, lblRWRDataSize, pbRWR, ref _RWRImage);
            Draw(_RWRImage, _RWRCommands, pbRWR);
            Process(_HMSCommands, "HMS", txtHMS, lblHMSDataSize, pbHMS, ref _HMSImage);
            Draw(_HMSImage, _HMSCommands, pbHMS);
        }
コード例 #2
0
        private void ProcessingMethod()
        {
            F4SharedMem.FalconDataFormats dataFormat = _configuration.DataFormat;
            int interval = _configuration.Interval;

            try
            {
                using (F4SharedMem.Reader reader = new F4SharedMem.Reader(dataFormat))
                {
                    // pierwsze odczytanie danych z wymuszeniem przesłania
                    F4SharedMem.FlightData data = reader.GetCurrentData();
                    if (_registeredVariable.Contains(_runningFalconVariable))
                    {
                        _runningFalconVariable.SetValue(reader.IsFalconRunning);
                    }
                    if (data != null)
                    {
                        Type t = data.GetType();
                        foreach (Variable v in _registeredVariable)
                        {
                            if (v == _runningFalconVariable)
                            {
                                continue;
                            }
                            if (v.Index > -1)
                            {
                                continue;
                            }
                            FieldInfo fi = t.GetField(v.ID);
                            if (fi != null)
                            {
                                object value = fi.GetValue(data);
                                v.SetValue(value);
                                continue;
                            }
                        }
                    }
                    while (_working)
                    {
                        if (interval > 0)
                        {
                            Thread.Sleep(interval);
                        }
                        data = reader.GetCurrentData();
                        if (data != null)
                        {
                            Type t = data.GetType();
                            foreach (Variable v in _registeredVariable)
                            {
                                if (v == _runningFalconVariable)
                                {
                                    v.SetValueIfChanged(reader.IsFalconRunning);
                                    continue;
                                }
                                if (v.Index > -1)
                                {
                                    continue;
                                }
                                FieldInfo fi = t.GetField(v.ID);
                                if (fi != null)
                                {
                                    v.SetValueIfChanged(fi.GetValue(data));
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                _log.Log(this, ex.ToString());
            }
        }