public static extern StandardDriverStatusCode NearestSampleIntervalStateless( short handle, EnabledChannelsAndPorts enabledChannelFlags, double timeIntervalRequested, DeviceResolution resolution, out uint timebase, out double timeIntervalAvailable);
/// <summary> /// Opens a ps6000a unit /// </summary> public static StandardDriverStatusCode OpenUnit(out short handle, DeviceResolution resolution, out int numChannels) { numChannels = 0; var status = DriverImports.PS6000a.OpenUnit(out handle, null, resolution); if (handle <= 0 || status != StandardDriverStatusCode.Ok) { return(status); } Console.WriteLine("The ps6000a Device has successfully opened with handle: " + handle); short requiredSize = 80; StringBuilder info = new StringBuilder(requiredSize); status = DriverImports.PS6000a.GetUnitInfo(handle, info, requiredSize, out requiredSize, InfoType.VariantInfo); if (status != StandardDriverStatusCode.Ok) { return(status); } numChannels = (int)Char.GetNumericValue(info[1]); //2nd Char contains the number of channels of the device variant Console.WriteLine("This device has " + numChannels + " Channels"); return(status); }
/// <summary> /// This function sets up and waits for an Aux trigger or 5s. /// </summary> static StandardDriverStatusCode AuxTriggerDelay(short handle, DeviceResolution resolution, int numChannels) { var channel = Channel.Aux; ulong numSamples = 1000; int autoTriggerDelay = 5000000; //5s in μs double idealTimeInterval = 0.0000001; //100ns var status = ps6000aDevice.SetTrigger(handle, channel, autoTriggerDelay); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.RunBlock(handle, resolution, numSamples, Channel.ChannelA, idealTimeInterval); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.WaitForDataToBeCaptured(handle, channel); if (status != StandardDriverStatusCode.Ok) { return(status); } return(status); }
/// <summary> /// TODO Add description /// </summary> static StandardDriverStatusCode RunAWGExample(short handle, DeviceResolution resolution, int numChannels) { var channel = Channel.ChannelA; ulong numSamples = 1000; double idealTimeInterval = 0.0000001; //100ns var status = ps6000aDevice.InitializeChannels(handle, new List <Channel>() { channel }, numChannels); if (status != StandardDriverStatusCode.Ok) { return(status); } //Hardcoded Arbitrary Waveform to prove it is working correctly, Numbers don't really matter. var arbitraryWaveformBuffer = new List <short>() { 0, 16000, 0, -16000, 0, 8000, 12000, 8000, 1200 }; status = ps6000aDevice.EnableAWGOutput(handle, WaveType.Arbitrary, false, arbitraryWaveformBuffer); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.RunBlock(handle, resolution, numSamples, channel, idealTimeInterval); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.WaitForDataToBeCaptured(handle, channel); if (status != StandardDriverStatusCode.Ok) { return(status); } var data = new short[numSamples]; GCHandle gch = GCHandle.Alloc(data); try { status = ps6000aDevice.ReadDataFromDevice(handle, channel, numSamples, ref data); if (status != StandardDriverStatusCode.Ok) { return(status); } ps6000aDevice.WriteDataToFile(data); } finally { gch.Free(); } return(status); }
/// <summary> /// Captures data on MSO Port0 and exits once data has been fully captured. /// </summary> static StandardDriverStatusCode RunMSOTriggerExample(short handle, DeviceResolution resolution, int numChannels) { var channel = Channel.Port0; ulong numSamples = 1000; double idealTimeInterval = 0.00001; //10us //Disable all analogue channels //Note: Disabling all analogue channels will result in only the PICO_DR_8BIT resolution being available for captures. var status = ps6000aDevice.InitializeChannels(handle, new List <Channel>(), numChannels); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.InitializeDigitalChannels(handle, channel); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.SetDigitalTrigger(handle, channel); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.RunBlock(handle, resolution, numSamples, channel, idealTimeInterval); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.WaitForDataToBeCaptured(handle, channel); if (status != StandardDriverStatusCode.Ok) { return(status); } var data = new short[numSamples]; GCHandle gch = GCHandle.Alloc(data); try { status = ps6000aDevice.ReadDataFromDevice(handle, channel, numSamples, ref data); if (status != StandardDriverStatusCode.Ok) { return(status); } ps6000aDevice.WriteDigitalDataToFile(data); } finally { gch.Free(); } return(status); }
/// <summary> /// Outputs a 100KHz Sine wave from AWG output, captures on Channel A and the data is written to Output.csv /// </summary> static StandardDriverStatusCode RunAWGExample(short handle, DeviceResolution resolution, int numChannels) { var channel = Channel.ChannelA; ulong numSamples = 1000; double idealTimeInterval = 0.0000001; //100ns var status = ps6000aDevice.InitializeChannels(handle, new List <Channel>() { channel }, numChannels); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.EnableAWGOutput(handle, WaveType.Sine); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.RunBlock(handle, resolution, numSamples, channel, idealTimeInterval); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.WaitForDataToBeCaptured(handle, channel); if (status != StandardDriverStatusCode.Ok) { return(status); } var data = new short[numSamples]; GCHandle gch = GCHandle.Alloc(data); try { status = ps6000aDevice.ReadDataFromDevice(handle, channel, numSamples, ref data); if (status != StandardDriverStatusCode.Ok) { return(status); } ps6000aDevice.WriteDataToFile(data); } finally { gch.Free(); } return(status); }
/// <summary> /// Gets the resolution of the display device associated with the screen. /// </summary> /// <param name="screen">The Windows Forms screen object associated with the display device.</param> /// <returns>A struct having the screen, display device width, and display device height.</returns> public static DeviceResolution GetDeviceResolution(System.Windows.Forms.Screen screen) { DEVMODE dm = new DEVMODE(); dm.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE)); EnumDisplaySettings(screen.DeviceName, ENUM_CURRENT_SETTINGS, ref dm); DeviceResolution deviceResolution = new DeviceResolution() { screen = screen, width = dm.dmPelsWidth, height = dm.dmPelsHeight }; return(deviceResolution); }
/// <summary> /// Calls Runblock on the device /// </summary> public static StandardDriverStatusCode RunBlock(short handle, DeviceResolution resolution, ulong numSamples, Channel channel, double idealTimeInterval, DefinitionBlockReady callback = null) { double actualTimeInterval; double timeIndisposedMS; uint timebase; var status = DriverImports.PS6000a.NearestSampleIntervalStateless(handle, GetChannelFlag(channel), idealTimeInterval, resolution, out timebase, out actualTimeInterval); if (status != StandardDriverStatusCode.Ok) { return(status); } //Set the number of pre and post trigger samples to half the number of samples. //Thus the middle sample should be the trigger point. return(DriverImports.PS6000a.RunBlock(handle, numSamples / 2, numSamples / 2, timebase, out timeIndisposedMS, 0, callback, IntPtr.Zero)); }
public static extern UInt32 GetDeviceResolution(short handle, out DeviceResolution resolution);
public static extern UInt32 OpenUnitWithResolution(out short handle, StringBuilder serial, DeviceResolution resolution);
public static extern StandardDriverStatusCode OpenUnit( out short handle, StringBuilder serial, DeviceResolution resolution);
static StandardDriverStatusCode RunGetTriggerInfoExample(short handle, DeviceResolution resolution, int numChannels) { var channel = Channel.ChannelA; ulong numSamples = 1000; double idealTimeInterval = 1.0e-7; // 100ns ulong numWaveforms = 10; var status = ps6000aDevice.InitializeChannels(handle, new List <Channel>() { channel }, numChannels); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.SetUpWithNoOfWaveformsToCapture(handle, ref numSamples, numWaveforms); if (status != StandardDriverStatusCode.Ok) { return(status); } double actualTimeInterval = 0.0; uint timebase = 0; status = DriverImports.PS6000a.NearestSampleIntervalStateless(handle, EnabledChannelsAndPorts.ChannelA, idealTimeInterval, resolution, out timebase, out actualTimeInterval); if (status != StandardDriverStatusCode.Ok) { return(status); } // We set up our signal generator to output a 10Hz Sine wave. status = ps6000aDevice.EnableAWGOutput(handle, WaveType.Sine, frequency: 10); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.SetTrigger(handle, channel); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.RunBlock(handle, resolution, numSamples, channel, idealTimeInterval); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.WaitForDataToBeCaptured(handle, channel); if (status != StandardDriverStatusCode.Ok) { return(status); } status = PrintTimeElapsedBetweenTriggers(handle, numWaveforms, actualTimeInterval); if (status != StandardDriverStatusCode.Ok) { return(status); } Console.WriteLine(); return(StandardDriverStatusCode.Ok); }
static StandardDriverStatusCode RunPulseWidthTriggerExample( short handle, DeviceResolution resolution, int numChannels, double awgFrequency, double pulseWidthFrequency, PulseWidthType pulseWidthType, string filename) { double cycleTime = 1.0 / pulseWidthFrequency; // The minimum time in seconds required for the pulse width trigger to hit. double pulseWidthPeriodSeconds = 0.5 * cycleTime; Console.WriteLine($"Running a pulse width qualifier test with a period of {(float)(1000000.0 * pulseWidthPeriodSeconds) }us."); switch (pulseWidthType) { case PulseWidthType.Greater_Than: Console.WriteLine("The AWG frequency is less than the pulse width period."); break; case PulseWidthType.Less_Than: Console.WriteLine("The AWG frequency is greater than the pulse width period."); break; } Console.WriteLine(); var channel = Channel.ChannelA; ulong numSamples = 1000; double idealTimeInterval = 0.0000001; //100ns var status = ps6000aDevice.EnableAWGOutput(handle, WaveType.Square, frequency: awgFrequency); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.InitializeChannels(handle, new List <Channel>() { channel }, numChannels); if (status != StandardDriverStatusCode.Ok) { return(status); } double actualTimeInterval = 0.0; uint timebase = 0; status = DriverImports.PS6000a.NearestSampleIntervalStateless(handle, EnabledChannelsAndPorts.ChannelA, idealTimeInterval, resolution, out timebase, out actualTimeInterval); if (status != StandardDriverStatusCode.Ok) { return(status); } int timeIntervalNanoseconds = 0; ulong maxSamples = 0; status = DriverImports.PS6000a.GetTimebase(handle, timebase, 1, out timeIntervalNanoseconds, out maxSamples, 0); if (status != StandardDriverStatusCode.Ok) { return(status); } var pulseWidthSampleCount = (uint)Math.Floor(pulseWidthPeriodSeconds / actualTimeInterval); status = ps6000aDevice.SetTriggerAndPulseWidth(handle, channel, pulseWidthSampleCount, pulseWidthType); if (status != StandardDriverStatusCode.Ok) { return(status); } ps6000aDevice.RunBlock(handle, resolution, numSamples, channel, idealTimeInterval); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.WaitForDataToBeCaptured(handle, channel); if (status != StandardDriverStatusCode.Ok) { return(status); } var data = new short[numSamples]; GCHandle gch = GCHandle.Alloc(data); try { status = ps6000aDevice.ReadDataFromDevice(handle, channel, numSamples, ref data); if (status != StandardDriverStatusCode.Ok) { return(status); } ps6000aDevice.WriteDataToFile(data, filename); } finally { gch.Free(); } return(status); }
static StandardDriverStatusCode RunTriggerWithinPreTriggerExample(short handle, DeviceResolution resolution, int numChannels) { var channel = Channel.ChannelA; ulong numSamples = 2000000; // 1 million pre-trigger samples (and 1 million post-trigger samples) double idealTimeInterval = 1e-7; // 100ns var status = ps6000aDevice.InitializeChannels(handle, new List <Channel>() { channel }, numChannels); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.EnableAWGOutput(handle, WaveType.Sine, softwareTrigger: true); if (status != StandardDriverStatusCode.Ok) { return(status); } status = DriverImports.PS6000a.TriggerWithinPreTriggerSamples(handle, TriggerWithinPreTrigger.Arm); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.SetTrigger(handle, channel); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.RunBlock(handle, resolution, numSamples, channel, idealTimeInterval, null); if (status != StandardDriverStatusCode.Ok) { return(status); } // Wait three milliseconds for AWG // (This is due to the device having a post sample latency after these previous API calls. // This latency can be reduced by enabling extra channels and/or increasing bit resolution.) Thread.Sleep(3); // The rising trigger we're passing in for this api function is dummy data status = DriverImports.PS6000a.SigGenSoftwareTriggerControl(handle, SiggenTrigType.Rising); if (status != StandardDriverStatusCode.Ok) { return(status); } status = ps6000aDevice.WaitForDataToBeCaptured(handle, channel); if (status != StandardDriverStatusCode.Ok) { return(status); } var data = new short[numSamples]; GCHandle gch = GCHandle.Alloc(data); try { status = ps6000aDevice.ReadDataFromDevice(handle, channel, numSamples, ref data); if (status != StandardDriverStatusCode.Ok) { return(status); } ps6000aDevice.WriteDataToFile(data); } finally { gch.Free(); } return(status); }