from . import bbn
import auspex.config
from auspex.log import logger
from QGL import *
ChannelLibrary()

def pulse_marker(marker_name, length = 100e-9):
    """ Utility to generate a square pulse on a APS2 marker. Used for instance to switch a signal between spectrum analyzer and input line
    marker_name as defined in measure.yaml """
    settings =  auspex.config.load_meas_file(auspex.config.find_meas_file())
    mkr = settings['markers'][marker_name]
    marker = MarkerFactory(marker_name)
    APS_name = mkr.split()[0]
    APS = bbn.APS2()
    APS.connect(settings['instruments'][APS_name]['address'])
    APS.set_trigger_source('Software')
    seq = [[TRIG(marker,length)]]
    APS.set_seq_file(compile_to_hardware(seq, 'Switch\Switch').replace('meta.json', APS_name+'.h5'))
    APS.run()
    APS.trigger()
    APS.stop()
    APS.disconnect()
    logger.info('Switched marker {} ({})'.format(marker_name, mkr))

from . import bbn
import auspex.config
from auspex.log import logger

def pulse_marker(marker_name, length = 100e-9):
    """ Utility to generate a square pulse on a APS2 marker. Used for instance to switch a signal between spectrum analyzer and input line
    marker_name as defined in measure.yaml """

    from QGL import *
    ChannelLibrary()
    
    settings =  auspex.config.load_meas_file(auspex.config.find_meas_file())
    mkr = settings['markers'][marker_name]
    marker = MarkerFactory(marker_name)
    APS_name = mkr.split()[0]
    APS = bbn.APS2()
    APS.connect(settings['instruments'][APS_name]['address'])
    APS.set_trigger_source('Software')
    seq = [[TRIG(marker,length)]]
    APS.set_seq_file(compile_to_hardware(seq, 'Switch\Switch').replace('meta.json', APS_name+'.h5'))
    APS.run()
    APS.trigger()
    APS.stop()
    APS.disconnect()
    logger.info('Switched marker {} ({})'.format(marker_name, mkr))

Move QGL import inside function
Move QGL import inside function

A channel library is not always available

  from . import bbn
  import auspex.config
  from auspex.log import logger
- from QGL import *
- ChannelLibrary()
  
  def pulse_marker(marker_name, length = 100e-9):
      """ Utility to generate a square pulse on a APS2 marker. Used for instance to switch a signal between spectrum analyzer and input line
      marker_name as defined in measure.yaml """
+ 
+     from QGL import *
+     ChannelLibrary()
+     
      settings =  auspex.config.load_meas_file(auspex.config.find_meas_file())
      mkr = settings['markers'][marker_name]
      marker = MarkerFactory(marker_name)
      APS_name = mkr.split()[0]
      APS = bbn.APS2()
      APS.connect(settings['instruments'][APS_name]['address'])
      APS.set_trigger_source('Software')
      seq = [[TRIG(marker,length)]]
      APS.set_seq_file(compile_to_hardware(seq, 'Switch\Switch').replace('meta.json', APS_name+'.h5'))
      APS.run()
      APS.trigger()
      APS.stop()
      APS.disconnect()
      logger.info('Switched marker {} ({})'.format(marker_name, mkr))
  
Move QGL import inside function
## Code Before:
from . import bbn
import auspex.config
from auspex.log import logger
from QGL import *
ChannelLibrary()

def pulse_marker(marker_name, length = 100e-9):
    """ Utility to generate a square pulse on a APS2 marker. Used for instance to switch a signal between spectrum analyzer and input line
    marker_name as defined in measure.yaml """
    settings =  auspex.config.load_meas_file(auspex.config.find_meas_file())
    mkr = settings['markers'][marker_name]
    marker = MarkerFactory(marker_name)
    APS_name = mkr.split()[0]
    APS = bbn.APS2()
    APS.connect(settings['instruments'][APS_name]['address'])
    APS.set_trigger_source('Software')
    seq = [[TRIG(marker,length)]]
    APS.set_seq_file(compile_to_hardware(seq, 'Switch\Switch').replace('meta.json', APS_name+'.h5'))
    APS.run()
    APS.trigger()
    APS.stop()
    APS.disconnect()
    logger.info('Switched marker {} ({})'.format(marker_name, mkr))

## Instruction:
Move QGL import inside function
## Code After:
from . import bbn
import auspex.config
from auspex.log import logger

def pulse_marker(marker_name, length = 100e-9):
    """ Utility to generate a square pulse on a APS2 marker. Used for instance to switch a signal between spectrum analyzer and input line
    marker_name as defined in measure.yaml """

    from QGL import *
    ChannelLibrary()
    
    settings =  auspex.config.load_meas_file(auspex.config.find_meas_file())
    mkr = settings['markers'][marker_name]
    marker = MarkerFactory(marker_name)
    APS_name = mkr.split()[0]
    APS = bbn.APS2()
    APS.connect(settings['instruments'][APS_name]['address'])
    APS.set_trigger_source('Software')
    seq = [[TRIG(marker,length)]]
    APS.set_seq_file(compile_to_hardware(seq, 'Switch\Switch').replace('meta.json', APS_name+'.h5'))
    APS.run()
    APS.trigger()
    APS.stop()
    APS.disconnect()
    logger.info('Switched marker {} ({})'.format(marker_name, mkr))
