Skip to content

Commit 8fdcc66

Browse files
glopesdevbanchan86
andauthored
Update device interface with DeviceDataWriter and fix register name (#37)
* Update interface with DeviceDataWriter The new standard interface generators include a DeviceDataWriter which makes it easier to log all device data using a single operator. * Fix register naming typo These registers are rarely used but better to correct this typo in preparation for unified releases. * Fix units for QuickMovement registers --------- Co-authored-by: Shawn Tan <banchan@gmail.com>
1 parent e363c33 commit 8fdcc66

4 files changed

Lines changed: 409 additions & 256 deletions

File tree

Generators/Generators.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<FirmwarePath>..\Firmware\Harp.StepperDriver</FirmwarePath>
1616
</PropertyGroup>
1717
<ItemGroup>
18-
<PackageReference Include="Harp.Generators" Version="0.3.0" GeneratePathProperty="true" />
18+
<PackageReference Include="Harp.Generators" Version="0.4.0" GeneratePathProperty="true" />
1919
</ItemGroup>
2020
<Target Name="TextTransform" BeforeTargets="AfterBuild">
2121
<PropertyGroup>

Interface/Harp.StepperDriver/AsyncDevice.Generated.cs

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ public partial class Device
1414
/// <param name="portName">
1515
/// The name of the serial port used to communicate with the Harp device.
1616
/// </param>
17+
/// <param name="cancellationToken">
18+
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
19+
/// </param>
1720
/// <returns>
1821
/// A task that represents the asynchronous initialization operation. The value of
1922
/// the <see cref="Task{TResult}.Result"/> parameter contains a new instance of
2023
/// the <see cref="AsyncDevice"/> class.
2124
/// </returns>
22-
public static async Task<AsyncDevice> CreateAsync(string portName)
25+
public static async Task<AsyncDevice> CreateAsync(string portName, CancellationToken cancellationToken = default)
2326
{
2427
var device = new AsyncDevice(portName);
25-
var whoAmI = await device.ReadWhoAmIAsync();
28+
var whoAmI = await device.ReadWhoAmIAsync(cancellationToken);
2629
if (whoAmI != Device.WhoAmI)
2730
{
2831
var errorMessage = string.Format(
@@ -2690,7 +2693,7 @@ public async Task WriteAccumulatedStepsAsync(AccumulatedStepsPayload value, Canc
26902693
}
26912694

26922695
/// <summary>
2693-
/// Asynchronously reads the contents of the Mortor0AccumulatedSteps register.
2696+
/// Asynchronously reads the contents of the Motor0AccumulatedSteps register.
26942697
/// </summary>
26952698
/// <param name="cancellationToken">
26962699
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
@@ -2699,14 +2702,14 @@ public async Task WriteAccumulatedStepsAsync(AccumulatedStepsPayload value, Canc
26992702
/// A task that represents the asynchronous read operation. The <see cref="Task{TResult}.Result"/>
27002703
/// property contains the register payload.
27012704
/// </returns>
2702-
public async Task<int> ReadMortor0AccumulatedStepsAsync(CancellationToken cancellationToken = default)
2705+
public async Task<int> ReadMotor0AccumulatedStepsAsync(CancellationToken cancellationToken = default)
27032706
{
2704-
var reply = await CommandAsync(HarpCommand.ReadInt32(Mortor0AccumulatedSteps.Address), cancellationToken);
2705-
return Mortor0AccumulatedSteps.GetPayload(reply);
2707+
var reply = await CommandAsync(HarpCommand.ReadInt32(Motor0AccumulatedSteps.Address), cancellationToken);
2708+
return Motor0AccumulatedSteps.GetPayload(reply);
27062709
}
27072710

27082711
/// <summary>
2709-
/// Asynchronously reads the timestamped contents of the Mortor0AccumulatedSteps register.
2712+
/// Asynchronously reads the timestamped contents of the Motor0AccumulatedSteps register.
27102713
/// </summary>
27112714
/// <param name="cancellationToken">
27122715
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
@@ -2715,28 +2718,28 @@ public async Task<int> ReadMortor0AccumulatedStepsAsync(CancellationToken cancel
27152718
/// A task that represents the asynchronous read operation. The <see cref="Task{TResult}.Result"/>
27162719
/// property contains the timestamped register payload.
27172720
/// </returns>
2718-
public async Task<Timestamped<int>> ReadTimestampedMortor0AccumulatedStepsAsync(CancellationToken cancellationToken = default)
2721+
public async Task<Timestamped<int>> ReadTimestampedMotor0AccumulatedStepsAsync(CancellationToken cancellationToken = default)
27192722
{
2720-
var reply = await CommandAsync(HarpCommand.ReadInt32(Mortor0AccumulatedSteps.Address), cancellationToken);
2721-
return Mortor0AccumulatedSteps.GetTimestampedPayload(reply);
2723+
var reply = await CommandAsync(HarpCommand.ReadInt32(Motor0AccumulatedSteps.Address), cancellationToken);
2724+
return Motor0AccumulatedSteps.GetTimestampedPayload(reply);
27222725
}
27232726

27242727
/// <summary>
2725-
/// Asynchronously writes a value to the Mortor0AccumulatedSteps register.
2728+
/// Asynchronously writes a value to the Motor0AccumulatedSteps register.
27262729
/// </summary>
27272730
/// <param name="value">The value to be stored in the register.</param>
27282731
/// <param name="cancellationToken">
27292732
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
27302733
/// </param>
27312734
/// <returns>The task object representing the asynchronous write operation.</returns>
2732-
public async Task WriteMortor0AccumulatedStepsAsync(int value, CancellationToken cancellationToken = default)
2735+
public async Task WriteMotor0AccumulatedStepsAsync(int value, CancellationToken cancellationToken = default)
27332736
{
2734-
var request = Mortor0AccumulatedSteps.FromPayload(MessageType.Write, value);
2737+
var request = Motor0AccumulatedSteps.FromPayload(MessageType.Write, value);
27352738
await CommandAsync(request, cancellationToken);
27362739
}
27372740

27382741
/// <summary>
2739-
/// Asynchronously reads the contents of the Mortor1AccumulatedSteps register.
2742+
/// Asynchronously reads the contents of the Motor1AccumulatedSteps register.
27402743
/// </summary>
27412744
/// <param name="cancellationToken">
27422745
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
@@ -2745,14 +2748,14 @@ public async Task WriteMortor0AccumulatedStepsAsync(int value, CancellationToken
27452748
/// A task that represents the asynchronous read operation. The <see cref="Task{TResult}.Result"/>
27462749
/// property contains the register payload.
27472750
/// </returns>
2748-
public async Task<int> ReadMortor1AccumulatedStepsAsync(CancellationToken cancellationToken = default)
2751+
public async Task<int> ReadMotor1AccumulatedStepsAsync(CancellationToken cancellationToken = default)
27492752
{
2750-
var reply = await CommandAsync(HarpCommand.ReadInt32(Mortor1AccumulatedSteps.Address), cancellationToken);
2751-
return Mortor1AccumulatedSteps.GetPayload(reply);
2753+
var reply = await CommandAsync(HarpCommand.ReadInt32(Motor1AccumulatedSteps.Address), cancellationToken);
2754+
return Motor1AccumulatedSteps.GetPayload(reply);
27522755
}
27532756

27542757
/// <summary>
2755-
/// Asynchronously reads the timestamped contents of the Mortor1AccumulatedSteps register.
2758+
/// Asynchronously reads the timestamped contents of the Motor1AccumulatedSteps register.
27562759
/// </summary>
27572760
/// <param name="cancellationToken">
27582761
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
@@ -2761,28 +2764,28 @@ public async Task<int> ReadMortor1AccumulatedStepsAsync(CancellationToken cancel
27612764
/// A task that represents the asynchronous read operation. The <see cref="Task{TResult}.Result"/>
27622765
/// property contains the timestamped register payload.
27632766
/// </returns>
2764-
public async Task<Timestamped<int>> ReadTimestampedMortor1AccumulatedStepsAsync(CancellationToken cancellationToken = default)
2767+
public async Task<Timestamped<int>> ReadTimestampedMotor1AccumulatedStepsAsync(CancellationToken cancellationToken = default)
27652768
{
2766-
var reply = await CommandAsync(HarpCommand.ReadInt32(Mortor1AccumulatedSteps.Address), cancellationToken);
2767-
return Mortor1AccumulatedSteps.GetTimestampedPayload(reply);
2769+
var reply = await CommandAsync(HarpCommand.ReadInt32(Motor1AccumulatedSteps.Address), cancellationToken);
2770+
return Motor1AccumulatedSteps.GetTimestampedPayload(reply);
27682771
}
27692772

27702773
/// <summary>
2771-
/// Asynchronously writes a value to the Mortor1AccumulatedSteps register.
2774+
/// Asynchronously writes a value to the Motor1AccumulatedSteps register.
27722775
/// </summary>
27732776
/// <param name="value">The value to be stored in the register.</param>
27742777
/// <param name="cancellationToken">
27752778
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
27762779
/// </param>
27772780
/// <returns>The task object representing the asynchronous write operation.</returns>
2778-
public async Task WriteMortor1AccumulatedStepsAsync(int value, CancellationToken cancellationToken = default)
2781+
public async Task WriteMotor1AccumulatedStepsAsync(int value, CancellationToken cancellationToken = default)
27792782
{
2780-
var request = Mortor1AccumulatedSteps.FromPayload(MessageType.Write, value);
2783+
var request = Motor1AccumulatedSteps.FromPayload(MessageType.Write, value);
27812784
await CommandAsync(request, cancellationToken);
27822785
}
27832786

27842787
/// <summary>
2785-
/// Asynchronously reads the contents of the Mortor2AccumulatedSteps register.
2788+
/// Asynchronously reads the contents of the Motor2AccumulatedSteps register.
27862789
/// </summary>
27872790
/// <param name="cancellationToken">
27882791
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
@@ -2791,14 +2794,14 @@ public async Task WriteMortor1AccumulatedStepsAsync(int value, CancellationToken
27912794
/// A task that represents the asynchronous read operation. The <see cref="Task{TResult}.Result"/>
27922795
/// property contains the register payload.
27932796
/// </returns>
2794-
public async Task<int> ReadMortor2AccumulatedStepsAsync(CancellationToken cancellationToken = default)
2797+
public async Task<int> ReadMotor2AccumulatedStepsAsync(CancellationToken cancellationToken = default)
27952798
{
2796-
var reply = await CommandAsync(HarpCommand.ReadInt32(Mortor2AccumulatedSteps.Address), cancellationToken);
2797-
return Mortor2AccumulatedSteps.GetPayload(reply);
2799+
var reply = await CommandAsync(HarpCommand.ReadInt32(Motor2AccumulatedSteps.Address), cancellationToken);
2800+
return Motor2AccumulatedSteps.GetPayload(reply);
27982801
}
27992802

28002803
/// <summary>
2801-
/// Asynchronously reads the timestamped contents of the Mortor2AccumulatedSteps register.
2804+
/// Asynchronously reads the timestamped contents of the Motor2AccumulatedSteps register.
28022805
/// </summary>
28032806
/// <param name="cancellationToken">
28042807
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
@@ -2807,28 +2810,28 @@ public async Task<int> ReadMortor2AccumulatedStepsAsync(CancellationToken cancel
28072810
/// A task that represents the asynchronous read operation. The <see cref="Task{TResult}.Result"/>
28082811
/// property contains the timestamped register payload.
28092812
/// </returns>
2810-
public async Task<Timestamped<int>> ReadTimestampedMortor2AccumulatedStepsAsync(CancellationToken cancellationToken = default)
2813+
public async Task<Timestamped<int>> ReadTimestampedMotor2AccumulatedStepsAsync(CancellationToken cancellationToken = default)
28112814
{
2812-
var reply = await CommandAsync(HarpCommand.ReadInt32(Mortor2AccumulatedSteps.Address), cancellationToken);
2813-
return Mortor2AccumulatedSteps.GetTimestampedPayload(reply);
2815+
var reply = await CommandAsync(HarpCommand.ReadInt32(Motor2AccumulatedSteps.Address), cancellationToken);
2816+
return Motor2AccumulatedSteps.GetTimestampedPayload(reply);
28142817
}
28152818

28162819
/// <summary>
2817-
/// Asynchronously writes a value to the Mortor2AccumulatedSteps register.
2820+
/// Asynchronously writes a value to the Motor2AccumulatedSteps register.
28182821
/// </summary>
28192822
/// <param name="value">The value to be stored in the register.</param>
28202823
/// <param name="cancellationToken">
28212824
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
28222825
/// </param>
28232826
/// <returns>The task object representing the asynchronous write operation.</returns>
2824-
public async Task WriteMortor2AccumulatedStepsAsync(int value, CancellationToken cancellationToken = default)
2827+
public async Task WriteMotor2AccumulatedStepsAsync(int value, CancellationToken cancellationToken = default)
28252828
{
2826-
var request = Mortor2AccumulatedSteps.FromPayload(MessageType.Write, value);
2829+
var request = Motor2AccumulatedSteps.FromPayload(MessageType.Write, value);
28272830
await CommandAsync(request, cancellationToken);
28282831
}
28292832

28302833
/// <summary>
2831-
/// Asynchronously reads the contents of the Mortor3AccumulatedSteps register.
2834+
/// Asynchronously reads the contents of the Motor3AccumulatedSteps register.
28322835
/// </summary>
28332836
/// <param name="cancellationToken">
28342837
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
@@ -2837,14 +2840,14 @@ public async Task WriteMortor2AccumulatedStepsAsync(int value, CancellationToken
28372840
/// A task that represents the asynchronous read operation. The <see cref="Task{TResult}.Result"/>
28382841
/// property contains the register payload.
28392842
/// </returns>
2840-
public async Task<int> ReadMortor3AccumulatedStepsAsync(CancellationToken cancellationToken = default)
2843+
public async Task<int> ReadMotor3AccumulatedStepsAsync(CancellationToken cancellationToken = default)
28412844
{
2842-
var reply = await CommandAsync(HarpCommand.ReadInt32(Mortor3AccumulatedSteps.Address), cancellationToken);
2843-
return Mortor3AccumulatedSteps.GetPayload(reply);
2845+
var reply = await CommandAsync(HarpCommand.ReadInt32(Motor3AccumulatedSteps.Address), cancellationToken);
2846+
return Motor3AccumulatedSteps.GetPayload(reply);
28442847
}
28452848

28462849
/// <summary>
2847-
/// Asynchronously reads the timestamped contents of the Mortor3AccumulatedSteps register.
2850+
/// Asynchronously reads the timestamped contents of the Motor3AccumulatedSteps register.
28482851
/// </summary>
28492852
/// <param name="cancellationToken">
28502853
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
@@ -2853,23 +2856,23 @@ public async Task<int> ReadMortor3AccumulatedStepsAsync(CancellationToken cancel
28532856
/// A task that represents the asynchronous read operation. The <see cref="Task{TResult}.Result"/>
28542857
/// property contains the timestamped register payload.
28552858
/// </returns>
2856-
public async Task<Timestamped<int>> ReadTimestampedMortor3AccumulatedStepsAsync(CancellationToken cancellationToken = default)
2859+
public async Task<Timestamped<int>> ReadTimestampedMotor3AccumulatedStepsAsync(CancellationToken cancellationToken = default)
28572860
{
2858-
var reply = await CommandAsync(HarpCommand.ReadInt32(Mortor3AccumulatedSteps.Address), cancellationToken);
2859-
return Mortor3AccumulatedSteps.GetTimestampedPayload(reply);
2861+
var reply = await CommandAsync(HarpCommand.ReadInt32(Motor3AccumulatedSteps.Address), cancellationToken);
2862+
return Motor3AccumulatedSteps.GetTimestampedPayload(reply);
28602863
}
28612864

28622865
/// <summary>
2863-
/// Asynchronously writes a value to the Mortor3AccumulatedSteps register.
2866+
/// Asynchronously writes a value to the Motor3AccumulatedSteps register.
28642867
/// </summary>
28652868
/// <param name="value">The value to be stored in the register.</param>
28662869
/// <param name="cancellationToken">
28672870
/// A <see cref="CancellationToken"/> which can be used to cancel the operation.
28682871
/// </param>
28692872
/// <returns>The task object representing the asynchronous write operation.</returns>
2870-
public async Task WriteMortor3AccumulatedStepsAsync(int value, CancellationToken cancellationToken = default)
2873+
public async Task WriteMotor3AccumulatedStepsAsync(int value, CancellationToken cancellationToken = default)
28712874
{
2872-
var request = Mortor3AccumulatedSteps.FromPayload(MessageType.Write, value);
2875+
var request = Motor3AccumulatedSteps.FromPayload(MessageType.Write, value);
28732876
await CommandAsync(request, cancellationToken);
28742877
}
28752878

0 commit comments

Comments
 (0)