@@ -14,6 +14,7 @@ var publicRegisters = deviceMetadata.Registers.Where(register => register.Value.
1414var deviceName = deviceMetadata.Device;
1515#>
1616using Bonsai.Harp;
17+ using System.Threading;
1718using System.Threading.Tasks;
1819
1920namespace <#= Namespace #>
@@ -69,26 +70,32 @@ foreach (var registerMetadata in publicRegisters)
6970 /// <summary>
7071 /// Asynchronously reads the contents of the <#= registerMetadata.Key #> register.
7172 /// </summary>
73+ /// <param name="cancellationToken">
74+ /// A <see cref="CancellationToken"/> which can be used to cancel the operation.
75+ /// </param>
7276 /// <returns>
7377 /// A task that represents the asynchronous read operation. The <see cref="Task{TResult}.Result"/>
7478 /// property contains the register payload.
7579 /// </returns>
76- public async Task<<#= interfaceType #>> Read<#= registerMetadata.Key #>Async()
80+ public async Task<<#= interfaceType #>> Read<#= registerMetadata.Key #>Async(CancellationToken cancellationToken = default )
7781 {
78- var reply = await CommandAsync(HarpCommand.Read<#= parsePayloadSuffix #>(<#= registerMetadata.Key #>.Address));
82+ var reply = await CommandAsync(HarpCommand.Read<#= parsePayloadSuffix #>(<#= registerMetadata.Key #>.Address), cancellationToken );
7983 return <#= registerMetadata.Key #>.GetPayload(reply);
8084 }
8185
8286 /// <summary>
8387 /// Asynchronously reads the timestamped contents of the <#= registerMetadata.Key #> register.
8488 /// </summary>
89+ /// <param name="cancellationToken">
90+ /// A <see cref="CancellationToken"/> which can be used to cancel the operation.
91+ /// </param>
8592 /// <returns>
8693 /// A task that represents the asynchronous read operation. The <see cref="Task{TResult}.Result"/>
8794 /// property contains the timestamped register payload.
8895 /// </returns>
89- public async Task<Timestamped<<#= interfaceType #>>> ReadTimestamped<#= registerMetadata.Key #>Async()
96+ public async Task<Timestamped<<#= interfaceType #>>> ReadTimestamped<#= registerMetadata.Key #>Async(CancellationToken cancellationToken = default )
9097 {
91- var reply = await CommandAsync(HarpCommand.Read<#= parsePayloadSuffix #>(<#= registerMetadata.Key #>.Address));
98+ var reply = await CommandAsync(HarpCommand.Read<#= parsePayloadSuffix #>(<#= registerMetadata.Key #>.Address), cancellationToken );
9299 return <#= registerMetadata.Key #>.GetTimestampedPayload(reply);
93100 }
94101<#
@@ -100,11 +107,14 @@ foreach (var registerMetadata in publicRegisters)
100107 /// Asynchronously writes a value to the <#= registerMetadata.Key #> register.
101108 /// </summary>
102109 /// <param name="value">The value to be stored in the register.</param>
110+ /// <param name="cancellationToken">
111+ /// A <see cref="CancellationToken"/> which can be used to cancel the operation.
112+ /// </param>
103113 /// <returns>The task object representing the asynchronous write operation.</returns>
104- public async Task Write<#= registerMetadata.Key #>Async(<#= interfaceType #> value)
114+ public async Task Write<#= registerMetadata.Key #>Async(<#= interfaceType #> value, CancellationToken cancellationToken = default )
105115 {
106116 var request = <#= registerMetadata.Key #>.FromPayload(MessageType.Write, value);
107- await CommandAsync(request);
117+ await CommandAsync(request, cancellationToken );
108118 }
109119<#
110120 }
0 commit comments