def main(pulsestreamer_ip='192.168.178.128'):
    """ This is the main function of the example.
        Parameters: 
            pulsestreamer_ip -  IP address of the Pulse Streamer.
                                The default value corresponds to the
                                direct connection of the Pulse Streamer 
                                to the network card of your PC.
    """

    # import API classes into the current namespace
    from pulsestreamer import PulseStreamer

    # connect to the Pulse Streamer
    ps = PulseStreamer(pulsestreamer_ip)

    # create a sequence-object
    sequence = ps.createSequence()

    # parameters for FCS pattern
    n_cells = 10
    em_counts = 1000
    meas_window = 1e9 # in ns, 1s
    pass_time = 1e5 # in ns, 100us

    # generate new pattern every second and stream
    while True:
        # generate and assign the pattern to a digital output of PS
        patt1 = pattFCS(n_cells, em_counts, meas_window, pass_time)
        sequence.setDigital(1, patt1)
        ps.stream(sequence, 1)
Exemplo n.º 2
0
 def on_activate(self):
     """
     Establish connection to pulse streamer and tell it to
     cancel all operations
     """
     self.pulse_streamer = PulseStreamer(self._pulsestreamer_ip)
     self.pulser_off()
     self.current_status = 0
Exemplo n.º 3
0
 def __init__(self, address = '169.254.8.2'):
     """
     Uses the pulsestreamer python package which can be installed at:
         https://www.swabianinstruments.com/downloads/
         (pulsestreamer-1.1.0-py2.py3-none-any.whl)
     Following user manual:
         https://www.swabianinstruments.com/static/documentation/PulseStreamer/PulseStreamer_User_Manual.pdf
     Connects via the permanent static fallback ip address: 169.254.8.2  
     Licence is
     """
     self.ip = address
     self.ps = PulseStreamer(self.ip)
     self.block =[]
     self.blockchain = self.ps.createSequence()
Exemplo n.º 4
0
def main(pulsestreamer_ip='192.168.178.128'):
    """ This is the main function of the example.
        Parameters: 
            pulsestreamer_ip -  IP address of the Pulse Streamer.
                                The default value corresponds to the
                                direct connection of the Pulse Streamer 
                                to the network card of your PC.
    """

    # import API classes into the current namespace
    from pulsestreamer import PulseStreamer

    # connect to the Pulse Streamer
    ps = PulseStreamer(pulsestreamer_ip)
    ps.reset()

    # create a sequence-object
    sequence = ps.createSequence()

    # choose your parameters
    # approximate fluorescence lifetime
    # non-dimentional normalized factor
    # multiply by "window" to get lifetime in ns
    exp_tau = 0.37
    # window is period between laser pulses
    # for Time Tagger 20 choose window >= 500 ns (below 2 MHz at 1 channel)
    # for Time Tagger Ultra choose window >= 50 ns (below 20 MHz at 1 channel)
    window = 1000  # ns
    # repeat = repetitions per one pattern
    repeat = 1000

    hold = 0.2  # seconds
    n_runs = PulseStreamer.REPEAT_INFINITELY
    # generate new patterns interminably
    # and hold each new pattern for time "hold"
    while (True):
        # TRFL pattern for channels 1 and 2
        pattern1 = TRFLpattern(exp_tau, window, repeat)
        pattern2 = LASERpattern(window, repeat)
        # antibunching pattern for channels 3 and 4
        antibunching = ANTIBpattern(int(window / 10), repeat)
        pattern3 = antibunching[0]
        pattern4 = antibunching[1]
        # assign the pattern to the digital channels
        sequence.setDigital(1, pattern1)
        sequence.setDigital(2, pattern2)
        sequence.setDigital(3, pattern3)
        sequence.setDigital(4, pattern4)
        # stream the sequence and repeat it infinitely
        sleep(hold)
        ps.stream(sequence, n_runs)
Exemplo n.º 5
0
def main(pulsestreamer_ip='192.168.178.128'):
    """ This is the main function of the example.
        Parameters: 
            pulsestreamer_ip -  IP address of the Pulse Streamer.
                                The default value corresponds to the
                                direct connection of the Pulse Streamer 
                                to the network card of your PC.
    """

    # import API classes into the current namespace
    from pulsestreamer import PulseStreamer

    # connect to the Pulse Streamer
    ps = PulseStreamer(pulsestreamer_ip)

    # parameters for pattern generation
    tau_base = 200  # ns
    laser_period = 1000  # ns
    pixel_period = 1000000  # ns
    pixels = 100

    # create a sequence-object
    sequence = ps.createSequence()

    # generate and assign the seeding patterns to the digital outputs of PS
    photon = [(1, 0)]
    laser = [(1, 0)]
    pixel = [(1, 0)]
    sync = [(1, 1)]
    sequence.setDigital(1, photon)
    sequence.setDigital(2, laser)
    sequence.setDigital(3, pixel)
    sequence.setDigital(4, sync)

    # generate different patterns for each pixel
    for pix in range(pixels):
        # create a sequence-object
        new_sequence = ps.createSequence()
        # generate next FLIM patterns for PS
        pl_lifetime = tau_base + rnd.randint(0, 300)
        photon, laser, pixel = genFLIM(pl_lifetime, laser_period, pixel_period)
        sync = [(pixel_period + 1, 0)]
        # assign the new patterns to the digital outputs of PS
        new_sequence.setDigital(1, photon)
        new_sequence.setDigital(2, laser)
        new_sequence.setDigital(3, pixel)
        new_sequence.setDigital(4, sync)
        # add the new_sequence to sequence
        sequence = sequence + new_sequence

    # stream the sequence infinitely
    n_runs = PulseStreamer.REPEAT_INFINITELY
    ps.stream(sequence, n_runs)
Exemplo n.º 6
0
def main(pulsestreamer_ip='192.168.178.128'):
    """ This is the main function of the example.
        Parameters: 
            pulsestreamer_ip -  IP address of the Pulse Streamer.
                                The default value corresponds to the
                                direct connection of the Pulse Streamer 
                                to the network card of your PC.
    """

    # import Pulse Streamer API into the current namespace
    from pulsestreamer import PulseStreamer

    # connect to the Pulse Streamer
    ps = PulseStreamer(pulsestreamer_ip)

    # create a sequence-object
    sequence = ps.createSequence()

    # choose parameters
    # las_f - laser repetition rate in MHz
    # pl_tau - fluorescence lifetime in ns
    # patt_ln is length of one pattern
    las_f = 80
    pl_tau = 4
    patt_ln = 1000

    hold = 0.2 # seconds
    runs = PulseStreamer.REPEAT_INFINITELY
    ps.stream(sequence, runs)
    while True:
        # generate patterns
        pattern1 = PHOTONpattern(las_f, pl_tau, patt_ln)
        pattern2 = LASERpattern(las_f, patt_ln)
        # assign the patterns to digital channels
        sequence.setDigital(1, pattern1)
        sequence.setDigital(2, pattern2)
        sleep(hold)
        ps.stream(sequence, runs)
Exemplo n.º 7
0
tagger = createTimeTagger()
tagger.reset()

CLICK_CH = 2  # the actual signal from APD or SNSPD
START_CH = 3
END_CH = DelayedChannel(tagger, START_CH, 100 * 1000)  # 300 nS, unit is P

tagger.setTriggerLevel(CLICK_CH, 0.2)  # trigger level 0.2
tagger.setTriggerLevel(START_CH, 0.2)  # trigger level 0.2
#tagger.setTestSignal(1, True) # if using internal test pulses
#tagger.setTestSignal(2, True) # if using internal test pulses

# set up pulse streammer
ip_hostname = '169.254.8.2'
pulser = PulseStreamer(ip_hostname)
HIGH = 1
LOW = 0


def all_zero(pulser):
    """setting Pulsestreamer constant (LOW)"""
    pulser.constant(OutputState.ZERO())


all_zero(pulser)

ch_532 = 1  # output channel 0
ch_apd_start = 4  # output channel 4
#ch_apdtime          = 0 # output channel 4
Exemplo n.º 8
0
class Pulser(Base, PulserInterface):
    """ Methods to control PulseStreamer.

    Example config for copy-paste:

    pulser:
        module.Class: 'kolkowitz.pulse_streamer.Pulser'
        pulsestreamer_ip: '128.104.160.11'
        clock_channel: 0
        counter_gate_channel: 2
        aom_channel: 3
        rf_channel: 4

    """
    _modclass = 'pulserinterface'
    _modtype = 'hardware'

    _low = 0
    _high = 1

    _pulsestreamer_ip = ConfigOption('pulsestreamer_ip',
                                     '128.104.160.11',
                                     missing='warn')
    _clock_channel = ConfigOption('clock_channel', 0, missing='warn')
    _counter_gate_channel = ConfigOption('counter_gate_channel',
                                         2,
                                         missing='warn')
    _green_aom_channel = ConfigOption('green_aom_channel', 3, missing='warn')
    _uw_gate_channel = ConfigOption('uw_gate_channel', 4, missing='warn')

    def __init__(self, config, **kwargs):
        super().__init__(config=config, **kwargs)

        if 'pulsed_file_dir' in config.keys():
            self.pulsed_file_dir = config['pulsed_file_dir']

            if not os.path.exists(self.pulsed_file_dir):
                homedir = get_home_dir()
                self.pulsed_file_dir = os.path.join(homedir, 'pulsed_files')
                self.log.warning(
                    'The directory defined in parameter '
                    '"pulsed_file_dir" in the config for '
                    'PulseStreamer does not exist!\n'
                    'The default home directory\n{0}\n will be taken '
                    'instead.'.format(self.pulsed_file_dir))
        else:
            homedir = get_home_dir()
            self.pulsed_file_dir = os.path.join(homedir, 'pulsed_files')
            self.log.warning(
                'No parameter "pulsed_file_dir" was specified in the config for '
                'PulseStreamer as directory for the pulsed files!\nThe default home '
                'directory\n{0}\nwill be taken instead.'.format(
                    self.pulsed_file_dir))

        self.current_status = -1
        self.sample_rate = 1e9
        self.current_loaded_asset = None

    def get_constraints(self):
        """
        Retrieve the hardware constrains from the Pulsing device.

        @return PulserConstraints: dict with constraints for the sequence
            generation and GUI
        """
        constraints = PulserConstraints()

        # The file formats are hardware specific.
        constraints.waveform_format = ['pstream']
        constraints.sequence_format = []

        constraints.sample_rate.min = 1e9
        constraints.sample_rate.max = 1e9
        constraints.sample_rate.step = 0
        constraints.sample_rate.default = 1e9

        constraints.d_ch_low.min = 0.0
        constraints.d_ch_low.max = 0.0
        constraints.d_ch_low.step = 0.0
        constraints.d_ch_low.default = 0.0

        constraints.d_ch_high.min = 3.3
        constraints.d_ch_high.max = 3.3
        constraints.d_ch_high.step = 0.0
        constraints.d_ch_high.default = 3.3

        # Sample file length max is not well-defined for PulseStreamer,
        # which collates sequential identical pulses into one.
        # Total number of not-sequentially-identical pulses which
        # can be stored is 10^6.
        constraints.waveform_length.min = 1
        constraints.waveform_length.max = 134217728
        constraints.waveform_length.step = 1
        constraints.waveform_length.default = 1

        # the name a_ch<num> and d_ch<num> are generic names, which describe UNAMBIGUOUSLY the
        # channels. Here all possible channel configurations are stated, where only the generic
        # names should be used. The names for the different configurations can be customary chosen.
        activation_config = OrderedDict()
        activation_config['all'] = [
            'd_ch1', 'd_ch2', 'd_ch3', 'd_ch4', 'd_ch5', 'd_ch6', 'd_ch7',
            'd_ch8'
        ]
        constraints.activation_config = activation_config

        return constraints

    def on_activate(self):
        """
        Establish connection to pulse streamer and tell it to
        cancel all operations
        """
        self.pulse_streamer = PulseStreamer(self._pulsestreamer_ip)
        self.pulser_off()
        self.current_status = 0

    def on_deactivate(self):
        """
        Break the connection to the pulse streamer.
        """
        del self.pulse_streamer

    def pulser_on(self):
        """
        Switches the pulsing device on.

        @return int: error code (0:OK, -1:error)
        """

        # start the pulse sequence
        self.pulse_streamer.startNow()
        self.current_status = 1
        return 0

    def pulser_off(self):
        """
        Switches the pulsing device off.

        @return int: error code (0:OK, -1:error)
        """

        # stop the pulse sequence
        #channels = self._convert_to_bitmask([self._laser_channel, self._uw_x_channel])
        self.pulse_streamer.constant(state=OutputState.ZERO())
        self.current_status = 0
        return 0

    def write_sequence(self, sequence, numRepeat):
        """
        Streams a sequence. It'll start when you call pulser_on.

        @param Sequence sequence: The sequence to stream
        @param int numRepeat: Number of times to stream the sequence, -1 for infinite

        @return int: error code (0:OK, -1:error)
        """

        self._sequence = sequence
        self._num_repeat = numRepeat

        # Set the PulseStreamer to start as soon as it receives the stream from
        # from the computer
        self.pulse_streamer.setTrigger(start=TriggerStart.SOFTWARE,
                                       rearm=TriggerRearm.AUTO)

        # Run the stream
        self.pulse_streamer.stream(self._sequence, self._num_repeat)
        self.log.info('Asset uploaded to PulseStreamer')

        return 0

    def load_asset(self, asset_name, load_dict=None):
        """ Loads a sequence or waveform to the specified channel of the pulsing
            device.

        @param str asset_name: The name of the asset to be loaded

        @param dict load_dict:  a dictionary with keys being one of the
                                available channel numbers and items being the
                                name of the already sampled
                                waveform/sequence files.
                                Examples:   {1: rabi_Ch1, 2: rabi_Ch2}
                                            {1: rabi_Ch2, 2: rabi_Ch1}
                                This parameter is optional. If none is given
                                then the channel association is invoked from
                                the sequence generation,
                                i.e. the filename appendix (_Ch1, _Ch2 etc.)

        @return int: error code (0:OK, -1:error)
        """

        self.log.error(
            'Reading from files is not yet implemented with the latest client lib.'
        )
        return -1
Exemplo n.º 9
0
class PulseStreamer_simple():  

    def __init__(self, address = '169.254.8.2'):
        """
        Uses the pulsestreamer python package which can be installed at:
            https://www.swabianinstruments.com/downloads/
            (pulsestreamer-1.1.0-py2.py3-none-any.whl)
        Following user manual:
            https://www.swabianinstruments.com/static/documentation/PulseStreamer/PulseStreamer_User_Manual.pdf
        Connects via the permanent static fallback ip address: 169.254.8.2  
        Licence is
        """
        self.ip = address
        self.ps = PulseStreamer(self.ip)
        self.block =[]
        self.blockchain = self.ps.createSequence()
        
    def create_block(self, block=[('duration', 'level'),(1000, 1)]):
        """
        Creates a single block pattern using run time encoding, takes (duration, level) in ns and V        
        """
        self.block = block
        return block
        
    def load_digital (self, channel, block):
        """
        adds block to blockchain to a given channel
        """
        self.blockchain.setDigital(channel, block)

    def load_analog (self, channel, block):
        """
        adds block to blockchain to a given channel
        """
        self.blockchain.setAnalog(channel, block)

        
    def stream(self, n_runs= PulseStreamer.REPEAT_INFINITELY):
        """
        Sends pulse sequence object (blockchain) to Pulse Streamer
        sequence repeated n_runs times
        """
        self.ps.stream(self.blockchain, n_runs)
    
    def plot_blockchain(self):
        """
        plots whole of blockchain
            * would be good to plot a single block or just digital (only works for Matlab)
        """
        self.blockchain.plot()
        
    def isrunning(self):
        """
        returns yes if Pulse Streamer is running, no otherwise
        """
        if (self.ps.isStreaming()==1):
            print('Yes')
        else:
            print('No') 
            
    def upload_stream_dictionary (self, stream_dict):
        
        for i in range (8):
            self.load_digital (channel = i, block = stream_dict['D'+str(i)])
        
        for i in range (2):
            self.load_analog (channel = i, block = stream_dict['A'+str(i)])

       
    def reset(self):
        """
        resets Pulse Streamer to default state
        all outputs are set to 0V
        does not clear loaded pulses
        """
        self.ps.reset()
        
    def id (self):
        print ("\nSerial number: \n", self.ps.getSerial())
        print("\nFirmware version: \n", self.ps.getFirmwareVersion())
        print("\nIP address: \n", self.ip)