Skip to main content
Version: 2.6

Bluetooth Data Access

Processor Information

The payload processing must be declared in a processor information within the device info file.

{
...
"TaskProcessors": [
{
"Id": "DABEA01B-CDA0-4DCD-9135-0FE1C17A46AE",
"Name": "MainTaskProcessor",
"ScriptFile": "TTestPayload.cs"
}
]
}

The payload script is typically placed in the folder:

$(ConfigPath)\HumanOS.UHAL.BluetoothDeviceDriver

Communication

The Bluetooth device driver connects and communicates in the following way:

Make sure that:

  • The devices are paired
  • The "partner" device is running and listening to incoming requests with the "partner" service UUID
  • HumanOS® Bluetooth device driver uses the same service UUID and knows the name of the "partner" device (which is given through pairing)

Requests

The device driver supports requests for an action. The following requests are taken:

RequestActionFormat
WriteWrites data to another devicedynamic
RequestRequest data from another devicedynamic

The action executed by this request and the format is generic and needs additional scripting.

Scripting

The script file implements the protocol specific reading and writing operations. The complete communication must be implemented here.

The script is placed in the folder:

$(ConfigPath)\HumanOS.UHAL.BluetoothDeviceDriver\

The script object must be derived from TAbstractStreamScriptObject. Following methods can be overwritten:

MethodAction
handleStreamHandles the stream in a cyclic manner. This method MUST be implemented. Arguments: (Kernel: HumanOS® Kernel access; Logger: Logger instance of the driver; DeviceInfo: device info file; DataStream: stream interface to Bluetooth socket)
connectToDeviceThis method is called after successful connection to the device. Place the code for initialization and connection preamble. Arguments: Same as handleStream()
disconnectFromDeviceThis method is called after successful disconnection from the device. Place the code for clean-up. Arguments: Same as handleStream()
onDataReceivedNot supported for Bluetooth devices

Example

/// <summary>
/// Test payload for script
/// </summary>
public class TTestPayload : TAbstractStreamScriptObject
{
///<see cref="TAbstractStreamScriptObject"/>
public override void handleStream(IKernelAccess Kernel,
ILogger Logger,
TDeviceInfo DeviceInfo,
IDataStream DataStream)
{
byte[] aui8Buffer = new byte[4];
DataStream.read(aui8Buffer, 0, 4);

aui8Buffer[0] = 0x11;
aui8Buffer[1] = 0x21;
aui8Buffer[2] = 0x31;
aui8Buffer[3] = 0x41;

DataStream.write(aui8Buffer, 0, 4);
}
}