当前位置: 首页>>代码示例>>C#>>正文


C# Device.SetConnected方法代码示例

本文整理汇总了C#中Device.SetConnected方法的典型用法代码示例。如果您正苦于以下问题:C# Device.SetConnected方法的具体用法?C# Device.SetConnected怎么用?C# Device.SetConnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Device的用法示例。


在下文中一共展示了Device.SetConnected方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RefreshDevices

        public void RefreshDevices()
        {
            // Mark all devices as disconnected. We will check which of those
            // are connected below.
            foreach (var device in Devices)
            {
                device.SetConnected(false);
            }

            // Discover joystick devices
            int xinput_device_count = 0;
            foreach (RawInputDeviceList dev in WinRawInput.GetDeviceList())
            {
                // Skip non-joystick devices
                if (dev.Type != RawInputDeviceType.HID)
                    continue;

                // We use the device handle as the hardware id.
                // This works, but the handle will change whenever the
                // device is unplugged/replugged. We compensate for this
                // by checking device GUIDs, below.
                // Note: we cannot use the GUID as the hardware id,
                // because it is costly to query (and we need to query
                // that every time we process a device event.)
                IntPtr handle = dev.Device;
                bool is_xinput = IsXInput(handle);
                Guid guid = GetDeviceGuid(handle);
                long hardware_id = handle.ToInt64();

                Device device = Devices.FromHardwareId(hardware_id);
                if (device != null)
                {
                    // We have already opened this device, mark it as connected
                    device.SetConnected(true);
                }
                else
                {
                    device = new Device(handle, guid, is_xinput,
                        is_xinput ? xinput_device_count++ : 0);

                    // This is a new device, query its capabilities and add it
                    // to the device list
                    if (!QueryDeviceCaps(device))
                    {
                        continue;
                    }
                    device.SetConnected(true);

                    // Check if a disconnected device with identical GUID already exists.
                    // If so, replace that device with this instance.
                    Device match = null;
                    foreach (Device candidate in Devices)
                    {
                        if (candidate.GetGuid() == guid && !candidate.GetCapabilities().IsConnected)
                        {
                            match = candidate;
                        }
                    }
                    if (match != null)
                    {
                        Devices.Remove(match.Handle.ToInt64());
                    }

                    Devices.Add(hardware_id, device);

                    Debug.Print("[{0}] Connected joystick {1} ({2})",
                        GetType().Name, device.GetGuid(), device.GetCapabilities());
                }
            }
        }
开发者ID:RockyTV,项目名称:opentk,代码行数:70,代码来源:WinRawJoystick.cs

示例2: FetchDevicesAsync

        private async Task<IEnumerable<Device>> FetchDevicesAsync(Config config, CancellationToken cancellationToken)
        {
            var connections = await this.apiClient.Value.FetchConnectionsAsync(cancellationToken);
            // We can potentially see duplicate devices (if the user set their config file that way). Ignore them.
            var devices = config.Devices.DistinctBy(x => x.DeviceID).Select(device =>
            {
                var deviceObj = new Device(device.DeviceID, device.Name);
                ItemConnectionData connectionData;
                if (connections.DeviceConnections.TryGetValue(device.DeviceID, out connectionData))
                {
                    if (connectionData.Connected && connectionData.Address != null)
                        deviceObj.SetConnected(SyncthingAddressParser.Parse(connectionData.Address));
                    if (connectionData.Paused)
                        deviceObj.SetPaused();
                }
                return deviceObj;
            });

            cancellationToken.ThrowIfCancellationRequested();

            return devices;
        }
开发者ID:johnhk,项目名称:SyncTrayzor,代码行数:22,代码来源:SyncthingDeviceManager.cs


注:本文中的Device.SetConnected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。