Table of Contents

Class AsyncDevice

Namespace
Bonsai.Harp
Assembly
Bonsai.Harp.dll

Represents an asynchronous API to configure and interface with Harp devices.

public class AsyncDevice : IDisposable
Inheritance
AsyncDevice
Implements
Derived
Inherited Members

Constructors

AsyncDevice(string)

Initializes a new instance of the AsyncDevice class on the specified port.

public AsyncDevice(string portName)

Parameters

portName string

The name of the serial port used to communicate with the Harp device.

Methods

CommandAsync(HarpMessage, CancellationToken)

Sends a command to the Harp device and awaits the response as an asynchronous operation.

public Task<HarpMessage> CommandAsync(HarpMessage command, CancellationToken cancellationToken = default)

Parameters

command HarpMessage

The HarpMessage specifying the command to send.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<HarpMessage>

The task object representing the asynchronous operation. The Result property contains the message representing the response of the device to the asynchronous command.

Dispose()

Releases all resources used by the current instance of the AsyncDevice.

public void Dispose()

ReadAssemblyVersionAsync(CancellationToken)

Asynchronously reads the assembly version of the device.

public Task<int> ReadAssemblyVersionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<int>

A task that represents the asynchronous read operation. The Result property contains the assembly version of the device.

ReadByteArrayAsync(int, CancellationToken)

Asynchronously reads the value of an 8-bit unsigned integer array register with the specified address.

public Task<byte[]> ReadByteArrayAsync(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<byte[]>

A task that represents the asynchronous read operation. The Result property contains the state of the array register.

ReadByteAsync(int, CancellationToken)

Asynchronously reads the value of an 8-bit unsigned integer register with the specified address.

public Task<byte> ReadByteAsync(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<byte>

A task that represents the asynchronous read operation. The Result property contains the value of the register.

ReadClockConfigurationAsync(CancellationToken)

Asynchronously reads the configuration for the device synchronization clock.

public Task<ClockConfigurationFlags> ReadClockConfigurationAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<ClockConfigurationFlags>

A task that represents the asynchronous read operation. The Result property contains the configuration for the device synchronization clock.

ReadCoreVersionAsync(CancellationToken)

Asynchronously reads the version of the Harp core implemented by the device firmware.

public Task<HarpVersion> ReadCoreVersionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<HarpVersion>

A task that represents the asynchronous read operation. The Result property contains the version of the Harp core implemented by the device firmware.

ReadDeviceNameAsync(CancellationToken)

Asynchronously reads the display name of the device.

public Task<string> ReadDeviceNameAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<string>

A task that represents the asynchronous read operation. The Result property contains the name of the device.

ReadFirmwareVersionAsync(CancellationToken)

Asynchronously reads the firmware version of the device.

public Task<HarpVersion> ReadFirmwareVersionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<HarpVersion>

A task that represents the asynchronous read operation. The Result property contains the firmware version of the device.

ReadHardwareVersionAsync(CancellationToken)

Asynchronously reads the hardware version of the device.

public Task<HarpVersion> ReadHardwareVersionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<HarpVersion>

A task that represents the asynchronous read operation. The Result property contains the hardware version of the device.

ReadInt16ArrayAsync(int, CancellationToken)

Asynchronously reads the value of a 16-bit signed integer array register with the specified address.

public Task<short[]> ReadInt16ArrayAsync(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<short[]>

A task that represents the asynchronous read operation. The Result property contains the state of the array register.

ReadInt16Async(int, CancellationToken)

Asynchronously reads the value of a 16-bit signed integer register with the specified address.

public Task<short> ReadInt16Async(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<short>

A task that represents the asynchronous read operation. The Result property contains the value of the register.

ReadInt32ArrayAsync(int, CancellationToken)

Asynchronously reads the value of a 32-bit signed integer array register with the specified address.

public Task<int[]> ReadInt32ArrayAsync(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<int[]>

A task that represents the asynchronous read operation. The Result property contains the state of the array register.

ReadInt32Async(int, CancellationToken)

Asynchronously reads the value of a 32-bit signed integer register with the specified address.

public Task<int> ReadInt32Async(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<int>

A task that represents the asynchronous read operation. The Result property contains the value of the register.

ReadInt64ArrayAsync(int, CancellationToken)

Asynchronously reads the value of a 64-bit signed integer array register with the specified address.

public Task<long[]> ReadInt64ArrayAsync(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<long[]>

A task that represents the asynchronous read operation. The Result property contains the state of the array register.

ReadInt64Async(int, CancellationToken)

Asynchronously reads the value of a 64-bit signed integer register with the specified address.

public Task<long> ReadInt64Async(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<long>

A task that represents the asynchronous read operation. The Result property contains the value of the register.

ReadOperationControlAsync(CancellationToken)

Asynchronously reads the contents of the OperationControl register.

public Task<OperationControlPayload> ReadOperationControlAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<OperationControlPayload>

A task that represents the asynchronous read operation. The Result property contains the register payload.

ReadResetDeviceAsync(CancellationToken)

Asynchronously reads the contents of the ResetDevice register.

public Task<ResetFlags> ReadResetDeviceAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<ResetFlags>

A task that represents the asynchronous read operation. The Result property contains the register payload.

ReadSByteArrayAsync(int, CancellationToken)

Asynchronously reads the value of an 8-bit signed integer array register with the specified address.

public Task<sbyte[]> ReadSByteArrayAsync(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<sbyte[]>

A task that represents the asynchronous read operation. The Result property contains the state of the array register.

ReadSByteAsync(int, CancellationToken)

Asynchronously reads the value of an 8-bit signed integer register with the specified address.

public Task<sbyte> ReadSByteAsync(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<sbyte>

A task that represents the asynchronous read operation. The Result property contains the value of the register.

ReadSerialNumberAsync(CancellationToken)

Asynchronously reads the unique serial number of the device.

public Task<int> ReadSerialNumberAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<int>

A task that represents the asynchronous read operation. The Result property contains the unique serial number of the device.

ReadSingleArrayAsync(int, CancellationToken)

Asynchronously reads the value of a single-precision floating point array register with the specified address.

public Task<float[]> ReadSingleArrayAsync(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<float[]>

A task that represents the asynchronous read operation. The Result property contains the state of the array register.

ReadSingleAsync(int, CancellationToken)

Asynchronously reads the value of a single-precision floating point register with the specified address.

public Task<float> ReadSingleAsync(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<float>

A task that represents the asynchronous read operation. The Result property contains the value of the register.

ReadTimestampMicrosecondsAsync(CancellationToken)

Asynchronously reads the fractional part of the system timestamp, in microseconds.

public Task<ushort> ReadTimestampMicrosecondsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<ushort>

A task that represents the asynchronous read operation. The Result property contains the fractional part of the system timestamp, in microseconds.

ReadTimestampSecondsAsync(CancellationToken)

Asynchronously reads the integral part of the system timestamp, in seconds.

public Task<uint> ReadTimestampSecondsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<uint>

A task that represents the asynchronous read operation. The Result property contains the integral part of the system timestamp, in seconds.

ReadUInt16ArrayAsync(int, CancellationToken)

Asynchronously reads the value of a 16-bit unsigned integer array register with the specified address.

public Task<ushort[]> ReadUInt16ArrayAsync(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<ushort[]>

A task that represents the asynchronous read operation. The Result property contains the state of the array register.

ReadUInt16Async(int, CancellationToken)

Asynchronously reads the value of a 16-bit unsigned integer register with the specified address.

public Task<ushort> ReadUInt16Async(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<ushort>

A task that represents the asynchronous read operation. The Result property contains the value of the register.

ReadUInt32ArrayAsync(int, CancellationToken)

Asynchronously reads the value of a 32-bit unsigned integer array register with the specified address.

public Task<uint[]> ReadUInt32ArrayAsync(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<uint[]>

A task that represents the asynchronous read operation. The Result property contains the state of the array register.

ReadUInt32Async(int, CancellationToken)

Asynchronously reads the value of a 32-bit unsigned integer register with the specified address.

public Task<uint> ReadUInt32Async(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<uint>

A task that represents the asynchronous read operation. The Result property contains the value of the register.

ReadUInt64ArrayAsync(int, CancellationToken)

Asynchronously reads the value of a 64-bit unsigned integer array register with the specified address.

public Task<ulong[]> ReadUInt64ArrayAsync(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<ulong[]>

A task that represents the asynchronous read operation. The Result property contains the state of the array register.

ReadUInt64Async(int, CancellationToken)

Asynchronously reads the value of a 64-bit unsigned integer register with the specified address.

public Task<ulong> ReadUInt64Async(int address, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to read.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<ulong>

A task that represents the asynchronous read operation. The Result property contains the value of the register.

ReadWhoAmIAsync(CancellationToken)

Asynchronously reads the identity class of the device.

public Task<int> ReadWhoAmIAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task<int>

A task that represents the asynchronous read operation. The Result property contains the identity class of the device.

WriteByteAsync(int, byte, CancellationToken)

Asynchronously writes a value to an 8-bit unsigned integer register with the specified address.

public Task WriteByteAsync(int address, byte value, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

value byte

The value to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteByteAsync(int, byte[], CancellationToken)

Asynchronously writes an array of values to an 8-bit unsigned integer register with the specified address.

public Task WriteByteAsync(int address, byte[] values, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

values byte[]

The values to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteClockConfigurationAsync(ClockConfigurationFlags, CancellationToken)

Asynchronously updates the configuration for the device synchronization clock.

public Task WriteClockConfigurationAsync(ClockConfigurationFlags value, CancellationToken cancellationToken = default)

Parameters

value ClockConfigurationFlags

A value specifying configuration flags for the device synchronization clock.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteDeviceNameAsync(string, CancellationToken)

Asynchronously updates the display name of the device.

public Task WriteDeviceNameAsync(string name, CancellationToken cancellationToken = default)

Parameters

name string

A string containing the name of the device. The maximum length of the specified device name is 25 characters.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteInt16Async(int, short, CancellationToken)

Asynchronously writes a value to a 16-bit signed integer register with the specified address.

public Task WriteInt16Async(int address, short value, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

value short

The value to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteInt16Async(int, short[], CancellationToken)

Asynchronously writes an array of values to a 16-bit signed integer register with the specified address.

public Task WriteInt16Async(int address, short[] values, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

values short[]

The values to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteInt32Async(int, int, CancellationToken)

Asynchronously writes a value to a 32-bit signed integer register with the specified address.

public Task WriteInt32Async(int address, int value, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

value int

The value to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteInt32Async(int, int[], CancellationToken)

Asynchronously writes an array of values to a 32-bit signed integer register with the specified address.

public Task WriteInt32Async(int address, int[] values, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

values int[]

The values to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteInt64Async(int, long, CancellationToken)

Asynchronously writes a value to a 64-bit signed integer register with the specified address.

public Task WriteInt64Async(int address, long value, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

value long

The value to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteInt64Async(int, long[], CancellationToken)

Asynchronously writes an array of values to a 64-bit signed integer register with the specified address.

public Task WriteInt64Async(int address, long[] values, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

values long[]

The values to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteResetDeviceAsync(ResetFlags, CancellationToken)

Asynchronously sends a command to reset the device and restore or save non-volatile registers.

public Task WriteResetDeviceAsync(ResetFlags reset, CancellationToken cancellationToken = default)

Parameters

reset ResetFlags

A value specifying whether to restore or save non-volatile registers.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous reset operation.

WriteSByteAsync(int, sbyte, CancellationToken)

Asynchronously writes a value to an 8-bit signed integer register with the specified address.

public Task WriteSByteAsync(int address, sbyte value, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

value sbyte

The value to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteSByteAsync(int, sbyte[], CancellationToken)

Asynchronously writes an array of values to an 8-bit signed integer register with the specified address.

public Task WriteSByteAsync(int address, sbyte[] values, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

values sbyte[]

The values to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteSingleAsync(int, float, CancellationToken)

Asynchronously writes a value to a single-precision floating point register with the specified address.

public Task WriteSingleAsync(int address, float value, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

value float

The value to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteSingleAsync(int, float[], CancellationToken)

Asynchronously writes an array of values to a single-precision floating point register with the specified address.

public Task WriteSingleAsync(int address, float[] values, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

values float[]

The values to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteTimestampSecondsAsync(uint, CancellationToken)

Asynchronously updates the integral part of the system timestamp, in seconds.

public Task WriteTimestampSecondsAsync(uint seconds, CancellationToken cancellationToken = default)

Parameters

seconds uint

The value to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteUInt16Async(int, ushort, CancellationToken)

Asynchronously writes a value to a 16-bit unsigned integer register with the specified address.

public Task WriteUInt16Async(int address, ushort value, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

value ushort

The value to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteUInt16Async(int, ushort[], CancellationToken)

Asynchronously writes an array of values to a 16-bit unsigned integer register with the specified address.

public Task WriteUInt16Async(int address, ushort[] values, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

values ushort[]

The values to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteUInt32Async(int, uint, CancellationToken)

Asynchronously writes a value to a 32-bit unsigned integer register with the specified address.

public Task WriteUInt32Async(int address, uint value, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

value uint

The value to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteUInt32Async(int, uint[], CancellationToken)

Asynchronously writes an array of values to a 32-bit unsigned integer register with the specified address.

public Task WriteUInt32Async(int address, uint[] values, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

values uint[]

The values to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteUInt64Async(int, ulong, CancellationToken)

Asynchronously writes a value to a 64-bit unsigned integer register with the specified address.

public Task WriteUInt64Async(int address, ulong value, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

value ulong

The value to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.

WriteUInt64Async(int, ulong[], CancellationToken)

Asynchronously writes an array of values to a 64-bit unsigned integer register with the specified address.

public Task WriteUInt64Async(int address, ulong[] values, CancellationToken cancellationToken = default)

Parameters

address int

The address of the register to write.

values ulong[]

The values to be stored in the register.

cancellationToken CancellationToken

A CancellationToken which can be used to cancel the operation.

Returns

Task

The task object representing the asynchronous write operation.