public static Dictionary<AnalogChannel, SmartScope.GainCalibration> ChannelSettings(this SmartScopeHeader h, SmartScope.Rom r) { Dictionary<AnalogChannel, SmartScope.GainCalibration> settings = new Dictionary<AnalogChannel, SmartScope.GainCalibration>(); foreach (AnalogChannel ch in AnalogChannel.List) { //Parse div_mul byte divMul = h.GetRegister(REG.DIVIDER_MULTIPLIER); int chOffset = ch.Value * 4; double div = SmartScope.validDividers[(divMul >> (0 + chOffset)) & 0x3]; double mul = SmartScope.validMultipliers[(divMul >> (2 + chOffset)) & 0x3]; settings.Add(ch, r.getCalibration(ch, div, mul)); } return settings; }
//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); AnalogTrigger = new AnalogTriggerValue() { channel = AnalogChannel.List.First(x => x.Value == ((GetRegister(REG.TRIGGER_MODE) >> 2) & 0x03)), direction = (TriggerDirection)((GetRegister(REG.TRIGGER_MODE) >> 4) & 0x03), }; 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)); ViewportOffset = SamplePeriod * ( GetRegister(REG.VIEW_OFFSET_B0) + (GetRegister(REG.VIEW_OFFSET_B1) << 8) + (GetRegister(REG.VIEW_OFFSET_B2) << 16) ); 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(TriggerMode, GetRegister(REG.TRIGGER_WIDTH), GetRegister(REG.INPUT_DECIMATION)); TriggerHoldoff = holdoffSamples * (SmartScope.BASE_SAMPLE_PERIOD * Math.Pow(2, GetRegister(REG.INPUT_DECIMATION))); }
private void OnDeviceConnect(ISmartScopeUsbInterface hardwareInterface, bool connected) { if (connected) { if (device == null) { device = new SmartScope(hardwareInterface); if (connectHandler != null) { connectHandler(fallbackDevice, false); } #if WINDOWS lastSmartScopeDetectedThroughWinUsb = DateTime.Now; Logger.Debug(String.Format("Update winusb detection time to {0}", lastSmartScopeDetectedThroughWinUsb)); #endif if (connectHandler != null) { connectHandler(device, true); } } else if (device is SmartScope) { if (connectHandler != null) { connectHandler(device, false); } SmartScope master = device as SmartScope; ISmartScopeUsbInterface masterInterface = master.hardwareInterface; master.Dispose(); //Instantiate 4 channel smartscope Logger.Debug("Turning scope into 4 channel scope"); device = new SmartScope4Channel(masterInterface, hardwareInterface); if (connectHandler != null) { connectHandler(device, true); } } } else { if (device is SmartScope) { Logger.Debug("DeviceManager: Calling connect handler"); if (connectHandler != null) { connectHandler(device, false); } Logger.Debug("DeviceManager: disposing device"); (device as SmartScope).Dispose(); device = null; #if WINDOWS lastSmartScopeDetectedThroughWinUsb = null; #endif Logger.Debug("DeviceManager: calling connect for fallback device"); if (connectHandler != null) { connectHandler(fallbackDevice, true); } } if (device is SmartScope4Channel) { Logger.Debug("Reducing 4 channel scope to regular smartscope"); SmartScope4Channel ss4chan = (device as SmartScope4Channel); ISmartScopeUsbInterface interfaceLeft = ss4chan.smartScopes. Select(x => x.Value.hardwareInterface). Where(x => x != hardwareInterface).First(); ss4chan.Dispose(); device = new SmartScope(interfaceLeft); if (connectHandler != null) { connectHandler(device, true); } } } }