public TriggerValue(TriggerValue t) : this() { mode = t.mode; source = t.source; channel = t.channel; Digital = new Dictionary <DigitalChannel, DigitalTriggerValue>(t.Digital); edge = t.edge; level = t.level; pulseWidthMax = t.pulseWidthMax; pulseWidthMin = t.pulseWidthMin; }
public static TriggerValue TriggerValue(this SmartScopeHeader hdr, Dictionary <AnalogChannel, SmartScope.GainCalibration> channelConfig) { byte modeByte = hdr.GetRegister(REG.TRIGGER_MODE); TriggerValue tv = new TriggerValue() { mode = (TriggerMode)(modeByte & 0x03), channel = AnalogChannel.List.Single(x => x.Value == ((modeByte >> 2) & 0x01)), source = (TriggerSource)((modeByte >> 3) & 0x01), edge = (TriggerEdge)((modeByte >> 4) & 0x03), }; tv.pulseWidthMin = ( (hdr.GetRegister(REG.TRIGGER_PW_MIN_B0) << 0) & (hdr.GetRegister(REG.TRIGGER_PW_MIN_B1) << 8) & (hdr.GetRegister(REG.TRIGGER_PW_MIN_B2) << 16) ) * SmartScope.BASE_SAMPLE_PERIOD; tv.pulseWidthMax = ( (hdr.GetRegister(REG.TRIGGER_PW_MAX_B0) << 0) & (hdr.GetRegister(REG.TRIGGER_PW_MAX_B1) << 8) & (hdr.GetRegister(REG.TRIGGER_PW_MAX_B2) << 16) ) * SmartScope.BASE_SAMPLE_PERIOD; tv.level = hdr.GetRegister(REG.TRIGGER_LEVEL).ConvertByteToVoltage(channelConfig[tv.channel], hdr.GetRegister(tv.channel.YOffsetRegister()), tv.channel); return(tv); }
private static bool DoTriggerAnalog(float [] wave, TriggerValue trigger, int holdoff, float threshold, uint width, uint outputWaveLength, out int triggerIndex) { //Hold off: // - if positive, start looking for trigger at that index, so we are sure to have that many samples before the trigger // - if negative, start looking at index 0 triggerIndex = 0; uint halfWidth = width / 2; uint preconditionCounterRising = 0; uint preconditionCounterFalling = 0; uint postconditionCounterRising = 0; uint postconditionCounterFalling = 0; for (int i = Math.Max(0, holdoff); i < wave.Length - width - outputWaveLength; i++) { bool preconditionRisingMet = preconditionCounterRising == halfWidth; bool preconditionFallingMet = preconditionCounterFalling == halfWidth; if (preconditionRisingMet) { if (wave[i] >= trigger.level + threshold) { postconditionCounterRising++; } } else { postconditionCounterRising = 0; } if (preconditionFallingMet) { if (wave[i] <= trigger.level - threshold) { postconditionCounterFalling++; } } else { postconditionCounterFalling = 0; } if (wave[i] < trigger.level && !preconditionRisingMet) { preconditionCounterRising++; } if (wave[i] > trigger.level && !preconditionFallingMet) { preconditionCounterFalling++; } if ( (preconditionRisingMet && postconditionCounterRising == halfWidth && trigger.edge != TriggerEdge.FALLING) || (preconditionFallingMet && postconditionCounterFalling == halfWidth && trigger.edge != TriggerEdge.RISING) ) { int triggerIndexTmp = (int)(i - width / 2); if (triggerIndexTmp - holdoff + outputWaveLength <= wave.Length) { triggerIndex = triggerIndexTmp; return(true); } } } return(false); }
//FIXME: we really shouldn't be needing the freqcomp mode in here internal SmartScopeHeader(byte[] data) { int headerSize = SmartScope.AcquisitionRegisters.Length + SmartScope.DumpRegisters.Length + (int)Math.Ceiling(SmartScope.AcquisitionStrobes.Length / 8.0); raw = new byte[headerSize]; if (data[0] != 'L' || data[1] != 'N') { throw new Exception("Invalid magic number, can't parse header"); } int headerOffset = data[2]; Array.Copy(data, headerOffset, raw, 0, headerSize); BytesPerBurst = data[3]; NumberOfPayloadBursts = data[4] + (data[5] << 8); PackageOffset = (short)(data[6] + (data[7] << 8)); ViewportLength = (int)(BytesPerBurst / Channels) << GetRegister(REG.VIEW_BURSTS); AcquisitionDepth = (uint)(2048 << GetRegister(REG.ACQUISITION_DEPTH)); Samples = NumberOfPayloadBursts * BytesPerBurst / Channels; Acquiring = Utils.IsBitSet(data[10], 0); OverviewBuffer = Utils.IsBitSet(data[10], 1); LastAcquisition = Utils.IsBitSet(data[10], 2); Rolling = Utils.IsBitSet(data[10], 3); TimedOut = Utils.IsBitSet(data[10], 4); AwaitingTrigger = Utils.IsBitSet(data[10], 5); Armed = Utils.IsBitSet(data[10], 6); FullAcquisitionDump = Utils.IsBitSet(data[10], 7); byte modeByte = GetRegister(REG.TRIGGER_MODE); TriggerValue = new TriggerValue() { mode = (TriggerMode)(modeByte & 0x03), channel = AnalogChannel.List.Single(x => x.Value == ((modeByte >> 2) & 0x01)), source = (TriggerSource)((modeByte >> 3) & 0x01), edge = (TriggerEdge)((modeByte >> 4) & 0x03), }; TriggerValue.pulseWidthMin = ( (GetRegister(REG.TRIGGER_PW_MIN_B0) << 0) & (GetRegister(REG.TRIGGER_PW_MIN_B1) << 8) & (GetRegister(REG.TRIGGER_PW_MIN_B2) << 16) ) * SmartScope.BASE_SAMPLE_PERIOD; TriggerValue.pulseWidthMax = ( (GetRegister(REG.TRIGGER_PW_MAX_B0) << 0) & (GetRegister(REG.TRIGGER_PW_MAX_B1) << 8) & (GetRegister(REG.TRIGGER_PW_MAX_B2) << 16) ) * SmartScope.BASE_SAMPLE_PERIOD; ChannelSacrificedForLogicAnalyser = GetStrobe(STR.LA_CHANNEL) ? AnalogChannel.ChB : AnalogChannel.ChA; LogicAnalyserEnabled = GetStrobe(STR.LA_ENABLE); AcquisitionId = data[11]; SamplePeriod = SmartScope.BASE_SAMPLE_PERIOD * Math.Pow(2, GetRegister(REG.INPUT_DECIMATION)); ViewportSamplePeriod = SmartScope.BASE_SAMPLE_PERIOD * Math.Pow(2, GetRegister(REG.INPUT_DECIMATION) + GetRegister(REG.VIEW_DECIMATION)); ViewportOffsetSamples = GetRegister(REG.VIEW_OFFSET_B0) + (GetRegister(REG.VIEW_OFFSET_B1) << 8) + (GetRegister(REG.VIEW_OFFSET_B2) << 16); ViewportOffset = SamplePeriod * ViewportOffsetSamples; int viewportExcessiveSamples = GetRegister(REG.VIEW_EXCESS_B0) + (GetRegister(REG.VIEW_EXCESS_B1) << 8); ViewportExcess = viewportExcessiveSamples * SamplePeriod; Int64 holdoffSamples = GetRegister(REG.TRIGGERHOLDOFF_B0) + (GetRegister(REG.TRIGGERHOLDOFF_B1) << 8) + (GetRegister(REG.TRIGGERHOLDOFF_B2) << 16) + (GetRegister(REG.TRIGGERHOLDOFF_B3) << 24) - SmartScope.TriggerDelay(TriggerValue.mode, GetRegister(REG.INPUT_DECIMATION)); TriggerHoldoffSamples = holdoffSamples; TriggerHoldoff = holdoffSamples * (SmartScope.BASE_SAMPLE_PERIOD * Math.Pow(2, GetRegister(REG.INPUT_DECIMATION))); }