Skip to content

Commit 8875bff

Browse files
committed
implement signal generation API for PS4000A (tested on 4824)
1 parent 9f4f8fa commit 8875bff

File tree

1 file changed

+134
-1
lines changed

1 file changed

+134
-1
lines changed

driver/src/ps4000a.rs

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ use parking_lot::{Mutex, RwLock};
1010
use pico_common::{
1111
ChannelConfig, DownsampleMode, Driver, FromPicoStr, PicoChannel, PicoError, PicoInfo,
1212
PicoRange, PicoResult, PicoStatus, SampleConfig, ToPicoStr,
13+
PicoSweepType,
14+
PicoExtraOperations, PicoIndexMode, PicoSigGenTrigType, PicoSigGenTrigSource,
15+
SweepShotCount, SigGenArbitraryMinMaxValues,
16+
};
17+
use pico_sys_dynamic::ps4000a::{
18+
PS4000ALoader, PS4000A_USER_PROBE_INTERACTIONS,
19+
PS4000A_EXTRA_OPERATIONS, PS4000A_INDEX_MODE, PS4000A_SIGGEN_TRIG_SOURCE, PS4000A_SIGGEN_TRIG_TYPE, PS4000A_SWEEP_TYPE,
1320
};
14-
use pico_sys_dynamic::ps4000a::{PS4000ALoader, PS4000A_USER_PROBE_INTERACTIONS};
1521
use std::{collections::HashMap, matches, pin::Pin, sync::Arc};
1622

1723
type ChannelRangesMap = HashMap<PicoChannel, Vec<PicoRange>>;
@@ -353,4 +359,131 @@ impl PicoDriver for PS4000ADriver {
353359
fn stop(&self, handle: i16) -> PicoResult<()> {
354360
PicoStatus::from(unsafe { self.bindings.ps4000aStop(handle) }).to_result((), "stop")
355361
}
362+
363+
#[tracing::instrument(level = "trace", skip(self))]
364+
fn set_sig_gen_properties_built_in(
365+
&self,
366+
handle: i16,
367+
start_frequency: f64,
368+
stop_frequency: f64,
369+
increment: f64,
370+
dwell_time: f64,
371+
sweep_type: PicoSweepType,
372+
sweeps_shots: SweepShotCount,
373+
trigger_type: PicoSigGenTrigType,
374+
trigger_source: PicoSigGenTrigSource,
375+
ext_in_threshold: i16
376+
) -> PicoResult<()> {
377+
PicoStatus::from(unsafe {
378+
self.bindings.ps4000aSetSigGenPropertiesBuiltIn(
379+
handle,
380+
start_frequency,
381+
stop_frequency,
382+
increment,
383+
dwell_time,
384+
sweep_type as u32,
385+
sweeps_shots.to_shots(),
386+
sweeps_shots.to_sweeps(),
387+
trigger_type as u32,
388+
trigger_source as u32,
389+
ext_in_threshold
390+
)
391+
}).to_result((), "set_sig_gen_properties_build_in")
392+
}
393+
394+
#[tracing::instrument(level = "trace", skip(self))]
395+
fn sig_gen_software_control(
396+
&self,
397+
handle: i16,
398+
state: i16,
399+
) -> PicoResult<()> {
400+
401+
PicoStatus::from(unsafe {
402+
self.bindings.ps4000aSigGenSoftwareControl(handle, state)
403+
}).to_result((), "sig_gen_software_control")
404+
}
405+
406+
// PS4000A has no SetSigGenBuiltInV2
407+
408+
#[tracing::instrument(level = "trace", skip(self))]
409+
fn set_sig_gen_arbitrary(
410+
&self,
411+
handle: i16,
412+
offset_voltage: i32,
413+
pk_to_pk: u32,
414+
start_delta_phase: u32,
415+
stop_delta_phase: u32,
416+
delta_phase_increment: u32,
417+
dwell_count: u32,
418+
arbitrary_waveform: &mut Vec<i16>,
419+
sweep_type: PicoSweepType,
420+
operation: PicoExtraOperations,
421+
index_mode: PicoIndexMode,
422+
sweeps_shots: SweepShotCount,
423+
trigger_type: PicoSigGenTrigType,
424+
trigger_source: PicoSigGenTrigSource,
425+
ext_in_threshold: i16,
426+
) -> PicoResult<()> {
427+
PicoStatus::from(unsafe {
428+
self.bindings.ps4000aSetSigGenArbitrary(
429+
handle,
430+
offset_voltage,
431+
pk_to_pk,
432+
start_delta_phase,
433+
stop_delta_phase,
434+
delta_phase_increment,
435+
dwell_count,
436+
arbitrary_waveform.as_mut_ptr(),
437+
arbitrary_waveform.len() as i32,
438+
sweep_type as PS4000A_SWEEP_TYPE,
439+
operation as PS4000A_EXTRA_OPERATIONS,
440+
index_mode as PS4000A_INDEX_MODE,
441+
sweeps_shots.to_shots(),
442+
sweeps_shots.to_sweeps(),
443+
trigger_type as PS4000A_SIGGEN_TRIG_TYPE,
444+
trigger_source as PS4000A_SIGGEN_TRIG_SOURCE,
445+
ext_in_threshold)
446+
}).to_result((), "set_sig_gen_arbitrary")
447+
}
448+
449+
fn sig_gen_arbitrary_min_max_values(
450+
&self,
451+
handle: i16,
452+
) -> PicoResult<SigGenArbitraryMinMaxValues> {
453+
let mut min_value: i16 = 0;
454+
let mut max_value: i16 = 0;
455+
let mut min_size: u32 = 0;
456+
let mut max_size: u32 = 0;
457+
PicoStatus::from(unsafe {
458+
self.bindings.ps4000aSigGenArbitraryMinMaxValues(
459+
handle,
460+
&mut min_value,
461+
&mut max_value,
462+
&mut min_size,
463+
&mut max_size,
464+
)}).to_result(SigGenArbitraryMinMaxValues {
465+
min_value,
466+
max_value,
467+
min_size,
468+
max_size,
469+
}, "sig_gen_arbitrary_min_max_values")
470+
}
471+
472+
fn sig_gen_frequency_to_phase(
473+
&self,
474+
handle: i16,
475+
frequency: f64,
476+
index_mode: PicoIndexMode,
477+
buffer_length: u32,
478+
) -> PicoResult<u32> {
479+
let mut phase: u32 = 0;
480+
PicoStatus::from(unsafe {
481+
self.bindings.ps4000aSigGenFrequencyToPhase(
482+
handle,
483+
frequency,
484+
index_mode as u32,
485+
buffer_length,
486+
&mut phase,
487+
)}).to_result(phase, "sig_gen_arbitrary_min_max_values")
488+
}
356489
}

0 commit comments

Comments
 (0)