public static void Main() { // Print library information: PrintInfo.PrintLibraryInfo(); // Enable network search: Network.AutoDetectEnabled = true; // Update device list: DeviceList.Update(); // Try to open an oscilloscope with block measurement support: Oscilloscope scp = null; for (UInt32 i = 0; i < DeviceList.Count; i++) { DeviceListItem item = DeviceList.GetItemByIndex(i); if (item.CanOpen(DeviceType.Oscilloscope)) { scp = item.OpenOscilloscope(); // Check for block measurement support: if ((scp.MeasureModes & Constants.MM_BLOCK) != 0) { break; } else { scp.Dispose(); scp = null; } } } if (scp != null) { try { // Get the number of channels: UInt16 channelCount = Convert.ToUInt16(scp.Channels.Count); // Set measure mode: scp.MeasureMode = MeasureMode.Block; // Set sample frequency: scp.SampleFrequency = 1e6; // 1 MHz // Set record length: scp.RecordLength = 10000; // 10 kS UInt64 recordLength = scp.RecordLength; // Read actual record length. // Set pre sample ratio: scp.PreSampleRatio = 0; // 0 % // For all channels: for (UInt16 ch = 0; ch < channelCount; ch++) { OscilloscopeChannel channel = scp.Channels[ch]; if (!channel.IsAvailable) { continue; } // Enable channel to measure it: channel.Enabled = true; // Set range: channel.Range = 8; // 8 V // Set coupling: channel.Coupling = Coupling.DCV; // DC Volt } // Set trigger timeout: scp.TriggerTimeOut = 100e-3; // 100 ms // Disable all channel trigger sources: for (UInt16 ch = 0; ch < channelCount; ch++) { scp.Channels[ch].Trigger.Enabled = false; } // Setup channel trigger: OscilloscopeChannelTrigger channelTrigger = scp.Channels[0].Trigger; // Ch 1 // Enable trigger source: channelTrigger.Enabled = true; // Kind: channelTrigger.Kind = TriggerKind.RisingEdge; // Level: channelTrigger.Level[0] = 0.5; // 50 % // Hysteresis: channelTrigger.Hysteresis[0] = 0.05; // 5 % // Print oscilloscope info: PrintInfo.PrintDeviceInfo(scp); // Start measurement: scp.Start(); // Wait for measurement to complete: while (!scp.IsDataReady) { Thread.Sleep(10); // 10 ms delay, to save CPU time. } // Get data: float[][] data = scp.GetData(); // Open file with write/update permissions: string filename = "OscilloscopeBlock.csv"; StreamWriter file = new StreamWriter(filename, false); // Write the data to csv: if (File.Exists(filename)) { // Write csv header: file.Write("Sample"); for (UInt16 i = 0; i < channelCount; i++) { file.Write(string.Format(";Ch{0}", i + 1)); } file.Write(Environment.NewLine); // Write the data to csv: for (UInt64 i = 0; i < recordLength; i++) { file.Write(i.ToString()); for (UInt16 ch = 0; ch < channelCount; ch++) { file.Write(";"); if (data[ch] != null) { file.Write(data[ch][i].ToString()); } } file.Write(Environment.NewLine); } Console.WriteLine("Data written to: " + filename); // Close file: file.Close(); } else { Console.WriteLine("Couldn't open file: " + filename); Environment.Exit(1); } } catch (System.Exception e) { Console.WriteLine("Exception: " + e.Message); Environment.Exit(1); } // Close oscilloscope: scp.Dispose(); scp = null; } else { Console.WriteLine("No oscilloscope available with block measurement support!"); Environment.Exit(1); } Environment.Exit(0); }
public static void PrintOscilloscopeInfo(Oscilloscope scp) { try { Console.WriteLine("Oscilloscope:"); Console.WriteLine(" Channel count : " + scp.Channels.Count.ToString()); Console.WriteLine(" Connection test : " + scp.HasConnectionTest.ToString()); Console.WriteLine(" Measure modes : " + MeasureModeToStr(scp.MeasureModes)); Console.WriteLine(" Measure mode : " + MeasureModeToStr((UInt32)scp.MeasureMode)); Console.WriteLine(" Auto resolution modes : " + AutoResolutionModeToStr(scp.AutoResolutionModes)); Console.WriteLine(" Auto resolution mode : " + AutoResolutionModeToStr((UInt64)scp.AutoResolutionMode)); Console.WriteLine(" Resolutions : " + String.Join(", ", Array.ConvertAll(scp.Resolutions, x => x.ToString()))); Console.WriteLine(" Resolution : " + scp.Resolution.ToString()); Console.WriteLine(" Resolution enhanced : " + scp.IsResolutionEnhanced.ToString()); Console.WriteLine(" Clock outputs : " + ClockOutputToStr(scp.ClockOutputs)); Console.WriteLine(" Clock output : " + ClockOutputToStr((UInt32)scp.ClockOutput)); try { Console.WriteLine(" Clock output frequencies : " + String.Join(", ", Array.ConvertAll(scp.ClockOutputFrequencies, x => x.ToString()))); Console.WriteLine(" Clock output frequency : " + scp.ClockOutputFrequency.ToString()); } catch { } Console.WriteLine(" Clock sources : " + ClockSourceToStr(scp.ClockSources)); Console.WriteLine(" Clock source : " + ClockSourceToStr((UInt32)scp.ClockSource)); try { Console.WriteLine(" Clock source frequencies : " + String.Join(", ", Array.ConvertAll(scp.ClockSourceFrequencies, x => x.ToString()))); Console.WriteLine(" Clock source frequency : " + scp.ClockSourceFrequency.ToString()); } catch { } Console.WriteLine(" Record length max : " + scp.RecordLengthMax.ToString()); Console.WriteLine(" Record length : " + scp.RecordLength.ToString()); Console.WriteLine(" Sample frequency max : " + scp.SampleFrequencyMax.ToString()); Console.WriteLine(" Sample frequency : " + scp.SampleFrequency.ToString()); if (scp.MeasureMode == MeasureMode.Block) { Console.WriteLine(" Segment count max : " + scp.SegmentCountMax.ToString()); if (scp.SegmentCountMax > 1) { Console.WriteLine(" Segment count : " + scp.SegmentCount.ToString()); } } if (scp.HasTrigger) { Console.WriteLine(" Pre sample ratio : " + scp.PreSampleRatio.ToString()); Double timeout = scp.TriggerTimeOut; Console.Write(" Trigger time out : "); if (timeout == Constants.TO_INFINITY) { Console.WriteLine("Infinite"); } else { Console.WriteLine(timeout.ToString()); } if (scp.HasTriggerDelay) { Console.WriteLine(" Trigger delay max : " + scp.TriggerDelayMax.ToString()); Console.WriteLine(" Trigger delay : " + scp.TriggerDelay.ToString()); } if (scp.HasTriggerHoldOff) { Console.WriteLine(" Trigger hold off count max: " + scp.TriggerHoldOffCountMax.ToString()); Console.WriteLine(" Trigger hold off count : " + scp.TriggerHoldOffCount.ToString()); } } for (UInt16 ch = 0; ch < scp.Channels.Count; ch++) { OscilloscopeChannel channel = scp.Channels[ch]; Console.WriteLine(" Channel" + (ch + 1).ToString() + ":"); Console.WriteLine(" Connector type : " + ConnectorTypeToStr((UInt32)channel.ConnectorType)); Console.WriteLine(" Differential : " + channel.IsDifferential.ToString()); Console.WriteLine(" Impedance : " + channel.Impedance.ToString()); Console.WriteLine(" Connection test : " + channel.HasConnectionTest.ToString()); Console.WriteLine(" Available : " + channel.IsAvailable.ToString()); Console.WriteLine(" Enabled : " + channel.Enabled.ToString()); Console.WriteLine(" Bandwidths : " + String.Join(", ", Array.ConvertAll(channel.Bandwidths, x => x.ToString()))); Console.WriteLine(" Bandwidth : " + channel.Bandwidth.ToString()); Console.WriteLine(" Couplings : " + CouplingToStr(channel.Couplings)); Console.WriteLine(" Coupling : " + CouplingToStr((UInt64)channel.Coupling)); Console.WriteLine(" Auto ranging : " + channel.AutoRanging.ToString()); Console.WriteLine(" Ranges : " + String.Join(", ", Array.ConvertAll(channel.Ranges, x => x.ToString()))); Console.WriteLine(" Range : " + channel.Range.ToString()); Console.WriteLine(" Probe gain : " + channel.ProbeGain.ToString()); Console.WriteLine(" Probe offset : " + channel.ProbeOffset.ToString()); if (channel.HasSafeGround) { Console.WriteLine(" SafeGround enabled : " + channel.SafeGroundEnabled.ToString()); Console.WriteLine(" SafeGround threshold max: " + channel.SafeGroundThresholdMax.ToString()); Console.WriteLine(" SafeGround threshold min: " + channel.SafeGroundThresholdMin.ToString()); Console.WriteLine(" SafeGround threshold : " + channel.SafeGroundThreshold.ToString()); } if (channel.HasTrigger) { OscilloscopeChannelTrigger trigger = channel.Trigger; Console.WriteLine(" Trigger:"); Console.WriteLine(" Available : " + trigger.IsAvailable.ToString()); Console.WriteLine(" Enabled : " + trigger.Enabled.ToString()); Console.WriteLine(" Kinds : " + TriggerKindToStr(trigger.Kinds)); Console.WriteLine(" Kind : " + TriggerKindToStr((UInt64)trigger.Kind)); Console.WriteLine(" Level modes : " + TriggerLevelModeToStr(trigger.LevelModes)); Console.WriteLine(" Level mode : " + TriggerLevelModeToStr((UInt32)trigger.LevelMode)); if (trigger.Level.Count != 0) { Double[] levels = new Double[trigger.Level.Count]; for (UInt32 i = 0; i < trigger.Level.Count; i++) { levels[i] = trigger.Level[i]; } Console.WriteLine(" Levels : " + String.Join(", ", Array.ConvertAll(levels, x => x.ToString()))); } if (trigger.Hysteresis.Count != 0) { Double[] hysteresis = new Double[trigger.Hysteresis.Count]; for (UInt32 i = 0; i < trigger.Hysteresis.Count; i++) { hysteresis[i] = trigger.Hysteresis[i]; } Console.WriteLine(" Histeresis : " + String.Join(", ", Array.ConvertAll(hysteresis, x => x.ToString()))); } Console.WriteLine(" Conditions : " + TriggerConditionToStr(trigger.Conditions)); if (trigger.Conditions != Constants.TCM_NONE) { Console.WriteLine(" Condition : " + TriggerConditionToStr((UInt32)trigger.Condition)); } if (trigger.Time.Count != 0) { Double[] times = new Double[trigger.Time.Count]; for (UInt32 i = 0; i < trigger.Time.Count; i++) { times[i] = trigger.Time[i]; } Console.WriteLine(" Times : " + String.Join(", ", Array.ConvertAll(times, x => x.ToString()))); } } } PrintTriggerInputsInfo(scp.TriggerInputs); PrintTriggerOutputsInfo(scp.TriggerOutputs); } catch (System.Exception e) { Console.WriteLine("Exception: " + e.Message); } }