Пример #1
0
        private async void MoveForwardButton_Pressed(object sender, EventArgs e)
        {
            if (AutoSwitch.IsToggled)
            {
                AutoSwitch.IsToggled = false;
            }

            try
            {
                await Task.Run(() =>
                {
                    while (MoveForwardButton.IsPressed && speed < 10)
                    {
                        _control.Move(allowMoving: true, forward: true, speed: speed);
                        speed++;
                        Thread.Sleep(150);
                    }
                });
            }
            catch (Exception)
            {
                await Navigation.PopModalAsync();

                CrossToastPopUp.Current.ShowToastMessage("Lost Connection");
                _connection = null;
                _control    = null;
            }
        }
Пример #2
0
 public void CloseConnection()
 {
     DeviceConnection.Close();
     Log.InfoFormat("Close connection for device #{0} successfully", Device.DN);
     DeviceConnection = null;
     Device           = null;
 }
Пример #3
0
 /// <summary>
 /// Creates a new UPnP device instance at the control point (client) side.
 /// </summary>
 /// <param name="connection">Device connection instance which attends the connection with the server side.</param>
 /// <param name="deviceType">Type of the device instance to match, in the format "schemas-upnp-org:device:[device-type]" or
 /// "vendor-domain:device:[device-type]". Note that in vendor-defined types, all dots in the vendors domain are
 /// replaced by hyphens.</param>
 /// <param name="deviceTypeVersion">Version of the device type to match.</param>
 /// <param name="uuid">UUID of the device we are connected to.</param>
 public CpDevice(DeviceConnection connection, string deviceType, int deviceTypeVersion, string uuid)
 {
     _connection        = connection;
     _deviceType        = deviceType;
     _deviceTypeVersion = deviceTypeVersion;
     _uuid = uuid;
 }
Пример #4
0
        Tunnel(SafeTunnelHandle handle, DeviceConnection owner)
        {
            Log.Write("Tunnel.Tunnel()");

            this.handle = handle;
            this.owner  = owner;
        }
Пример #5
0
 public void CloseControlsSettingPopup(DeviceConnection connection = null, Object arg = null)
 {
     IsControlsSettingPopupOpen  = false;
     _waitingHIDToControlBinding = null;
     _timer.Tick -= _controlsSettingsWaitForHidKey_EventHandler;
     _hidConnection.OnDeviceClose -= CloseControlsSettingPopup;
 }
        void OnUPnPDeviceDisconnected(DeviceConnection connection)
        {
            IEnumerable <UPnPServiceProxyBase> servicesToDispose;

            lock (_networkTracker.SharedControlPointData.SyncObj)
            {
                _connection = null;
                _contentDirectoryService    = null;
                _resourceInformationService = null;
                _serverControllerService    = null;
                servicesToDispose           = new List <UPnPServiceProxyBase>(_additionalServices);
                _additionalServices.Clear();
            }
            // Dispose all additional services if possible, to allow proper shutdown and cleanup
            foreach (UPnPServiceProxyBase service in servicesToDispose)
            {
                IDisposable disposable = service as IDisposable;
                if (disposable == null)
                {
                    continue;
                }
                try
                {
                    disposable.Dispose();
                }
                catch (Exception e)
                {
                    ServiceRegistration.Get <ILogger>().Warn("UPnPClientControlPoint: Error disposing additional service '{0}'", service, e);
                }
            }
            InvokeBackendServerDeviceDisconnected(connection);
        }
 public ClientConnection(UPnPControlPoint controlPoint, DeviceConnection connection, ClientDescriptor clientDescriptor)
 {
     _controlPoint     = controlPoint;
     _connection       = connection;
     _clientDescriptor = clientDescriptor;
     _connection.DeviceDisconnected += OnUPnPDeviceDisconnected;
     try
     {
         CpService ccsStub = connection.Device.FindServiceByServiceId(UPnPTypesAndIds.CLIENT_CONTROLLER_SERVICE_ID);
         if (ccsStub == null)
         {
             throw new InvalidDataException("ClientController service not found in device '{0}' of type '{1}:{2}'",
                                            clientDescriptor.MPFrontendServerUUID,
                                            UPnPTypesAndIds.FRONTEND_SERVER_DEVICE_TYPE, UPnPTypesAndIds.FRONTEND_SERVER_DEVICE_TYPE_VERSION);
         }
         lock (_connection.CPData.SyncObj)
             _clientController = new UPnPClientControllerServiceProxy(ccsStub);
         // TODO: other services
     }
     catch (Exception)
     {
         _connection.DeviceDisconnected -= OnUPnPDeviceDisconnected;
         throw;
     }
 }
Пример #8
0
 /// <summary>
 /// Creates a new UPnP device instance at the control point (client) side.
 /// </summary>
 /// <param name="connection">Device connection instance which attends the connection with the server side.</param>
 /// <param name="deviceType">Type of the device instance to match, in the format "schemas-upnp-org:device:[device-type]" or
 /// "vendor-domain:device:[device-type]". Note that in vendor-defined types, all dots in the vendors domain are
 /// replaced by hyphens.</param>
 /// <param name="deviceTypeVersion">Version of the device type to match.</param>
 /// <param name="uuid">UUID of the device we are connected to.</param>
 public CpDevice(DeviceConnection connection, string deviceType, int deviceTypeVersion, string uuid)
 {
   _connection = connection;
   _deviceType = deviceType;
   _deviceTypeVersion = deviceTypeVersion;
   _uuid = uuid;
 }
Пример #9
0
        public ActionResult ConnectBiometric(DownloadDataViewModel model)
        {
            device                 = new Device();
            device.DN              = 1;
            device.Model           = "A-C071";
            device.ConnectionModel = 5;

            device.IpAddress         = model.IpAddress;
            device.IpPort            = int.Parse(model.Port);
            device.CommunicationType = CommunicationType.Tcp;
            deviceConnection         = DeviceConnection.CreateConnection(ref device);
            System.Diagnostics.Debug.WriteLine(deviceConnection.Open());

            if (deviceConnection.Open() > 0)
            {
                deviceEty                  = new DeviceComEty();
                deviceEty.Device           = device;
                deviceEty.DeviceConnection = deviceConnection;
            }
            else
            {
            }


            return(View());
        }
Пример #10
0
 internal static CpService ConnectService(DeviceConnection connection, CpDevice parentDevice,
                                          ServiceDescriptor serviceDescriptor, DataTypeResolverDlgt dataTypeResolver)
 {
     lock (connection.CPData.SyncObj)
     {
         CpService result = new CpService(connection, parentDevice, serviceDescriptor.ServiceType, serviceDescriptor.ServiceTypeVersion,
                                          serviceDescriptor.ServiceId);
         XPathNavigator serviceNav = serviceDescriptor.ServiceDescription.CreateNavigator();
         serviceNav.MoveToChild(XPathNodeType.Element);
         XmlNamespaceManager nsmgr = new XmlNamespaceManager(serviceNav.NameTable);
         nsmgr.AddNamespace("s", UPnPConsts.NS_SERVICE_DESCRIPTION);
         XPathNodeIterator svIt = serviceNav.Select("s:serviceStateTable/s:stateVariable", nsmgr);
         // State variables must be connected first because they are needed from the action's arguments
         while (svIt.MoveNext())
         {
             result.AddStateVariable(CpStateVariable.ConnectStateVariable(connection, result, svIt.Current, nsmgr, dataTypeResolver));
         }
         XPathNodeIterator acIt = serviceNav.Select("s:actionList/s:action", nsmgr);
         while (acIt.MoveNext())
         {
             result.AddAction(CpAction.ConnectAction(connection, result, acIt.Current, nsmgr));
         }
         return(result);
     }
 }
Пример #11
0
 /// <summary>
 /// Creates a new <see cref="CpStateVariable"/> instance.
 /// </summary>
 /// <param name="connection">Device connection instance which attends the connection with the server side.</param>
 /// <param name="parentService">Instance of the service which contains the new state variable.</param>
 /// <param name="name">Name of the state variable.</param>
 /// <param name="dataType">Data type of the state variable.</param>
 public CpStateVariable(DeviceConnection connection, CpService parentService, string name, CpDataType dataType)
 {
   _connection = connection;
   _parentService = parentService;
   _name = name;
   _dataType = dataType;
 }
Пример #12
0
    /// <summary>
    /// Initializes a new instance of the <see cref="RTSPServer"/> class.
    /// </summary>
    /// <param name="aPortNumber">A numero port.</param>
    /// <param name="username">username.</param>
    /// <param name="password">password.</param>
    public RtspServer(int portNumber, string username, string password, string nvrHost, int nvrPort, int nvrChannel, string nvrUsername, string nvrPassword)
    {
        if (portNumber < System.Net.IPEndPoint.MinPort || portNumber > System.Net.IPEndPoint.MaxPort)
        {
            throw new ArgumentOutOfRangeException("aPortNumber", portNumber, "Port number must be between System.Net.IPEndPoint.MinPort and System.Net.IPEndPoint.MaxPort");
        }
        Contract.EndContractBlock();

        if (string.IsNullOrEmpty(username) == false &&
            string.IsNullOrEmpty(password) == false)
        {
            string realm = "RtspForZR04RN";
            auth = new Authentication(username, password, realm, Authentication.Type.Digest);
        }
        else
        {
            auth = null;
        }

        this.nvrHost     = nvrHost;
        this.nvrPort     = nvrPort;
        this.nvrChannel  = nvrChannel;
        this.nvrUsername = nvrUsername;
        this.nvrPassword = nvrPassword;

        RtspUtils.RegisterUri();
        rtspServerListener = new TcpListener(IPAddress.Any, portNumber);
        nvr = new DeviceConnection();
        nvr.StreamFrameReceived += Nvr_StreamFrameReceived;
        nvr.Disconnected        += Nvr_Disconnected;
    }
Пример #13
0
 /// <summary>
 /// Creates a new <see cref="CpStateVariable"/> instance.
 /// </summary>
 /// <param name="connection">Device connection instance which attends the connection with the server side.</param>
 /// <param name="parentService">Instance of the service which contains the new state variable.</param>
 /// <param name="name">Name of the state variable.</param>
 /// <param name="dataType">Data type of the state variable.</param>
 public CpStateVariable(DeviceConnection connection, CpService parentService, string name, CpDataType dataType)
 {
     _connection    = connection;
     _parentService = parentService;
     _name          = name;
     _dataType      = dataType;
 }
Пример #14
0
        internal static CpDevice ConnectDevice(DeviceConnection connection, DeviceDescriptor deviceDescriptor, DataTypeResolverDlgt dataTypeResolver)
        {
            lock (connection.CPData.SyncObj)
            {
                string type;
                int    version;
                if (!deviceDescriptor.GetTypeAndVersion(out type, out version))
                {
                    throw new ArgumentException(string.Format("Invalid device type/version URN '{0}'", deviceDescriptor.TypeVersion_URN));
                }
                CpDevice result = new CpDevice(connection, type, version, deviceDescriptor.DeviceUUID);

                foreach (DeviceDescriptor childDevice in deviceDescriptor.ChildDevices)
                {
                    result.AddEmbeddedDevice(ConnectDevice(connection, childDevice, dataTypeResolver));
                }
                IDictionary <string, ServiceDescriptor> serviceDescriptors;
                if (deviceDescriptor.RootDescriptor.ServiceDescriptors.TryGetValue(deviceDescriptor.DeviceUUID, out serviceDescriptors))
                {
                    foreach (ServiceDescriptor serviceDescriptor in serviceDescriptors.Values)
                    {
                        if (serviceDescriptor.State == ServiceDescriptorState.Ready)
                        {
                            result.AddService(CpService.ConnectService(connection, result, serviceDescriptor, dataTypeResolver));
                        }
                        else
                        {
                            UPnPConfiguration.LOGGER.Warn("CpDevice.ConnectDevice: Unable to connect to service '{0}' (type '{1}', version '{2}') - the service descriptor was not initialized properly",
                                                          serviceDescriptor.ServiceId, serviceDescriptor.ServiceType, serviceDescriptor.ServiceTypeVersion);
                        }
                    }
                }
                return(result);
            }
        }
Пример #15
0
        internal void Disconnect()
        {
            DeviceConnection connection = _connection;

            if (connection == null)
            {
                return;
            }
            ICollection <CpDevice>  embeddedDevices;
            ICollection <CpService> services;

            lock (connection.CPData.SyncObj)
            {
                _connection     = null;
                embeddedDevices = new List <CpDevice>(_embeddedDevices.Values);
                services        = new List <CpService>(_services.Values);
            }
            foreach (CpDevice embeddedDevice in embeddedDevices)
            {
                embeddedDevice.Disconnect();
            }
            foreach (CpService service in services)
            {
                service.Disconnect();
            }
        }
Пример #16
0
        static async Task Main(string[] args)
        {
            // Run this together with SnoopApp for diagnostics
            connection = new DeviceConnection();
            connection.UnknownCommandReceived += Connection_UnknownCommandReceived;
            await connection.Connect("127.0.0.1", 5000);

            Console.WriteLine("Connected");
            Console.Write("Password: "******"admin", password);

            Console.WriteLine("Logged in");
            Console.WriteLine("Device name: {0}", loginSuccess.ProductInfo.DeviceName);
            Console.WriteLine("Firmware version: {0}", loginSuccess.ProductInfo.FirmwareVersion);
            StreamFrame keyframe = await connection.SnapKeyframe(0);

            Console.WriteLine("Keyframe received");
            Console.WriteLine("Width: {0}", keyframe.Width);
            Console.WriteLine("Height: {0}", keyframe.Height);
            // File.WriteAllBytes("C:\\temp\\keyframe.h264", keyframe.Data);
            connection.StreamFrameReceived += Connection_StreamFrameReceived;
            fs       = new FileStream("C:\\temp\\channel0a.h264", FileMode.Create, FileAccess.Write, FileShare.Read);
            streamId = await connection.StreamStart(0);

            // Console.ReadKey();
            await(new TaskCompletionSource <bool>().Task);
        }
Пример #17
0
 /// <summary>
 /// Creates a new UPnP service instance at the client (control point) side.
 /// </summary>
 /// <param name="connection">Device connection instance which attends the connection with the server side.</param>
 /// <param name="parentDevice">Instance of the device which contains the new service.</param>
 /// <param name="serviceType">Type of the service instance, in the format "schemas-upnp-org:service:[service-type]" or
 /// "vendor-domain:service:[service-type]". Note that in vendor-defined types, all dots in the vendors domain are
 /// replaced by hyphens.</param>
 /// <param name="serviceTypeVersion">Version of the implemented service type.</param>
 /// <param name="serviceId">Service id in the format "urn:upnp-org:serviceId:[service-id]" (for standard services) or
 /// "urn:domain-name:serviceId:[service-id]" (for vendor-defined service types).</param>
 public CpService(DeviceConnection connection, CpDevice parentDevice, string serviceType, int serviceTypeVersion, string serviceId)
 {
     _connection         = connection;
     _parentDevice       = parentDevice;
     _serviceType        = serviceType;
     _serviceTypeVersion = serviceTypeVersion;
     _serviceId          = serviceId;
 }
Пример #18
0
        public AccessControlForm(DeviceCommEty deviceEty)
        {
            InitializeComponent();
            device           = deviceEty.Device;
            deviceConnection = deviceEty.DeviceConnection;

            lockComboBox.SelectedIndex = 0;
        }
Пример #19
0
 /// <summary>
 /// Creates a new UPnP service instance at the client (control point) side.
 /// </summary>
 /// <param name="connection">Device connection instance which attends the connection with the server side.</param>
 /// <param name="parentDevice">Instance of the device which contains the new service.</param>
 /// <param name="serviceType">Type of the service instance, in the format "schemas-upnp-org:service:[service-type]" or
 /// "vendor-domain:service:[service-type]". Note that in vendor-defined types, all dots in the vendors domain are
 /// replaced by hyphens.</param>
 /// <param name="serviceTypeVersion">Version of the implemented service type.</param>
 /// <param name="serviceId">Service id in the format "urn:upnp-org:serviceId:[service-id]" (for standard services) or
 /// "urn:domain-name:serviceId:[service-id]" (for vendor-defined service types).</param>
 public CpService(DeviceConnection connection, CpDevice parentDevice, string serviceType, int serviceTypeVersion, string serviceId)
 {
   _connection = connection;
   _parentDevice = parentDevice;
   _serviceType = serviceType;
   _serviceTypeVersion = serviceTypeVersion;
   _serviceId = serviceId;
 }
Пример #20
0
        private void cmdOk_Click(object sender, EventArgs e)
        {
            DataTable        dt = null;
            DeviceConnection dc = null;

            if (string.IsNullOrWhiteSpace(txtName.Text))
            {
                MessageBox.Show("You must provide a valid name for the decoder.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtName.Focus();
                return;
            }
            else if (int.Parse(txtOutputs.Text) <= 0)
            {
                MessageBox.Show("Invalid number of decoder digital outputs.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtOutputs.SelectAll();
                txtOutputs.Focus();
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            this.Decoder.Name         = txtName.Text.Trim();
            this.Decoder.Manufacturer = cboManufacturer.EditValue as Manufacturer;
            this.Decoder.Model        = cboModel.Text.Trim();
            this.Decoder.Outputs      = int.Parse(txtOutputs.Text);
            this.Decoder.Notes        = txtNotes.Text.Trim();
            this.Decoder.Type         = Device.DeviceType.AccessoryDecoder;

            try
            {
                if (!this.Decoder.IsNew)
                {
                    // Update the outputs addresses
                    // At this point the module must have all outputs created in DB
                    dt = grdConnect.DataSource as DataTable;
                    foreach (DataRow row in dt.Rows)
                    {
                        dc         = DeviceConnection.Get((long)row[0]);
                        dc.Address = (int)row[3];
                    }
                }

                Device.Save(this.Decoder);

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;

                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
        DeviceStream(DeviceConnection owner, SafeStreamHandle handle)
        {
            this.handle = handle;
            this.owner  = owner;

            ServiceConfigurationResponse = null;

            Log.Write("NabtoClientStream.NabtoClientStream({0}, {1})", owner, handle);
        }
Пример #22
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                device                 = new Device();
                device.DN              = 1;
                device.Password        = "******";
                device.Model           = "A-C030";
                device.ConnectionModel = 5;//等于5时才能正确加载ZD2911通讯模块

                if (rdb_Network.Checked == true)
                {
                    //ip address
                    if (string.IsNullOrEmpty(txt_IP.Text.Trim()))
                    {
                        MessageBox.Show("Please Input IP Address", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txt_IP.Focus();
                        return;
                    }

                    if (false == ConvertObject.IsCorrenctIP(txt_IP.Text.Trim()))
                    {
                        MessageBox.Show("Illegal IP Address", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        txt_IP.Focus();
                        return;
                    }

                    device.IpAddress         = txt_IP.Text.Trim();
                    device.IpPort            = int.Parse(txt_Port.Text);
                    device.CommunicationType = CommunicationType.Tcp;
                }
                else
                {
                    device.CommunicationType = CommunicationType.Usb;
                }

                deviceConnection = DeviceConnection.CreateConnection(ref device);
                if (deviceConnection.Open() > 0)
                {
                    deviceEty                  = new DeviceComEty();
                    deviceEty.Device           = device;
                    deviceEty.DeviceConnection = deviceConnection;
                    MessageBox.Show("Device successfully connected", "System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    btnBiometricData.Enabled = true;
                    btnDisconnect.Enabled    = true;
                    btnConnect.Enabled       = false;
                }
                else
                {
                    MessageBox.Show("Failed to Connect to Device", "System", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        protected void InvokeBackendServerDeviceDisconnected(DeviceConnection connection)
        {
            BackendServerDisconnectedDlgt dlgt = BackendServerDisconnected;

            if (dlgt != null)
            {
                dlgt(connection);
            }
        }
        public string GetResourceServerBaseURL(out IPAddress localIpAddress)
        {
            CpAction         action        = GetAction("GetResourceServerBaseURL");
            IList <object>   outParameters = action.InvokeAction(null);
            DeviceConnection connection    = _serviceStub.Connection;

            localIpAddress = connection == null ? null : connection.RootDescriptor.SSDPRootEntry.PreferredLink.Endpoint.EndPointIPAddress;
            return((string)outParameters[0]);
        }
Пример #25
0
        void ShowInputs(DeviceConnection connection)
        {
            TreeListNode   root;
            TreeListNode   mod;
            TreeListNode   output;
            TreeListColumn col;

            tvwConnections.BeginUpdate();
            col              = tvwConnections.Columns.Add();
            col.Caption      = "Name";
            col.VisibleIndex = 0;
            col              = tvwConnections.Columns.Add();
            col.Caption      = "Address";
            col.VisibleIndex = 1;
            col              = tvwConnections.Columns.Add();
            col.Caption      = "Element";
            col.VisibleIndex = 2;
            tvwConnections.EndUpdate();

            tvwConnections.BeginUnboundLoad();

            root = tvwConnections.AppendNode(new object[] { "Modules", string.Empty, string.Empty }, null);
            root.StateImageIndex = 4;
            root.Expanded        = true;

            foreach (Device module in OTCContext.Project.Devices)
            {
                mod = tvwConnections.AppendNode(new object[] { module.Name, string.Empty, string.Empty }, root);
                mod.StateImageIndex = 1;
                mod.Tag             = module;

                foreach (DeviceConnection con in OTCContext.Project.GetDeviceConnections(module))
                {
                    output = tvwConnections.AppendNode(new object[] { con.Output,
                                                                      con.Address.ToString("D4"),
                                                                      con.Element == null ? "<empty>" : con.Element.Name }, mod);
                    output.StateImageIndex = (con.Element == null ? 2 : 3);
                    output.Tag             = con;

                    if (connection != null && connection.ID == con.ID)
                    {
                        tvwConnections.FocusedNode = output;
                    }
                }
            }

            if (tvwConnections.FocusedNode != null && tvwConnections.FocusedNode != root)
            {
                tvwConnections.MakeNodeVisible(tvwConnections.FocusedNode);
            }
            else
            {
                root.Expanded = true;
            }

            tvwConnections.EndUnboundLoad();
        }
Пример #26
0
 void OnBackendServerDisconnected(DeviceConnection connection)
 {
   lock (_syncObj)
     _isHomeServerConnected = false;
   IImporterWorker importerWorker = ServiceRegistration.Get<IImporterWorker>();
   importerWorker.Suspend();
   UpdateCurrentlyImportingShares(null); // Mark all shares as not being imported
   ServerConnectionMessaging.SendServerConnectionStateChangedMessage(ServerConnectionMessaging.MessageType.HomeServerDisconnected);
 }
Пример #27
0
        /// <summary>
        /// Pairing device with user credentials (_credentials)
        /// </summary>
        private async Task CreatePairing()
        {
            _log.Debug($"Pairing device with user credentials");

            try
            {
                var ps = new Dictionary <string, string>()
                {
                    { "username", _credentials.Username },
                    { "password", _credentials.Password },
                    { "type", "samsungtv" }
                };

                var deviceConnectionString = await SendRequest("create-pairing", ps);

                var devConnJson = JObject.Parse(deviceConnectionString);

                if (
                    ((devConnJson.HasValue("status") && (devConnJson.GetStringValue("status") == "0"))) ||
                    ((devConnJson.HasValue("error")) && (devConnJson.GetStringValue("error") == "bad login")) ||
                    (!devConnJson.HasValue("deviceId"))
                    )
                {
                    if ((devConnJson.HasValue("error")) && (devConnJson.GetStringValue("error") == "bad login"))
                    {
                        _status = StatusEnum.PairingFailed;
                    }
                    else
                    {
                        _status = StatusEnum.LoginFailed;
                    }
                }
                else
                {
                    _status = StatusEnum.Paired;

                    _deviceConnection = new DeviceConnection()
                    {
                        deviceId = devConnJson.GetStringValue("deviceId").ToString(),
                        password = devConnJson.GetStringValue("password").ToString()
                    };

                    _log.Debug("Received User Connection:");
                    _log.Debug(_deviceConnection.ToString());
                }
            }
            catch (WebException wex)
            {
                _log.Error(wex, "Error while pairing device");
                _status = StatusEnum.ConnectionNotAvailable;
            }
            catch (Exception ex)
            {
                _log.Error(ex, "Error while pairing device");
                _status = StatusEnum.GeneralError;
            }
        }
Пример #28
0
        async Task <DeviceConnection> GetDeviceAsync()
        {
            if (_connection == null)
            {
                _connection = await DeviceConnection.CreateAsync(_comPort);
            }

            return(_connection);
        }
Пример #29
0
 private void btn_CloseDevice_Click(object sender, EventArgs e)
 {
     deviceConnection.Close();
     btn_CloseDevice.Enabled = false;
     SetButtonEnabled(false);
     btn_OpenDevice.Enabled = true;
     device           = null;
     deviceConnection = null;
     deviceEty        = null;
 }
Пример #30
0
 void StatusEditorControl_MapChanged(object sender, MapChangedEventArgs e)
 {
     foreach (DeviceConnection connection in this.Element.AccessoryConnections)
     {
         if (connection != null)
         {
             DeviceConnection.Save(connection);
         }
     }
 }
Пример #31
0
        internal void Disconnect()
        {
            DeviceConnection connection = _connection;

            if (connection == null)
            {
                return;
            }
            lock (connection.CPData.SyncObj)
                _connection = null;
        }
Пример #32
0
        internal void Disconnect()
        {
            DeviceConnection connection = _connection;

            if (connection == null)
            {
                return;
            }
            using (_connection.CPData.Lock.EnterWrite())
                _connection = null;
        }
Пример #33
0
        public bool CheckExists(DeviceConnection objDeviceConnection)
        {
            string             sql           = null;
            List <DbParameter> parameterList = new List <DbParameter>();

            sql = " select count(1) from tbl_device_connection where DeviceNumber=:DeviceNumber ";

            parameterList.Add(new OracleParameter(":DeviceNumber", objDeviceConnection.DeviceNumber));

            return(int.Parse(DbHelper.ExecuteScalar(sql, CommandType.Text, parameterList.ToArray()).ToString()) > 0);
        }
Пример #34
0
        public Task SetConnectionSettings(DeviceConnection.ConnectionSettings connectionSettings)
        {
            device.BaudRate = connectionSettings.BaudRate;
            device.Handshake = connectionSettings.Handshake;
            device.Parity = connectionSettings.Parity;
            device.StopBits = connectionSettings.StopBits;
            device.DataBits = connectionSettings.DataBits;

            if (connectionSettings.XOn != 0x00 || connectionSettings.XOff != 0x00)
                throw new Exception("Setting the XOn / XOff bytes is not supported for the WindowsSerialDevice.");

            return Task.CompletedTask;
        }
Пример #35
0
 internal static CpStateVariable ConnectStateVariable(DeviceConnection connection, CpService parentService,
     XPathNavigator svIt, IXmlNamespaceResolver nsmgr, DataTypeResolverDlgt dataTypeResolver)
 {
   string name = ParserHelper.SelectText(svIt, "s:name/text()", nsmgr);
   XPathNodeIterator dtIt = svIt.Select("s:dataType", nsmgr);
   if (!dtIt.MoveNext())
     throw new ArgumentException("Error evaluating data type element");
   CpDataType dataType = CpDataType.CreateDataType(dtIt.Current, nsmgr, dataTypeResolver);
   CpStateVariable result = new CpStateVariable(connection, parentService, name, dataType);
   XPathNodeIterator dvIt = svIt.Select("s:defaultValue", nsmgr);
   if (dvIt.MoveNext())
   {
     XmlReader reader = dvIt.Current.ReadSubtree();
     reader.MoveToContent();
     result.DefaultValue = dataType.SoapDeserializeValue(reader, true);  // Default value is always simple value (see DevArch)
   }
   XPathNodeIterator avlIt = svIt.Select("s:allowedValueList/s:allowedValue", nsmgr);
   if (avlIt.Count > 0)
   {
     IList<string> allowedValueList = new List<string>();
     while (avlIt.MoveNext())
       allowedValueList.Add(ParserHelper.SelectText(avlIt.Current, "text()", null));
     result.AllowedValueList = allowedValueList;
   }
   XPathNodeIterator avrIt = svIt.Select("s:allowedValueRange", nsmgr);
   if (avrIt.MoveNext())
     result.AllowedValueRange = CpAllowedValueRange.CreateAllowedValueRange(avrIt.Current, nsmgr);
   return result;
 }
Пример #36
0
 internal void Disconnect()
 {
   DeviceConnection connection = _connection;
   if (connection == null)
     return;
   lock (connection.CPData.SyncObj)
     _connection = null;
 }
Пример #37
0
 public GENAClientController(CPData cpData, DeviceConnection connection, EndpointConfiguration endpoint, UPnPVersion upnpVersion)
 {
   _cpData = cpData;
   _connection = connection;
   _endpoint = endpoint;
   _upnpVersion = upnpVersion;
   _eventNotificationPath = "/" + Guid.NewGuid();
   IPAddress address = endpoint.EndPointIPAddress;
   _eventNotificationEndpoint = new IPEndPoint(address, address.AddressFamily == AddressFamily.InterNetwork ?
       cpData.HttpPortV4 : cpData.HttpPortV6);
   _subscriptionRenewalTimer = new Timer(OnSubscriptionRenewalTimerElapsed);
 }
Пример #38
0
 internal static CpAction ConnectAction(DeviceConnection connection, CpService parentService, XPathNavigator actionNav,
     IXmlNamespaceResolver nsmgr)
 {
   lock (connection.CPData.SyncObj)
   {
     string name = ParserHelper.SelectText(actionNav, "s:name/text()", nsmgr);
     CpAction result = new CpAction(connection, parentService, name);
     XPathNodeIterator argumentIt = actionNav.Select("s:argumentList/s:argument", nsmgr);
     while (argumentIt.MoveNext())
     {
       CpArgument argument = CpArgument.CreateArgument(result, parentService, argumentIt.Current, nsmgr);
       if (argument.Direction == ArgumentDirection.In)
         result.AddInAgrument(argument);
       else
         result.AddOutAgrument(argument);
     }
     return result;
   }
 }
Пример #39
0
 /// <summary>
 /// Creates a new instance of <see cref="CpAction"/>.
 /// </summary>
 /// <param name="connection">Device connection instance which attends the connection with the server side.</param>
 /// <param name="parentService">Instance of the service which contains the new action.</param>
 /// <param name="name">The name of the new action template.</param>
 public CpAction(DeviceConnection connection, CpService parentService, string name)
 {
   _connection = connection;
   _parentService = parentService;
   _name = name;
 }
Пример #40
0
    internal static CpDevice ConnectDevice(DeviceConnection connection, DeviceDescriptor deviceDescriptor, DataTypeResolverDlgt dataTypeResolver)
    {
      lock (connection.CPData.SyncObj)
      {
        string type;
        int version;
        if (!deviceDescriptor.GetTypeAndVersion(out type, out version))
          throw new ArgumentException(string.Format("Invalid device type/version URN '{0}'", deviceDescriptor.TypeVersion_URN));
        CpDevice result = new CpDevice(connection, type, version, deviceDescriptor.DeviceUUID);

        foreach (DeviceDescriptor childDevice in deviceDescriptor.ChildDevices)
          result.AddEmbeddedDevice(ConnectDevice(connection, childDevice, dataTypeResolver));
        IDictionary<string, ServiceDescriptor> serviceDescriptors;
        if (deviceDescriptor.RootDescriptor.ServiceDescriptors.TryGetValue(deviceDescriptor.DeviceUUID, out serviceDescriptors))
          foreach (ServiceDescriptor serviceDescriptor in serviceDescriptors.Values)
            if (serviceDescriptor.State == ServiceDescriptorState.Ready)
              result.AddService(CpService.ConnectService(connection, result, serviceDescriptor, dataTypeResolver));
            else
              UPnPConfiguration.LOGGER.Warn("CpDevice.ConnectDevice: Unable to connect to service '{0}' (type '{1}', version '{2}') - the service descriptor was not initialized properly",
                  serviceDescriptor.ServiceId, serviceDescriptor.ServiceType, serviceDescriptor.ServiceTypeVersion);
        return result;
      }
    }
Пример #41
0
 internal void Disconnect()
 {
   DeviceConnection connection = _connection;
   if (connection == null)
     return;
   ICollection<CpDevice> embeddedDevices;
   ICollection<CpService> services;
   lock (connection.CPData.SyncObj)
   {
     _connection = null;
     embeddedDevices = new List<CpDevice>(_embeddedDevices.Values);
     services = new List<CpService>(_services.Values);
   }
   foreach (CpDevice embeddedDevice in embeddedDevices)
     embeddedDevice.Disconnect();
   foreach (CpService service in services)
     service.Disconnect();
 }
Пример #42
0
 internal static CpService ConnectService(DeviceConnection connection, CpDevice parentDevice,
     ServiceDescriptor serviceDescriptor, DataTypeResolverDlgt dataTypeResolver)
 {
   lock (connection.CPData.SyncObj)
   {
     CpService result = new CpService(connection, parentDevice, serviceDescriptor.ServiceType, serviceDescriptor.ServiceTypeVersion,
         serviceDescriptor.ServiceId);
     XPathNavigator serviceNav = serviceDescriptor.ServiceDescription.CreateNavigator();
     serviceNav.MoveToChild(XPathNodeType.Element);
     XmlNamespaceManager nsmgr = new XmlNamespaceManager(serviceNav.NameTable);
     nsmgr.AddNamespace("s", UPnPConsts.NS_SERVICE_DESCRIPTION);
     XPathNodeIterator svIt = serviceNav.Select("s:serviceStateTable/s:stateVariable", nsmgr);
     // State variables must be connected first because they are needed from the action's arguments
     while (svIt.MoveNext())
       result.AddStateVariable(CpStateVariable.ConnectStateVariable(connection, result, svIt.Current, nsmgr, dataTypeResolver));
     XPathNodeIterator acIt = serviceNav.Select("s:actionList/s:action", nsmgr);
     while (acIt.MoveNext())
       result.AddAction(CpAction.ConnectAction(connection, result, acIt.Current, nsmgr));
     return result;
   }
 }
Пример #43
0
 public async Task SetConnectionSettings(DeviceConnection.ConnectionSettings connectionSettings)
 {
     await ftDevice.SetBaudRateAsync(connectionSettings.BaudRate);
     await ftDevice.SetDataCharacteristicsAsync(GetWordLength(connectionSettings.DataBits), GetStopBits(connectionSettings.StopBits), GetParity(connectionSettings.Parity));
     await ftDevice.SetFlowControlAsync(GetFlowControl(connectionSettings.Handshake), connectionSettings.XOn, connectionSettings.XOff);
 }