Skip to content

Commit bb650b6

Browse files
Fix/tsp 1240 missing measure range in script (#41)
Missing measure range added to the generated tsp script and both source and measure range values are rounded to 3 decimal places
1 parent 37fee6b commit bb650b6

File tree

3 files changed

+79
-4
lines changed

3 files changed

+79
-4
lines changed

script-gen-manager/src/model/chan_data/default_channel.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct CommonChanAttributes {
1919
pub source_function: ParameterString,
2020
pub meas_function: ParameterString,
2121
pub source_range: ChannelRange,
22-
meas_range: ChannelRange,
22+
pub meas_range: ChannelRange,
2323
pub source_limiti: Option<ParameterFloat>,
2424
pub source_limitv: Option<ParameterFloat>,
2525
pub sense_mode: Option<ParameterString>,
@@ -153,6 +153,7 @@ impl CommonChanAttributes {
153153

154154
fn evaluate_measure_function(&mut self) {
155155
if self.meas_function.value == self.source_function.value {
156+
self.meas_range.unit = self.source_range.unit.clone();
156157
self.meas_range.range = self.source_range.range.clone();
157158
self.meas_range.value = self.source_range.value.clone();
158159
} else {
@@ -163,6 +164,7 @@ impl CommonChanAttributes {
163164
}
164165

165166
fn set_meas_range(&mut self, metadata: &MetadataEnum) {
167+
self.meas_range.unit = self.determine_units(&self.meas_function.value);
166168
if self.meas_function.value == BaseMetadata::FUNCTION_VOLTAGE.to_string() {
167169
self.meas_range.range = self.get_range(metadata, "source_meas.rangev");
168170
} else {

script-gen-manager/src/script_component/sweep.rs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ impl SweepModel {
129129
&instr_name,
130130
);
131131

132+
self.set_measure_range(
133+
bias_channel.common_chan_attributes.meas_range.clone(),
134+
&instr_name,
135+
);
136+
132137
let val = self
133138
.get_function_value(&bias_channel.common_chan_attributes.meas_function)
134139
.clone();
@@ -201,6 +206,16 @@ impl SweepModel {
201206
.insert(instr_name.clone() + ":SRANGE", val);
202207
}
203208

209+
fn set_measure_range(&mut self, channel_range: ChannelRange, instr_name: &String) {
210+
let mut val = self.format_range(channel_range.clone());
211+
212+
if channel_range.is_range_auto() {
213+
val = "CONSTANTS.AUTO".to_string();
214+
}
215+
self.val_replacement_map
216+
.insert(instr_name.clone() + ":MRANGE", val);
217+
}
218+
204219
//Returns the value used in the script
205220
fn get_function_value(&mut self, source_function: &ParameterString) -> String {
206221
if source_function.value.to_lowercase() == BaseMetadata::FUNCTION_VOLTAGE.to_lowercase() {
@@ -282,6 +297,15 @@ impl SweepModel {
282297
&instr_name,
283298
);
284299

300+
self.set_measure_range(
301+
step_channel
302+
.start_stop_channel
303+
.common_chan_attributes
304+
.meas_range
305+
.clone(),
306+
&instr_name,
307+
);
308+
285309
let val = self
286310
.get_function_value(
287311
&step_channel
@@ -495,6 +519,15 @@ impl SweepModel {
495519
&instr_name,
496520
);
497521

522+
self.set_measure_range(
523+
sweep_channel
524+
.start_stop_channel
525+
.common_chan_attributes
526+
.meas_range
527+
.clone(),
528+
&instr_name,
529+
);
530+
498531
let val = self
499532
.get_function_value(
500533
&sweep_channel
@@ -725,15 +758,20 @@ impl SweepModel {
725758
///
726759
/// # Returns
727760
/// A formatted string representing the range value. If the range is set to auto or follow limit,
728-
/// the original value is returned. Otherwise, the scaled value is formatted using the `format` method.
761+
/// the original value is returned. Otherwise, the scaled value is formatted with 3 decimal places.
729762
fn format_range(&self, range: ChannelRange) -> String {
730763
let mut result = String::from("NaN");
731764
if range.is_range_auto() || range.is_range_follow_limiti() {
732765
result = range.value;
733766
} else {
734767
let range_value = range.get_scaled_value();
735768
if let Some(value) = range_value {
736-
result = self.format(value);
769+
// Format with 3 decimal places, using scientific notation if needed
770+
if value.abs() < 1e-3 || value.abs() >= 1e3 {
771+
result = format!("{:.3e}", value);
772+
} else {
773+
result = format!("{:.3}", value);
774+
}
737775
}
738776
}
739777
result

xml-handler/src/resources/sweep/MP5000Sweep.xml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
---@field nplc number | nil
9999
---@field aperture number | nil
100100
---@field rate `CONSTANTS.RATE_FAST` | `CONSTANTS.RATE_NORMAL` | nil
101+
---@field range number | "AUTO" The range to use, or Auto
101102
-- ---@field autozero boolean Whether autozero should be turned on or not
102103
---@field count integer The number of measurments to take
103104
-- ---@field filter_enable boolean Whether to enable the filter or not
@@ -386,6 +387,20 @@
386387
elseif self.measure.aperture ~= nil then
387388
self.channel.measure.aperture = self.measure.aperture
388389
end
390+
-- range
391+
if self.measure.range == CONSTANTS.AUTO then
392+
if self.measure.func == CONSTANTS.FUNC_DC_VOLTAGE then
393+
self.channel.measure.autorangev = self.slot.smu.ON
394+
elseif self.measure.func == CONSTANTS.FUNC_DC_CURRENT then
395+
self.channel.measure.autorangei = self.slot.smu.ON
396+
end
397+
else
398+
if self.measure.func == CONSTANTS.FUNC_DC_VOLTAGE then
399+
self.channel.measure.rangev = self.measure.range
400+
elseif self.measure.func == CONSTANTS.FUNC_DC_CURRENT then
401+
self.channel.measure.rangei = self.measure.range
402+
end
403+
end
389404
-- count
390405
self.channel.measure.count = self.measure.count
391406
-- TODO: filter_enable
@@ -788,6 +803,20 @@
788803
self.channel.measure.rate = self.channel.RATE_NORMAL
789804
end
790805
end
806+
-- range
807+
if self.measure.range == CONSTANTS.AUTO then
808+
if self.measure.func == CONSTANTS.FUNC_DC_VOLTAGE then
809+
self.channel.measure.autorangev = self.slot.psu.ON
810+
elseif self.measure.func == CONSTANTS.FUNC_DC_CURRENT then
811+
self.channel.measure.autorangei = self.slot.psu.ON
812+
end
813+
else
814+
if self.measure.func == CONSTANTS.FUNC_DC_VOLTAGE then
815+
self.channel.measure.rangev = self.measure.range
816+
elseif self.measure.func == CONSTANTS.FUNC_DC_CURRENT then
817+
self.channel.measure.rangei = self.measure.range
818+
end
819+
end
791820
-- count
792821
self.channel.measure.count = self.measure.count
793822
-- TODO: filter_enable
@@ -1309,6 +1338,7 @@
13091338
<substitute name="BIAS-DEVICE:SRANGE">%SRANGE%</substitute>
13101339
<substitute name="BIAS-DEVICE:BIAS">%BIAS%</substitute>
13111340
<substitute name="BIAS-DEVICE:MFUNCTION">%MFUNCTION%</substitute>
1341+
<substitute name="BIAS-DEVICE:MRANGE">%MRANGE%</substitute>
13121342
<substitute name="BIAS-DEVICE:SENSE">%SENSE%</substitute>
13131343
<substitute name="BIAS-DEVICE:LIMITI">%LIMITI%</substitute>
13141344
<substitute name="BIAS-DEVICE:LIMITV">%LIMITV%</substitute>
@@ -1329,6 +1359,7 @@
13291359
},
13301360
measure = {
13311361
nplc = nplc,
1362+
range = %MRANGE%,
13321363
aperture = aperture,
13331364
count = measure_count,
13341365
delay = measure_delay,
@@ -1386,6 +1417,7 @@
13861417
<substitute name="STEP-DEVICE:START">%START%</substitute>
13871418
<substitute name="STEP-DEVICE:STOP">%STOP%</substitute>
13881419
<substitute name="STEP-DEVICE:LIST">%LIST%</substitute>
1420+
<substitute name="STEP-DEVICE:MRANGE">%MRANGE%</substitute>
13891421
<substitute name="STEP-DEVICE:MFUNCTION">%MFUNCTION%</substitute>
13901422
<substitute name="STEP-DEVICE:SENSE">%SENSE%</substitute>
13911423
<substitute name="STEP-DEVICE:LIMITI">%LIMITI%</substitute>
@@ -1435,6 +1467,7 @@
14351467
},
14361468
measure = {
14371469
nplc = nplc,
1470+
range = %MRANGE%,
14381471
aperture = aperture,
14391472
count = measure_count,
14401473
delay = measure_delay,
@@ -1491,7 +1524,8 @@
14911524
<substitute name="SWEEP-DEVICE:SRANGE">%SRANGE%</substitute>
14921525
<substitute name="SWEEP-DEVICE:START">%START%</substitute>
14931526
<substitute name="SWEEP-DEVICE:STOP">%STOP%</substitute>
1494-
<substitute name="SWEEP-DEVICE:LIST">%LIST%</substitute>
1527+
<substitute name="SWEEP-DEVICE:LIST">%LIST%</substitute>
1528+
<substitute name="SWEEP-DEVICE:MRANGE">%MRANGE%</substitute>
14951529
<substitute name="SWEEP-DEVICE:MFUNCTION">%MFUNCTION%</substitute>
14961530
<substitute name="SWEEP-DEVICE:SENSE">%SENSE%</substitute>
14971531
<substitute name="SWEEP-DEVICE:LIMITI">%LIMITI%</substitute>
@@ -1541,6 +1575,7 @@
15411575
},
15421576
measure = {
15431577
nplc = nplc,
1578+
range = %MRANGE%,
15441579
aperture = aperture,
15451580
count = measure_count,
15461581
delay = measure_delay,

0 commit comments

Comments
 (0)