public void FromByte_Value_PayloadHasValue() { byte value = 23; var message = HarpCommand.WriteByte(DefaultAddress, value); AssertIsValid(message); Assert.AreEqual(value, message.GetPayloadByte()); }
public void FromByte_Array_PayloadHasValue() { var value = new byte[] { 23, 17 }; var message = HarpCommand.WriteByte(DefaultAddress, value); AssertIsValid(message); var payload = message.GetPayloadArray <byte>(); AssertArrayEqual(value, payload); Assert.AreEqual(value[1], message.GetPayloadByte(1)); }
public IObservable <HarpMessage> Generate(IObservable <HarpMessage> source) { return(Observable.Defer(() => { var stopModes = AcquisitionModes.StopPhotometry | AcquisitionModes.StopExternalCamera; var start = Observable.Return(HarpCommand.WriteByte(Registers.Start, (byte)AcquisitionMode)).Publish(); var stop = Observable.Return(HarpCommand.WriteByte(Registers.Start, (byte)(stopModes))).Publish(); var triggerControl = Observable.Concat(start, stop); var messages = board.Generate(source.Merge(triggerControl)); var frames = capture.Generate(start.RefCount()); return messages.Publish(ps => ps.Merge(ps.Do(message => { switch (message.Address) { case Registers.TriggerPeriod: capture.TriggerPeriod = message.GetPayloadUInt16(); break; case Registers.TriggerTimeUpdateOutputs: const int ExposureSafetyMargin = 1000; var dwellTime = message.GetPayloadUInt16(); capture.ExposureTime = dwellTime - ExposureSafetyMargin / 2; break; case Registers.TriggerLaserOn: var triggerLaserOn = message.GetPayloadUInt16(); capture.ExposureTime = Math.Min(capture.ExposureTime, triggerLaserOn - ExposureSafetyMargin / 2); break; case Registers.CameraSerialNumber: if (message.PayloadType != PayloadType.TimestampedU64) { break; } var serialNumber = message.GetPayloadUInt64(); if (serialNumber > 0) { capture.SerialNumber = serialNumber.ToString(); } break; default: break; } }).Where(Registers.TriggerLaserOff).FirstAsync().SelectMany(message => { return photometry.Process(frames).FillMissing(NullFrame).Zip( ps.Event(Registers.FrameEvent).FillMissing(NullTrigger), (f, m) => new PhotometryHarpMessage(f, m)) .Where(m => m.PhotometryData != NullFrame && m.TriggerData != NullTrigger) .Finally(() => stop.Connect()); }))); })); }
private IEnumerable <HarpMessage> SetTriggerMode(FrameFlags[] pattern, int triggerPeriod, int dwellTime) { var triggerState = TriggerHelper.FromFrameFlags(pattern); yield return(HarpCommand.WriteByte(ConfigurationRegisters.TriggerState, triggerState)); yield return(HarpCommand.WriteByte(ConfigurationRegisters.TriggerStateLength, (byte)pattern.Length)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerPeriod, (ushort)triggerPeriod)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerTimeUpdateOutputs, (ushort)dwellTime)); }
IEnumerable <HarpMessage> WriteRegisters(bool savePersistent) { var triggerState = configuration.TriggerState; yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.Config, (ushort)configuration.Config)); yield return(HarpCommand.WriteByte(ConfigurationRegisters.ScreenBrightness, (byte)configuration.ScreenBrightness)); yield return(HarpCommand.WriteByte(ConfigurationRegisters.TriggerState, TriggerHelper.FromFrameFlags(triggerState))); yield return(HarpCommand.WriteByte(ConfigurationRegisters.TriggerStateLength, (byte)triggerState.Length)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerPeriod, (ushort)configuration.TriggerPeriod)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerTimeUpdateOutputs, (ushort)configuration.DwellTime)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerLaserOn, (ushort)configuration.TriggerLaserOn)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerLaserOff, (ushort)configuration.TriggerLaserOff)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL415, LedPowerConverter.ClampLedPower((ushort)configuration.L415))); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL470, LedPowerConverter.ClampLedPower((ushort)configuration.L470))); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL560, LedPowerConverter.ClampLedPower((ushort)configuration.L560))); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacLaser, (ushort)configuration.LaserAmplitude)); yield return(HarpCommand.WriteByte(ConfigurationRegisters.Out0Conf, (byte)configuration.DigitalOutput0)); yield return(HarpCommand.WriteByte(ConfigurationRegisters.Out1Conf, (byte)configuration.DigitalOutput1)); yield return(HarpCommand.WriteByte(ConfigurationRegisters.In0Conf, (byte)configuration.DigitalInput0)); yield return(HarpCommand.WriteByte(ConfigurationRegisters.In1Conf, (byte)configuration.DigitalInput1)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimPeriod, (ushort)configuration.PulsePeriod)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimOn, (ushort)configuration.PulseWidth)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimReps, (ushort)configuration.PulseCount)); if (savePersistent) { yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimWavelength, 0)); yield return(HarpCommand.Reset(ResetMode.Save)); } }
IEnumerable <HarpMessage> RestoreCalibration() { yield return(HarpCommand.WriteByte(ConfigurationRegisters.StimStart, (byte)CommandMode.Stop)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerPeriod, (ushort)configuration.TriggerPeriod)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerTimeUpdateOutputs, (ushort)configuration.DwellTime)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL415, LedPowerConverter.ClampLedPower((ushort)configuration.L415))); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL470, LedPowerConverter.ClampLedPower((ushort)configuration.L470))); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL560, LedPowerConverter.ClampLedPower((ushort)configuration.L560))); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacLaser, (ushort)configuration.LaserAmplitude)); }
IEnumerable <HarpMessage> StartStimulation() { yield return(HarpCommand.WriteByte(ConfigurationRegisters.StimStart, (byte)CommandMode.Start)); }
IEnumerable <HarpMessage> WritePropertyRegister(string propertyName) { switch (propertyName) { case nameof(configuration.ClockSynchronizer): case nameof(configuration.Output1Routing): yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.Config, (ushort)configuration.Config)); yield return(HarpCommand.WriteByte(ConfigurationRegisters.Out1Conf, (byte)configuration.DigitalOutput1)); break; case nameof(configuration.ScreenBrightness): yield return(HarpCommand.WriteByte(ConfigurationRegisters.ScreenBrightness, (byte)configuration.ScreenBrightness)); break; case nameof(configuration.FrameRate): case nameof(configuration.DwellTime): case nameof(configuration.InterleaveWidth): yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerPeriod, (ushort)configuration.TriggerPeriod)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerTimeUpdateOutputs, (ushort)configuration.DwellTime)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerLaserOn, (ushort)configuration.TriggerLaserOn)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.TriggerLaserOff, (ushort)configuration.TriggerLaserOff)); break; case nameof(configuration.TriggerState): var triggerState = configuration.TriggerState; yield return(HarpCommand.WriteByte(ConfigurationRegisters.TriggerState, TriggerHelper.FromFrameFlags(triggerState))); yield return(HarpCommand.WriteByte(ConfigurationRegisters.TriggerStateLength, (byte)triggerState.Length)); break; case nameof(configuration.L415): yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL415, LedPowerConverter.ClampLedPower((ushort)configuration.L415))); break; case nameof(configuration.L470): yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL470, LedPowerConverter.ClampLedPower((ushort)configuration.L470))); break; case nameof(configuration.L560): yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacL560, LedPowerConverter.ClampLedPower((ushort)configuration.L560))); break; case nameof(configuration.LaserAmplitude): yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacLaser, (ushort)configuration.LaserAmplitude)); break; case nameof(configuration.DigitalOutput0): yield return(HarpCommand.WriteByte(ConfigurationRegisters.Out0Conf, (byte)configuration.DigitalOutput0)); break; case nameof(configuration.DigitalOutput1): yield return(HarpCommand.WriteByte(ConfigurationRegisters.Out1Conf, (byte)configuration.DigitalOutput1)); break; case nameof(configuration.DigitalInput0): yield return(HarpCommand.WriteByte(ConfigurationRegisters.In0Conf, (byte)configuration.DigitalInput0)); break; case nameof(configuration.DigitalInput1): yield return(HarpCommand.WriteByte(ConfigurationRegisters.In1Conf, (byte)configuration.DigitalInput1)); break; case nameof(configuration.LaserWavelength): yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimWavelength, (ushort)configuration.LaserWavelength)); if (configuration.LaserWavelength != LaserWavelength.None) { yield return(HarpCommand.WriteByte(ConfigurationRegisters.ScreenBrightness, (byte)configuration.ScreenBrightness)); } break; case nameof(configuration.PulseFrequency): yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimPeriod, (ushort)configuration.PulsePeriod)); break; case nameof(configuration.PulseWidth): yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimOn, (ushort)configuration.PulseWidth)); yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.DacLaser, (ushort)configuration.LaserAmplitude)); break; case nameof(configuration.PulseCount): yield return(HarpCommand.WriteUInt16(ConfigurationRegisters.StimReps, (ushort)configuration.PulseCount)); break; default: yield break; } }
HarpMessage CreateCommand() { return(HarpCommand.WriteByte(Registers.StimStart, (byte)Command)); }
HarpMessage CreateStartCommand(AcquisitionModes mode) { return(HarpCommand.WriteByte(address: Registers.Start, (byte)mode)); }
HarpMessage CreateCommand(int address, byte mode) { return(HarpCommand.WriteByte(address, (byte)mode)); }
HarpMessage CreateCommand(int address, bool mode) { return(HarpCommand.WriteByte(address, (byte)(mode ? 1 : 0))); }
HarpMessage CreateCommand() { return(HarpCommand.WriteByte(Registers.OutSet + (byte)Command, (byte)Mask)); }