Skip to content

Commit

Permalink
Merge pull request #217 from open-ephys/issue-156
Browse files Browse the repository at this point in the history
Expose headstage port status data stream
  • Loading branch information
jonnew authored Aug 20, 2024
2 parents 60e22f1 + 54e635b commit 70a29e5
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 68 deletions.
43 changes: 13 additions & 30 deletions OpenEphys.Onix1/ConfigureHeadstage64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace OpenEphys.Onix1
{
/// <summary>
/// A class that configures an ONIX headstage-64 in the specified port.
/// A class that configures an ONIX headstage-64 on the specified port.
/// </summary>
[Description("Configures an ONIX headstage-64 in the specified port.")]
public class ConfigureHeadstage64 : MultiDeviceFactory
{
PortName port;
readonly ConfigureHeadstage64LinkController LinkController = new();
readonly ConfigureHeadstage64PortController PortControl = new();

/// <summary>
/// Initializes a new instance of the <see cref="ConfigureHeadstage64"/> class.
Expand All @@ -35,7 +35,7 @@ public ConfigureHeadstage64()
// The FMC port voltage can only go down to 3.3V, which means that its very hard to find the true lowest voltage
// for a lock and then add a large offset to that. Fixing this requires a hardware change.
Port = PortName.PortA;
LinkController.HubConfiguration = HubConfiguration.Standard;
PortControl.HubConfiguration = HubConfiguration.Standard;
}

/// <summary>
Expand Down Expand Up @@ -92,7 +92,7 @@ public PortName Port
{
port = value;
var offset = (uint)port << 8;
LinkController.DeviceAddress = (uint)port;
PortControl.DeviceAddress = (uint)port;
Rhd2164.DeviceAddress = offset + 0;
Bno055.DeviceAddress = offset + 1;
TS4231.DeviceAddress = offset + 2;
Expand Down Expand Up @@ -122,21 +122,21 @@ public PortName Port
"Supplying higher voltages may result in damage to the headstage.")]
public double? PortVoltage
{
get => LinkController.PortVoltage;
set => LinkController.PortVoltage = value;
get => PortControl.PortVoltage;
set => PortControl.PortVoltage = value;
}

internal override IEnumerable<IDeviceConfiguration> GetDevices()
{
yield return LinkController;
yield return PortControl;
yield return Rhd2164;
yield return Bno055;
yield return TS4231;
yield return ElectricalStimulator;
yield return OpticalStimulator;
}

class ConfigureHeadstage64LinkController : ConfigureFmcLinkController
class ConfigureHeadstage64PortController : ConfigurePortController
{
protected override bool ConfigurePortVoltage(DeviceContext device)
{
Expand All @@ -153,7 +153,7 @@ protected override bool ConfigurePortVoltage(DeviceContext device)
var voltage = MaxVoltage;
for (; voltage >= MinVoltage; voltage -= VoltageIncrement)
{
device.WriteRegister(FmcLinkController.PORTVOLTAGE, voltage);
device.WriteRegister(PortController.PORTVOLTAGE, voltage);
Thread.Sleep(200);
if (!CheckLinkState(device))
{
Expand All @@ -162,32 +162,15 @@ protected override bool ConfigurePortVoltage(DeviceContext device)
}
}

device.WriteRegister(FmcLinkController.PORTVOLTAGE, MinVoltage);
device.WriteRegister(FmcLinkController.PORTVOLTAGE, 0);
device.WriteRegister(PortController.PORTVOLTAGE, MinVoltage);
device.WriteRegister(PortController.PORTVOLTAGE, 0);
Thread.Sleep(1000);
device.WriteRegister(FmcLinkController.PORTVOLTAGE, voltage + VoltageOffset);
device.WriteRegister(PortController.PORTVOLTAGE, voltage + VoltageOffset);
Thread.Sleep(200);
return CheckLinkState(device);
}
}
}

/// <summary>
/// Specifies the physical port that a headstage is plugged into.
/// </summary>
/// <remarks>
/// ONIX uses a common protocol to communicate with a variety of devices using the same physical connection. For this reason
/// lots of different headstage types can be plugged into a headstage port.
/// </remarks>
public enum PortName
{
/// <summary>
/// Specifies Port A.
/// </summary>
PortA = 1,
/// <summary>
/// Specifies Port B.
/// </summary>
PortB = 2
}

}
20 changes: 10 additions & 10 deletions OpenEphys.Onix1/ConfigureNeuropixelsV1eHeadstage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
namespace OpenEphys.Onix1
{
/// <summary>
/// A class that configures a NeuropixelsV1e headstage.
/// A class that configures a NeuropixelsV1e headstage on the specified port.
/// </summary>
[Description("Configures a NeuropixelsV1e headstage.")]
public class ConfigureNeuropixelsV1eHeadstage : MultiDeviceFactory
{
PortName port;
readonly ConfigureNeuropixelsV1eLinkController LinkController = new();
readonly ConfigureNeuropixelsV1ePortController PortControl = new();

/// <summary>
/// Initialize a new instance of a <see cref="ConfigureNeuropixelsV1eHeadstage"/> class.
/// </summary>
public ConfigureNeuropixelsV1eHeadstage()
{
Port = PortName.PortA;
LinkController.HubConfiguration = HubConfiguration.Passthrough;
PortControl.HubConfiguration = HubConfiguration.Passthrough;
}

/// <summary>
Expand Down Expand Up @@ -52,7 +52,7 @@ public PortName Port
{
port = value;
var offset = (uint)port << 8;
LinkController.DeviceAddress = (uint)port;
PortControl.DeviceAddress = (uint)port;
NeuropixelsV1e.DeviceAddress = offset + 0;
Bno055.DeviceAddress = offset + 1;
}
Expand All @@ -72,18 +72,18 @@ public PortName Port
"for proper operation. Higher voltages can damage the headstage.")]
public double? PortVoltage
{
get => LinkController.PortVoltage;
set => LinkController.PortVoltage = value;
get => PortControl.PortVoltage;
set => PortControl.PortVoltage = value;
}

internal override IEnumerable<IDeviceConfiguration> GetDevices()
{
yield return LinkController;
yield return PortControl;
yield return NeuropixelsV1e;
yield return Bno055;
}

class ConfigureNeuropixelsV1eLinkController : ConfigureFmcLinkController
class ConfigureNeuropixelsV1ePortController : ConfigurePortController
{
protected override bool ConfigurePortVoltage(DeviceContext device)
{
Expand All @@ -108,9 +108,9 @@ protected override bool ConfigurePortVoltage(DeviceContext device)

void SetVoltage(DeviceContext device, double voltage)
{
device.WriteRegister(FmcLinkController.PORTVOLTAGE, 0);
device.WriteRegister(PortController.PORTVOLTAGE, 0);
Thread.Sleep(200);
device.WriteRegister(FmcLinkController.PORTVOLTAGE, (uint)(10 * voltage));
device.WriteRegister(PortController.PORTVOLTAGE, (uint)(10 * voltage));
Thread.Sleep(200);
}
}
Expand Down
14 changes: 7 additions & 7 deletions OpenEphys.Onix1/ConfigureNeuropixelsV2eBetaHeadstage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
namespace OpenEphys.Onix1
{
/// <summary>
/// A class that configures a NeuropixelsV2eBeta headstage.
/// A class that configures a NeuropixelsV2eBeta headstage on the specified port.
/// </summary>
[Description("Configures a NeuropixelsV2eBeta headstage.")]
public class ConfigureNeuropixelsV2eBetaHeadstage : MultiDeviceFactory
{
PortName port;
readonly ConfigureNeuropixelsV2eLinkController LinkController = new();
readonly ConfigureNeuropixelsV2ePortController PortControl = new();

/// <summary>
/// Initialize a new instance of a <see cref="ConfigureNeuropixelsV2eBetaHeadstage"/> class.
/// </summary>
public ConfigureNeuropixelsV2eBetaHeadstage()
{
Port = PortName.PortA;
LinkController.HubConfiguration = HubConfiguration.Passthrough;
PortControl.HubConfiguration = HubConfiguration.Passthrough;
}

/// <summary>
Expand Down Expand Up @@ -51,7 +51,7 @@ public PortName Port
{
port = value;
var offset = (uint)port << 8;
LinkController.DeviceAddress = (uint)port;
PortControl.DeviceAddress = (uint)port;
NeuropixelsV2eBeta.DeviceAddress = offset + 0;
Bno055.DeviceAddress = offset + 1;
}
Expand All @@ -71,13 +71,13 @@ public PortName Port
"for proper operation. Higher voltages can damage the headstage.")]
public double? PortVoltage
{
get => LinkController.PortVoltage;
set => LinkController.PortVoltage = value;
get => PortControl.PortVoltage;
set => PortControl.PortVoltage = value;
}

internal override IEnumerable<IDeviceConfiguration> GetDevices()
{
yield return LinkController;
yield return PortControl;
yield return NeuropixelsV2eBeta;
yield return Bno055;
}
Expand Down
14 changes: 7 additions & 7 deletions OpenEphys.Onix1/ConfigureNeuropixelsV2eHeadstage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
namespace OpenEphys.Onix1
{
/// <summary>
/// A class that configures a NeuropixelsV2e headstage.
/// A class that configures a NeuropixelsV2e headstage on the specified port.
/// </summary>
[Editor("OpenEphys.Onix1.Design.NeuropixelsV2eHeadstageEditor, OpenEphys.Onix1.Design", typeof(ComponentEditor))]
[Description("configures a NeuropixelsV2e headstage.")]
public class ConfigureNeuropixelsV2eHeadstage : MultiDeviceFactory
{
PortName port;
readonly ConfigureNeuropixelsV2eLinkController LinkController = new();
readonly ConfigureNeuropixelsV2ePortController PortControl = new();

/// <summary>
/// Initialize a new instance of a <see cref="ConfigureNeuropixelsV2e"/> class.
/// </summary>
public ConfigureNeuropixelsV2eHeadstage()
{
Port = PortName.PortA;
LinkController.HubConfiguration = HubConfiguration.Passthrough;
PortControl.HubConfiguration = HubConfiguration.Passthrough;
}

/// <summary>
Expand Down Expand Up @@ -52,7 +52,7 @@ public PortName Port
{
port = value;
var offset = (uint)port << 8;
LinkController.DeviceAddress = (uint)port;
PortControl.DeviceAddress = (uint)port;
NeuropixelsV2e.DeviceAddress = offset + 0;
Bno055.DeviceAddress = offset + 1;
}
Expand All @@ -72,13 +72,13 @@ public PortName Port
"for proper operation. Higher voltages can damage the headstage.")]
public double? PortVoltage
{
get => LinkController.PortVoltage;
set => LinkController.PortVoltage = value;
get => PortControl.PortVoltage;
set => PortControl.PortVoltage = value;
}

internal override IEnumerable<IDeviceConfiguration> GetDevices()
{
yield return LinkController;
yield return PortControl;
yield return NeuropixelsV2e;
yield return Bno055;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace OpenEphys.Onix1
{
class ConfigureNeuropixelsV2eLinkController : ConfigureFmcLinkController
class ConfigureNeuropixelsV2ePortController : ConfigurePortController
{

protected override bool ConfigurePortVoltage(DeviceContext device)
Expand All @@ -29,9 +29,9 @@ protected override bool ConfigurePortVoltage(DeviceContext device)

void SetVoltage(DeviceContext device, double voltage)
{
device.WriteRegister(FmcLinkController.PORTVOLTAGE, 0);
device.WriteRegister(PortController.PORTVOLTAGE, 0);
Thread.Sleep(200);
device.WriteRegister(FmcLinkController.PORTVOLTAGE, (uint)(10 * voltage));
device.WriteRegister(PortController.PORTVOLTAGE, (uint)(10 * voltage));
Thread.Sleep(200);
}
}
Expand Down
Loading

0 comments on commit 70a29e5

Please sign in to comment.