DeviceDiscoveryAgent QML Type

Discover external accessories from your app. More...

Import Statement: import ArcGIS.AppFramework.Devices 1.0

Properties

Signals

Methods

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

NameValue
DeviceDiscoveryAgent.None0
DeviceDiscoveryAgent.Bluetooth1
DeviceDiscoveryAgent.SerialPort2
DeviceDiscoveryAgent.USB4

Property Documentation

deviceFilter : var

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.


[read-only] error : string

Returns an error message string.


properties : object

A list of properties to control device discovery. This code sample will disable Bluetooth scanning for devices.

DeviceDiscoveryAgent {
    id: discoveryAgent

    properties: {
        "isScanBluetoothDevices" : false
    }
}

refreshInterval : int

The time, in milliseconds, that must elapse before a new scan for devices is run. Default is 1000.


[read-only] running : bool

Returns true if device discovery is currently running.


sortCompare : var

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.


discoverDevicesCompleted()

Signal emitted when device discovery has completed.

Note: The corresponding handler is onDiscoverDevicesCompleted.


Method Documentation

object propertyValue(string key)

The key parameter

See also setPropertyValue().


setPropertyValue(string key, object value)

The key parameter

The value parameter

See also propertyValue().


start()

Starts device discovery, for each time the amount of time defined by the refreshInterval property elapses, until stopDiscoverDevices is called.


stop()

Stops device discovery.


Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.