Пример #1
0
        internal bool ConnectAndPair()
        {
            if (UDAPnP.Protocol == UDAPnP.LGProtocol.LG2011 ||
                UDAPnP.Protocol == UDAPnP.LGProtocol.LG2012x)
            {
                // LG UPnP stack is sometimes very slow in answering,
                // so wait up to 5 seconds before giving up pairing.

                int loops = 0;

                while (IPAddress == null || IPAddress.Length == 0)
                {
                    Thread.Sleep(5);

                    if (loops++ > 100)
                    {
                        Log.Error("Auto3D: LG service not connected withing additional 10 seconds!");
                        return(false);
                    }
                }

                if (UDAPnP.UpdateServiceInformation(IPAddress))
                {
                    Log.Info("Auto3D: UpdateServiceInfo OK");

                    if (PairingKey.Length > 0)
                    {
                        if (UDAPnP.RequestPairing(PairingKey))
                        {
                            Log.Info("Auto3D: Pairing LG client with key {0} succeeded", PairingKey);
                        }
                        else
                        {
                            Log.Error("Auto3D: Pairing LG client with key {0} failed!", PairingKey);
                            return(false);
                        }
                    }
                }
                else
                {
                    Log.Error("Auto3D: UpdateServiceInfo failed!");
                    return(false);
                }
            }
            else // WebOS
            {
                WebOS.Register(IPAddress, PairingKey);
            }

            return(true);
        }
Пример #2
0
        private void buttonSendKey_Click(object sender, EventArgs e)
        {
            if (!UDAPnP.Connected)
            {
                if (!UDAPnP.UpdateServiceInformation(_device.IPAddress))
                {
                    MessageBox.Show("Connection to LG TV failed!");
                    return;
                }
            }

            if (UDAPnP.RequestPairing(textBoxPairingKey.Text))
            {
                SaveSettings();
            }
        }