11use std:: { any:: Any , collections:: HashMap } ;
22
33use crate :: {
4+ device:: DeviceType ,
45 instr_metadata:: base_metadata:: BaseMetadata ,
56 model:: {
67 chan_data:: channel_range:: ChannelRange ,
7- sweep_data:: { parameters:: ParameterFloat , sweep_config:: SweepConfig } ,
8+ sweep_data:: {
9+ parameters:: { ParameterFloat , ParameterString } ,
10+ sweep_config:: SweepConfig ,
11+ } ,
812 } ,
913} ;
1014
@@ -79,9 +83,9 @@ impl SweepModel {
7983 }
8084 }
8185
82- fn define_bias_channels ( & mut self , sweep_config : & SweepConfig ) {
86+ fn define_bias_channels ( & mut self , bias_config : & SweepConfig ) {
8387 let mut index = 1 ;
84- for bias_channel in sweep_config . bias_channels . iter ( ) {
88+ for bias_channel in bias_config . bias_channels . iter ( ) {
8589 let instr_name = format ! ( "bias{index}" ) ;
8690 self . attributes . bias_names . push ( instr_name. clone ( ) ) ;
8791
@@ -106,43 +110,47 @@ impl SweepModel {
106110 ) ;
107111
108112 self . val_replacement_map . insert (
109- instr_name. clone ( ) + ":SFUNCTION " ,
113+ instr_name. clone ( ) + ":MODEL-TYPE " ,
110114 bias_channel
111115 . common_chan_attributes
112- . source_function
113- . value
114- . to_lowercase ( )
115- . clone ( ) ,
116- ) ;
117- self . val_replacement_map . insert (
118- instr_name. clone ( ) + ":SRANGE" ,
119- self . format_range ( bias_channel. common_chan_attributes . source_range . clone ( ) ) ,
116+ . device
117+ . device_type
118+ . to_string ( ) ,
120119 ) ;
121120
122- self . val_replacement_map . insert (
123- instr_name. clone ( ) + ":MFUNCTION" ,
124- bias_channel
125- . common_chan_attributes
126- . meas_function
127- . value
128- . to_lowercase ( )
129- . clone ( ) ,
121+ let val = self
122+ . get_function_value ( & bias_channel. common_chan_attributes . source_function )
123+ . clone ( ) ;
124+ self . val_replacement_map
125+ . insert ( instr_name. clone ( ) + ":SFUNCTION" , val) ;
126+
127+ self . set_source_range (
128+ bias_channel. common_chan_attributes . source_range . clone ( ) ,
129+ & instr_name,
130130 ) ;
131131
132+ let val = self
133+ . get_function_value ( & bias_channel. common_chan_attributes . meas_function )
134+ . clone ( ) ;
135+
136+ self . val_replacement_map
137+ . insert ( instr_name. clone ( ) + ":MFUNCTION" , val) ;
138+
132139 //sense mode exists only for SMU
133140 if let Some ( sense_mode) = & bias_channel. common_chan_attributes . sense_mode {
134141 let sense_mode_key = format ! ( "sense={}" , sense_mode. value) ;
135142 if let Some ( sense_mode_value) = bias_channel
136143 . common_chan_attributes
137144 . get_name_for ( & sense_mode_key)
138145 {
139- self . val_replacement_map . insert (
140- instr_name. clone ( ) + ":SENSE" ,
141- String :: from ( sense_mode_value) ,
142- ) ;
143- } else {
144- //TODO: error handling for sense mode value not found
146+ self . val_replacement_map
147+ . insert ( instr_name. clone ( ) + ":SENSE" , sense_mode_value. to_owned ( ) ) ;
145148 }
149+ } else {
150+ self . val_replacement_map . insert (
151+ instr_name. clone ( ) + ":SENSE" ,
152+ BaseMetadata :: UNDEFINED . to_string ( ) ,
153+ ) ;
146154 }
147155
148156 //source_limitv exists only for SMU
@@ -182,9 +190,33 @@ impl SweepModel {
182190 }
183191 }
184192
185- fn define_step_channels ( & mut self , sweep_config : & SweepConfig ) {
193+ fn set_source_range ( & mut self , channel_range : ChannelRange , instr_name : & String ) {
194+ let mut val = self . format_range ( channel_range. clone ( ) ) ;
195+
196+ if channel_range. is_range_auto ( ) {
197+ val = "CONSTANTS.AUTO" . to_string ( ) ;
198+ }
199+
200+ self . val_replacement_map
201+ . insert ( instr_name. clone ( ) + ":SRANGE" , val) ;
202+ }
203+
204+ //Returns the value used in the script
205+ fn get_function_value ( & mut self , source_function : & ParameterString ) -> String {
206+ if source_function. value . to_lowercase ( ) == BaseMetadata :: FUNCTION_VOLTAGE . to_lowercase ( ) {
207+ "FUNC_DC_VOLTAGE" . to_string ( )
208+ } else if source_function. value . to_lowercase ( )
209+ == BaseMetadata :: FUNCTION_CURRENT . to_lowercase ( )
210+ {
211+ "FUNC_DC_CURRENT" . to_string ( )
212+ } else {
213+ "FUNC_DC_IV_COMBINED" . to_string ( )
214+ }
215+ }
216+
217+ fn define_step_channels ( & mut self , step_config : & SweepConfig ) {
186218 let mut index = 1 ;
187- for step_channel in sweep_config . step_channels . iter ( ) {
219+ for step_channel in step_config . step_channels . iter ( ) {
188220 let instr_name = format ! ( "step{index}" ) ;
189221 self . attributes . step_names . push ( instr_name. clone ( ) ) ;
190222
@@ -221,35 +253,53 @@ impl SweepModel {
221253 ) ;
222254
223255 self . val_replacement_map . insert (
224- instr_name. clone ( ) + ":SFUNCTION " ,
256+ instr_name. clone ( ) + ":MODEL-TYPE " ,
225257 step_channel
226258 . start_stop_channel
227259 . common_chan_attributes
228- . source_function
229- . value
230- . to_lowercase ( )
231- . clone ( ) ,
260+ . device
261+ . device_type
262+ . to_string ( ) ,
232263 ) ;
233- self . val_replacement_map . insert (
234- instr_name . clone ( ) + ":SRANGE" ,
235- self . format_range (
236- step_channel
264+
265+ let val = self
266+ . get_function_value (
267+ & step_channel
237268 . start_stop_channel
238269 . common_chan_attributes
239- . source_range
240- . clone ( ) ,
241- ) ,
242- ) ;
270+ . source_function ,
271+ )
272+ . clone ( ) ;
273+ self . val_replacement_map
274+ . insert ( instr_name. clone ( ) + ":SFUNCTION" , val) ;
243275
244- self . val_replacement_map . insert (
245- instr_name. clone ( ) + ":MFUNCTION" ,
276+ self . set_source_range (
246277 step_channel
247278 . start_stop_channel
248279 . common_chan_attributes
249- . meas_function
250- . value
251- . to_lowercase ( )
280+ . source_range
252281 . clone ( ) ,
282+ & instr_name,
283+ ) ;
284+
285+ let val = self
286+ . get_function_value (
287+ & step_channel
288+ . start_stop_channel
289+ . common_chan_attributes
290+ . meas_function ,
291+ )
292+ . clone ( ) ;
293+ self . val_replacement_map
294+ . insert ( instr_name. clone ( ) + ":MFUNCTION" , val) ;
295+
296+ self . val_replacement_map . insert (
297+ instr_name. clone ( ) + ":MODE" ,
298+ if step_config. step_global_parameters . list_step {
299+ "LIST" . to_string ( )
300+ } else {
301+ step_channel. start_stop_channel . style . value . clone ( )
302+ } ,
253303 ) ;
254304
255305 //sense mode exists only for SMU
@@ -264,13 +314,14 @@ impl SweepModel {
264314 . common_chan_attributes
265315 . get_name_for ( & sense_mode_key)
266316 {
267- self . val_replacement_map . insert (
268- instr_name. clone ( ) + ":SENSE" ,
269- String :: from ( sense_mode_value) ,
270- ) ;
271- } else {
272- //TODO: error handling for sense mode value not found
317+ self . val_replacement_map
318+ . insert ( instr_name. clone ( ) + ":SENSE" , sense_mode_value. to_owned ( ) ) ;
273319 }
320+ } else {
321+ self . val_replacement_map . insert (
322+ instr_name. clone ( ) + ":SENSE" ,
323+ BaseMetadata :: UNDEFINED . to_string ( ) ,
324+ ) ;
274325 }
275326
276327 //source_limitv exists only for SMU
@@ -312,17 +363,17 @@ impl SweepModel {
312363 ) ;
313364
314365 self . process_list (
315- sweep_config . step_global_parameters . list_step ,
366+ step_config . step_global_parameters . list_step ,
316367 & step_channel. start_stop_channel . list ,
317368 instr_name,
318- sweep_config . step_global_parameters . step_points . value as usize ,
369+ step_config . step_global_parameters . step_points . value as usize ,
319370 ) ;
320371
321372 index += 1 ;
322373 }
323374
324375 let step_count = if !self . attributes . step_names . is_empty ( ) {
325- sweep_config
376+ step_config
326377 . step_global_parameters
327378 . step_points
328379 . value
@@ -332,12 +383,7 @@ impl SweepModel {
332383 } ;
333384
334385 let step_to_sweep_delay = if !self . attributes . step_names . is_empty ( ) {
335- self . format (
336- sweep_config
337- . step_global_parameters
338- . step_to_sweep_delay
339- . value ,
340- )
386+ self . format ( step_config. step_global_parameters . step_to_sweep_delay . value )
341387 } else {
342388 String :: from ( "0" )
343389 } ;
@@ -420,37 +466,54 @@ impl SweepModel {
420466 ) ;
421467
422468 self . val_replacement_map . insert (
423- instr_name. clone ( ) + ":SFUNCTION " ,
469+ instr_name. clone ( ) + ":MODEL-TYPE " ,
424470 sweep_channel
425471 . start_stop_channel
426472 . common_chan_attributes
427- . source_function
428- . value
429- . to_lowercase ( )
430- . clone ( ) ,
473+ . device
474+ . device_type
475+ . to_string ( ) ,
431476 ) ;
432- self . val_replacement_map . insert (
433- instr_name . clone ( ) + ":SRANGE" ,
434- self . format_range (
435- sweep_channel
477+
478+ let val = self
479+ . get_function_value (
480+ & sweep_channel
436481 . start_stop_channel
437482 . common_chan_attributes
438- . source_range
439- . clone ( ) ,
440- ) ,
441- ) ;
483+ . source_function ,
484+ )
485+ . clone ( ) ;
486+ self . val_replacement_map
487+ . insert ( instr_name. clone ( ) + ":SFUNCTION" , val) ;
442488
443- self . val_replacement_map . insert (
444- instr_name. clone ( ) + ":MFUNCTION" ,
489+ self . set_source_range (
445490 sweep_channel
446491 . start_stop_channel
447492 . common_chan_attributes
448- . meas_function
449- . value
450- . to_lowercase ( )
493+ . source_range
451494 . clone ( ) ,
495+ & instr_name,
452496 ) ;
453497
498+ let val = self
499+ . get_function_value (
500+ & sweep_channel
501+ . start_stop_channel
502+ . common_chan_attributes
503+ . meas_function ,
504+ )
505+ . clone ( ) ;
506+ self . val_replacement_map
507+ . insert ( instr_name. clone ( ) + ":MFUNCTION" , val) ;
508+
509+ self . val_replacement_map . insert (
510+ instr_name. clone ( ) + ":MODE" ,
511+ if sweep_config. sweep_global_parameters . list_sweep {
512+ "LIST" . to_string ( )
513+ } else {
514+ sweep_channel. start_stop_channel . style . value . clone ( )
515+ } ,
516+ ) ;
454517 //sense mode exists only for SMU
455518 if let Some ( sense_mode) = & sweep_channel
456519 . start_stop_channel
@@ -463,13 +526,14 @@ impl SweepModel {
463526 . common_chan_attributes
464527 . get_name_for ( & sense_mode_key)
465528 {
466- self . val_replacement_map . insert (
467- instr_name. clone ( ) + ":SENSE" ,
468- String :: from ( sense_mode_value) ,
469- ) ;
470- } else {
471- //TODO: error handling for sense mode value not found
529+ self . val_replacement_map
530+ . insert ( instr_name. clone ( ) + ":SENSE" , sense_mode_value. to_owned ( ) ) ;
472531 }
532+ } else {
533+ self . val_replacement_map . insert (
534+ instr_name. clone ( ) + ":SENSE" ,
535+ BaseMetadata :: UNDEFINED . to_string ( ) ,
536+ ) ;
473537 }
474538
475539 //source_limitv exists only for SMU
0 commit comments