@@ -290,124 +290,124 @@ def get_min_semiperiod_measurement(device_name):
290290 return dtmin
291291 return dtmin
292292
293-
294- capabilities = {}
295- if os .path .exists (CAPABILITIES_FILE ):
296- with open (CAPABILITIES_FILE ) as f :
293+ if __name__ == '__main__' :
294+ capabilities = {}
295+ if os .path .exists (CAPABILITIES_FILE ):
296+ with open (CAPABILITIES_FILE ) as f :
297+ try :
298+ capabilities = json .load (f )
299+ except ValueError :
300+ pass
301+
302+
303+ models = []
304+ for name in DAQmxGetSysDevNames ().split (', ' ):
305+ model = DAQmxGetDevProductType (name )
306+ print ("found device:" , name , model )
307+ if model not in models :
308+ models .append (model )
309+ capabilities [model ] = {}
297310 try :
298- capabilities = json .load (f )
299- except ValueError :
300- pass
301-
302-
303- models = []
304- for name in DAQmxGetSysDevNames ().split (', ' ):
305- model = DAQmxGetDevProductType (name )
306- print ("found device:" , name , model )
307- if model not in models :
308- models .append (model )
309- capabilities [model ] = {}
310- try :
311- capabilities [model ]["supports_buffered_AO" ] = DAQmxGetDevAOSampClkSupported (
312- name
313- )
314- except PyDAQmx .DAQmxFunctions .AttrNotSupportedError :
315- capabilities [model ]["supports_buffered_AO" ] = False
316- try :
317- capabilities [model ]["max_DO_sample_rate" ] = DAQmxGetDevDOMaxRate (name )
318- capabilities [model ]["supports_buffered_DO" ] = True
319- except PyDAQmx .DAQmxFunctions .AttrNotSupportedError :
320- capabilities [model ]["max_DO_sample_rate" ] = None
321- capabilities [model ]["supports_buffered_DO" ] = False
322- if capabilities [model ]["supports_buffered_AO" ]:
323- capabilities [model ]["max_AO_sample_rate" ] = DAQmxGetDevAOMaxRate (name )
324- else :
325- capabilities [model ]["max_AO_sample_rate" ] = None
326-
327- capabilities [model ]["num_AO" ] = len (DAQmxGetDevAOPhysicalChans (name ))
328- capabilities [model ]["num_AI" ] = len (DAQmxGetDevAIPhysicalChans (name ))
329- if capabilities [model ]["num_AI" ] > 0 :
330- single_rate = DAQmxGetDevAIMaxSingleChanRate (name )
331- multi_rate = DAQmxGetDevAIMaxMultiChanRate (name )
332- else :
333- single_rate = None
334- multi_rate = None
335- capabilities [model ]["max_AI_single_chan_rate" ] = single_rate
336- capabilities [model ]["max_AI_multi_chan_rate" ] = multi_rate
337-
338- capabilities [model ]["ports" ] = {}
339- ports = DAQmxGetDevDOPorts (name )
340- chans = DAQmxGetDevDOLines (name )
341- for port in ports :
342- if '_' in port :
343- # Ignore the alternate port names such as 'port0_32' that allow using two or
344- # more ports together as a single, larger one:
345- continue
346- port_info = {}
347- capabilities [model ]["ports" ][port ] = port_info
348- port_chans = [chan for chan in chans if chan .split ('/' )[0 ] == port ]
349- port_info ['num_lines' ] = len (port_chans )
350- if capabilities [model ]["supports_buffered_DO" ]:
351- port_info ['supports_buffered' ] = port_supports_buffered (name , port )
311+ capabilities [model ]["supports_buffered_AO" ] = DAQmxGetDevAOSampClkSupported (
312+ name
313+ )
314+ except PyDAQmx .DAQmxFunctions .AttrNotSupportedError :
315+ capabilities [model ]["supports_buffered_AO" ] = False
316+ try :
317+ capabilities [model ]["max_DO_sample_rate" ] = DAQmxGetDevDOMaxRate (name )
318+ capabilities [model ]["supports_buffered_DO" ] = True
319+ except PyDAQmx .DAQmxFunctions .AttrNotSupportedError :
320+ capabilities [model ]["max_DO_sample_rate" ] = None
321+ capabilities [model ]["supports_buffered_DO" ] = False
322+ if capabilities [model ]["supports_buffered_AO" ]:
323+ capabilities [model ]["max_AO_sample_rate" ] = DAQmxGetDevAOMaxRate (name )
352324 else :
353- port_info [ 'supports_buffered' ] = False
325+ capabilities [ model ][ "max_AO_sample_rate" ] = None
354326
355- capabilities [model ]["num_CI" ] = len (DAQmxGetDevCIPhysicalChans (name ))
356- supports_semiperiod = supports_semiperiod_measurement (name )
357- capabilities [model ]["supports_semiperiod_measurement" ] = supports_semiperiod
358- if capabilities [model ]["num_CI" ] > 0 and supports_semiperiod :
359- min_semiperiod_measurement = get_min_semiperiod_measurement (name )
360- else :
361- min_semiperiod_measurement = None
362- capabilities [model ]["min_semiperiod_measurement" ] = min_semiperiod_measurement
363-
364- if capabilities [model ]['num_AO' ] > 0 :
365- AO_ranges = []
366- raw_limits = DAQmxGetDevAOVoltageRngs (name )
367- for i in range (0 , len (raw_limits ), 2 ):
368- Vmin , Vmax = raw_limits [i ], raw_limits [i + 1 ]
369- AO_ranges .append ([Vmin , Vmax ])
370- # Find range with the largest maximum voltage and use that:
371- Vmin , Vmax = max (AO_ranges , key = lambda range : range [1 ])
372- # Confirm that no other range has a voltage lower than Vmin,
373- # since if it does, this violates our assumptions and things might not
374- # be as simple as having a single range:
375- assert min (AO_ranges )[0 ] >= Vmin
376- capabilities [model ]["AO_range" ] = [Vmin , Vmax ]
377- else :
378- capabilities [model ]["AO_range" ] = None
379-
380- if capabilities [model ]['num_AI' ] > 0 :
381- AI_ranges = []
382- raw_limits = DAQmxGetDevAIVoltageRngs (name )
383- for i in range (0 , len (raw_limits ), 2 ):
384- Vmin , Vmax = raw_limits [i ], raw_limits [i + 1 ]
385- AI_ranges .append ([Vmin , Vmax ])
386- # Restrict to the ranges allowed for non-differential input:
387- AI_ranges = supported_AI_ranges_for_non_differential_input (name , AI_ranges )
388- # Find range with the largest maximum voltage and use that:
389- Vmin , Vmax = max (AI_ranges , key = lambda range : range [1 ])
390- # Confirm that no other range has a voltage lower than Vmin,
391- # since if it does, this violates our assumptions and things might not
392- # be as simple as having a single range:
393- assert min (AI_ranges )[0 ] >= Vmin
394- capabilities [model ]["AI_range" ] = [Vmin , Vmax ]
395- else :
396- capabilities [model ]["AI_range" ] = None
327+ capabilities [model ]["num_AO" ] = len (DAQmxGetDevAOPhysicalChans (name ))
328+ capabilities [model ]["num_AI" ] = len (DAQmxGetDevAIPhysicalChans (name ))
329+ if capabilities [model ]["num_AI" ] > 0 :
330+ single_rate = DAQmxGetDevAIMaxSingleChanRate (name )
331+ multi_rate = DAQmxGetDevAIMaxMultiChanRate (name )
332+ else :
333+ single_rate = None
334+ multi_rate = None
335+ capabilities [model ]["max_AI_single_chan_rate" ] = single_rate
336+ capabilities [model ]["max_AI_multi_chan_rate" ] = multi_rate
337+
338+ capabilities [model ]["ports" ] = {}
339+ ports = DAQmxGetDevDOPorts (name )
340+ chans = DAQmxGetDevDOLines (name )
341+ for port in ports :
342+ if '_' in port :
343+ # Ignore the alternate port names such as 'port0_32' that allow using two or
344+ # more ports together as a single, larger one:
345+ continue
346+ port_info = {}
347+ capabilities [model ]["ports" ][port ] = port_info
348+ port_chans = [chan for chan in chans if chan .split ('/' )[0 ] == port ]
349+ port_info ['num_lines' ] = len (port_chans )
350+ if capabilities [model ]["supports_buffered_DO" ]:
351+ port_info ['supports_buffered' ] = port_supports_buffered (name , port )
352+ else :
353+ port_info ['supports_buffered' ] = False
354+
355+ capabilities [model ]["num_CI" ] = len (DAQmxGetDevCIPhysicalChans (name ))
356+ supports_semiperiod = supports_semiperiod_measurement (name )
357+ capabilities [model ]["supports_semiperiod_measurement" ] = supports_semiperiod
358+ if capabilities [model ]["num_CI" ] > 0 and supports_semiperiod :
359+ min_semiperiod_measurement = get_min_semiperiod_measurement (name )
360+ else :
361+ min_semiperiod_measurement = None
362+ capabilities [model ]["min_semiperiod_measurement" ] = min_semiperiod_measurement
363+
364+ if capabilities [model ]['num_AO' ] > 0 :
365+ AO_ranges = []
366+ raw_limits = DAQmxGetDevAOVoltageRngs (name )
367+ for i in range (0 , len (raw_limits ), 2 ):
368+ Vmin , Vmax = raw_limits [i ], raw_limits [i + 1 ]
369+ AO_ranges .append ([Vmin , Vmax ])
370+ # Find range with the largest maximum voltage and use that:
371+ Vmin , Vmax = max (AO_ranges , key = lambda range : range [1 ])
372+ # Confirm that no other range has a voltage lower than Vmin,
373+ # since if it does, this violates our assumptions and things might not
374+ # be as simple as having a single range:
375+ assert min (AO_ranges )[0 ] >= Vmin
376+ capabilities [model ]["AO_range" ] = [Vmin , Vmax ]
377+ else :
378+ capabilities [model ]["AO_range" ] = None
379+
380+ if capabilities [model ]['num_AI' ] > 0 :
381+ AI_ranges = []
382+ raw_limits = DAQmxGetDevAIVoltageRngs (name )
383+ for i in range (0 , len (raw_limits ), 2 ):
384+ Vmin , Vmax = raw_limits [i ], raw_limits [i + 1 ]
385+ AI_ranges .append ([Vmin , Vmax ])
386+ # Restrict to the ranges allowed for non-differential input:
387+ AI_ranges = supported_AI_ranges_for_non_differential_input (name , AI_ranges )
388+ # Find range with the largest maximum voltage and use that:
389+ Vmin , Vmax = max (AI_ranges , key = lambda range : range [1 ])
390+ # Confirm that no other range has a voltage lower than Vmin,
391+ # since if it does, this violates our assumptions and things might not
392+ # be as simple as having a single range:
393+ assert min (AI_ranges )[0 ] >= Vmin
394+ capabilities [model ]["AI_range" ] = [Vmin , Vmax ]
395+ else :
396+ capabilities [model ]["AI_range" ] = None
397397
398- if capabilities [model ]["num_AI" ] > 0 :
399- capabilities [model ]["AI_start_delay" ] = AI_start_delay (name )
400- else :
401- capabilities [model ]["AI_start_delay" ] = None
398+ if capabilities [model ]["num_AI" ] > 0 :
399+ capabilities [model ]["AI_start_delay" ] = AI_start_delay (name )
400+ else :
401+ capabilities [model ]["AI_start_delay" ] = None
402402
403403
404- with open (CAPABILITIES_FILE , 'w' , newline = '\n ' ) as f :
405- data = json .dumps (capabilities , sort_keys = True , indent = 4 )
406- f .write (data )
404+ with open (CAPABILITIES_FILE , 'w' , newline = '\n ' ) as f :
405+ data = json .dumps (capabilities , sort_keys = True , indent = 4 )
406+ f .write (data )
407407
408- print ("added/updated capabilities for %d models" % len (models ))
409- print ("Total models with known capabilities: %d" % len (capabilities ))
410- for model in capabilities :
411- if model not in models :
412- print (model , 'capabilities not updated' )
413- print ("run generate_subclasses.py to make labscript devices for these models" )
408+ print ("added/updated capabilities for %d models" % len (models ))
409+ print ("Total models with known capabilities: %d" % len (capabilities ))
410+ for model in capabilities :
411+ if model not in models :
412+ print (model , 'capabilities not updated' )
413+ print ("run generate_subclasses.py to make labscript devices for these models" )
0 commit comments