Beispiel #1
0
        public async Task <bool> Connect(int liveviewport, string lang)
        {
            language = lang;
            var token        = connectCancellation.Token;
            var connectStage = 0;

            try
            {
                LogTrace("Connecting camera " + Device.ModelName);
                do
                {
                    try
                    {
                        if (Profile.RequestConnection)
                        {
                            await RequestAccess(token);
                        }

                        connectStage = 1;

                        if (Profile.SetDeviceName)
                        {
                            await TryGet("?mode=setsetting&type=device_name&value=SM-G9350");
                        }

                        connectStage = 2;

                        LumixState.Reset();

                        LumixState.MenuSet = await GetMenuSet();

                        if (LumixState.MenuSet == null)
                        {
                            LogError($"Camera connection failed on Stage {connectStage} for camera {Device.ModelName}", "CameraConnect");
                            LumixState.IsLimited = true;
                        }

                        if (!LumixState.IsLimited)
                        {
                            LumixState.CurMenu = await GetCurMenu();
                        }

                        connectStage = 3;
                        await SwitchToRec();

                        connectStage        = 4;
                        LumixState.LensInfo = await GetLensInfo();

                        connectStage     = 5;
                        LumixState.State = await GetState();

                        connectStage = 6;
                        await http.Get <BaseRequestResult>($"?mode=startstream&value={liveviewport}", token);

                        token.ThrowIfCancellationRequested();
                        break;
                    }
                    catch (ConnectionLostException)
                    {
                        Debug.WriteLine("Connection lost", "Connection");
                    }
                    catch (TimeoutException)
                    {
                        Debug.WriteLine("Timeout", "Connection");
                    }
                    catch (OperationCanceledException)
                    {
                        return(false);
                    }
                    catch (Exception ex)
                    {
                        LogError($"Camera connection failed on Stage {connectStage} for camera {Device.ModelName}", ex);
                    }

                    await Task.Delay(1000, token);
                }while (true);

                if (OffFrameProcessor == null)
                {
                    connectStage                   = 7;
                    OffFrameProcessor              = new OffFrameProcessor(Device.ModelName, Parser, LumixState);
                    OffFrameProcessor.LensChanged += OffFrameProcessor_LensChanged;
                }

                stateTimer.Change(2000, 2000);
                return(true);
            }
            catch (OperationCanceledException)
            {
                connectCancellation.Dispose();
                return(false);
            }
            catch (Exception e)
            {
                LogError($"Camera connection failed on Stage {connectStage} for camera {Device.ModelName}", e);
                return(false);
            }
            finally
            {
                isConnecting = false;
            }
        }
Beispiel #2
0
 public OffFrameProcessor(string deviceName, CameraParser parser, LumixState lumixState)
 {
     this.parser     = parser;
     this.lumixState = lumixState;
     this.deviceName = deviceName;
 }