Discover external accessories from your app. More...
Import Statement: | import ArcGIS.AppFramework.Devices 1.0 |
Properties
- deviceFilter : var
- devices : DeviceListModel
- error : string
- properties : object
- refreshInterval : int
- running : bool
- sortCompare : var
Signals
- deviceDiscovered(Device device)
- discoverDevicesCompleted()
Methods
- object propertyValue(string key)
- setPropertyValue(string key, object value)
- start()
- stop()
Detailed Description
The DeviceDiscoveryAgent component searches for connected devices and makes them available to interact with in your app. By default Bluetooth devices are automatically scanned, but USB and serial port connected devices can additionally be scanned for. When new devices are discovered they are added to a list model, which can be used to populate other components such as drop down boxes or scrollviews. The list model can be optionally filtered or ordered.
This code sample shows usage of DeviceDiscoveryAgent, displaying Bluetooth devices found through device discovery in a combo box. Data read from the currently selected device is then printed into a list view, informed by DeviceListModel.
Item { property DeviceListModel deviceListModel: discoveryAgent.devices property Device currentDevice ColumnLayout { anchors.fill: parent anchors.margins: 10 ComboBox { id: comboBox Layout.fillWidth: true model: deviceListModel textRole: "name" onCurrentTextChanged: selectDevice(deviceListModel.get(currentIndex)) } ListView { Layout.fillWidth: true Layout.fillHeight: true model: messagesListModel delegate: Text { text: msg } } } DeviceDiscoveryAgent { id: discoveryAgent } DataSource { id: dataSource onReceivedDataChanged: log(receivedData.trim()) } ListModel { id: messagesListModel } Connections { target: deviceListModel onCountChanged: if (comboBox.currentIndex == -1 && deviceListModel.count > 0) { comboBox.currentIndex = 0; } } Component.onCompleted: discoveryAgent.start() function selectDevice(device) { if (currentDevice) currentDevice.connected = false; currentDevice = device; messagesListModel.clear(); JSON.stringify(device, undefined, 2).split("\n").forEach(log); dataSource.source = currentDevice; currentDevice.connected = true; } function log(txt) { console.log(txt); messagesListModel.append( { msg: txt } ); if (messagesListModel.count > 20) { messagesListModel.remove(0); } } }
Enumerations
DeviceFilter enumeration
Name | Value |
---|---|
DeviceDiscoveryAgent.None | 0 |
DeviceDiscoveryAgent.Bluetooth | 1 |
DeviceDiscoveryAgent.SerialPort | 2 |
DeviceDiscoveryAgent.USB | 4 |
Property Documentation
A filter based on properties of the devices, such as device type and name. Only the devices that fit the terms in this filter will be added to the device list model.
This code sample removes from the device list model all COM devices that correspond to Bluetooth devices, as well as similar devices with the prefixes 'tty' and 'cu' that can appear on macOS. As these COM, tty, and cu devices are usually not needed, they can be safely filtered out of most uses of DeviceDiscoveryAgent.
deviceFilter: function(device) { return !device.name.match(/^(COM|tty|cu)/i) }
[read-only] devices : DeviceListModel |
Returns a list of devices that have been discovered.
A list of properties to control device discovery. This code sample will disable Bluetooth scanning for devices.
DeviceDiscoveryAgent { id: discoveryAgent properties: { "isScanBluetoothDevices" : false } }
The time, in milliseconds, that must elapse before a new scan for devices is run. Default is 1000.
Used to sort devices in the list model based on properties such as name and device type. When new devices are discovered, they get filtered, added to the list model, and then sorted.
sortCompare: function (device1, device2) { return device1.name.toLowerCase() < device2.name.toLowerCase(); }
Signal Documentation
deviceDiscovered(Device device) |
Signal emitted when a device fitting the current deviceFilterFlag has been discovered.
Note: The corresponding handler is onDeviceDiscovered
.
Signal emitted when device discovery has completed.
Note: The corresponding handler is onDiscoverDevicesCompleted
.
Method Documentation
The key parameter
See also setPropertyValue().
Starts device discovery, for each time the amount of time defined by the refreshInterval property elapses, until stopDiscoverDevices is called.