-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from AllenNeuralDynamics/bc/add-zaber-axis-set…
…tings Add operators to directly interface with Axis `Settings`
- Loading branch information
Showing
4 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Reactive.Linq; | ||
using Bonsai; | ||
using Zaber.Motion; | ||
using Zaber.Motion.Ascii; | ||
|
||
namespace AllenNeuralDynamics.Zaber | ||
{ | ||
/// <summary> | ||
/// Represents an operator that sends reads a setting from a given axis.. | ||
/// </summary> | ||
[Description("Gets the value of a setting from an axis.")] | ||
public class GetSetting : Combinator<double> | ||
{ | ||
/// <summary> | ||
/// Gets or sets the COM port or alias of the target <see cref="ZaberDevice"/> | ||
/// </summary> | ||
[TypeConverter(typeof(PortNameConverter))] | ||
[Description("The name of the serial port used to communicate with the manipulator.")] | ||
public string PortName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the device to be controlled. Defaults to 0. | ||
/// </summary> | ||
[Description("The axis index to be actuated.")] | ||
public int? Device { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the axis of the manipulator to be controlled. | ||
/// </summary> | ||
[Description("The axis index to be actuated.")] | ||
public int Axis { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the axis setting to be queried. | ||
/// </summary> | ||
[Description("The setting to get.")] | ||
public string Setting { get; set; } | ||
|
||
|
||
/// <summary> | ||
/// Gets or sets the Units of the transaction. | ||
/// </summary> | ||
[Description("The setting to get.")] | ||
public Units Units { get; set; } = Units.Native; | ||
|
||
/// <summary> | ||
/// Sends a request to get a specific setting for an axis. | ||
/// </summary> | ||
/// <returns> | ||
/// On each event, it will emit the response of the device. | ||
/// </returns> | ||
public override IObservable<double> Process<T>(IObservable<T> source) | ||
{ | ||
return Observable.Using( | ||
async token => await ZaberDeviceManager.ReserveConnectionAsync(PortName), | ||
async (connection, cancellationToken) => source.Select(_ => | ||
Check warning on line 58 in src/AllenNeuralDynamics.Zaber/GetSetting.cs GitHub Actions / build
|
||
Observable.FromAsync( async token => | ||
await connection.Device.GetSetting(Device, Axis, Setting, Units) | ||
)).Concat()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Reactive.Linq; | ||
using System.Threading.Tasks; | ||
using Bonsai; | ||
using Zaber.Motion; | ||
|
||
|
||
namespace AllenNeuralDynamics.Zaber | ||
{ | ||
/// <summary> | ||
/// Represents an operator that sets a setting for a specified axis. | ||
/// </summary> | ||
[Description("Sets an axis setting.")] | ||
public class SetSetting : Sink<double> | ||
{ | ||
/// <summary> | ||
/// Gets or sets the COM port or alias of the target <see cref="ZaberDevice"/> | ||
/// </summary> | ||
[TypeConverter(typeof(PortNameConverter))] | ||
[Description("The name of the serial port used to communicate with the manipulator.")] | ||
public string PortName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the device to be controlled. Defaults to 0. | ||
/// </summary> | ||
[Description("The axis index to be actuated.")] | ||
public int? Device { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the axis of the manipulator to be controlled. | ||
/// </summary> | ||
[Description("The axis index to be actuated.")] | ||
public int Axis { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the axis setting to be set. | ||
/// </summary> | ||
[Description("The setting to get.")] | ||
public string Setting { get; set; } | ||
|
||
|
||
/// <summary> | ||
/// Gets or sets the Units of the transaction. | ||
/// </summary> | ||
[Description("The setting to get.")] | ||
public Units Units { get; set; } = Units.Native; | ||
|
||
/// <summary> | ||
/// Moves to the target absolute position when a valid value is received. | ||
/// </summary> | ||
/// <returns> | ||
/// Returns the original input sequence. | ||
/// </returns> | ||
public override IObservable<double> Process(IObservable<double> source) | ||
{ | ||
return Observable.Using( | ||
cancellationToken => ZaberDeviceManager.ReserveConnectionAsync(PortName), | ||
(connection, cancellationToken) => | ||
{ | ||
return Task.FromResult(source.Do(value => | ||
{ | ||
lock (connection.Device) | ||
{ | ||
connection.Device.SetSetting( | ||
Device, | ||
Axis, | ||
Setting, | ||
value, | ||
Units | ||
); | ||
} | ||
})); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters