Skip to main content

Scan Device Example

In this example the user can trigger a scan of all available Skinetic devices and display the result of the scan. He can then select one of the devices and connect to it. Play and stop buttons enable to trigger an effect in order to test the connection.

img - Basic Effects

Basic Effects

The HapticEffects gameobject contains only a basic predetermined effect as to test the connection. The effect is handled and triggers with buttons just like in the previous example. The only difference is that the PatternAsset is not in the Preload list of the SkineticDevice component and is registered through scripting in the SkiEx_BasicSingleEffect script that handles the effect and the triggers.

Scanning Procedure

The Scanning (and connection) procedure is done in the SkiEx_DeviceScan script. The scan is triggered by pressing on the button Scan which triggers the ScanDevices coroutine.

  • This coroutine first disconnects any device that might still be connected, as the scan can only be done if no device is connected. Since no callback was set in this example, the connection state is monitored by calling ConnectionStatus every 0.2s until the state E_DISCONNECTED is obtained. The connected device's serial number is display using the provided string format by calling Skinetic.SkineticDevice.SerialNumberToString.
  • Then the scanning procedure is triggered to find Skinetic devices using any kind of output type. Then every 0.2s the scanning procedure status is checked with ScanStatus until it returns 0 for a successful scan.
  • Finally, the result is obtained with GetScannedDevices, the dropdown menu is updated with the available devices and the first one in the list is displayed.

Displaying Device Info

The Scanning procedure returns a list of Skinetic.SkineticDevice.DeviceInfo. A dropdown menu allows the user to select one of the devices. By doing so, the device information is displayed in a text field: OutputType, Serial Number, Device Type, Device Version.

Connection Procedure

As the user select a device from the scanned device list, he can connect to it by clicking on the Connect button which triggers the connection routine:

  • This coroutine first calls Connect by passing as argument the output type and the serial number of the selected device in the scan list.
  • As there is no connection callback set, the connection state is monitored by calling ConnectionStatus every 0.2s until the state E_CONNECTED or E_DISCONNECTED is obtained.