Ejemplo n.º 1
0
from visa import ResourceManager


class A34970A:
    def __init__(self, address):
        rm = ResourceManager()
        self.device = rm.open_resource(address)
        idn = self.query('*IDN?')
        assert '34970A' in idn, 'invalid device identity: %s' % idn

    def query(self, cmd):
        self.device.write(cmd)
        return self.device.read()

    def get_temperature(self, slot, channel):
        address = slot * 100 + channel
        return float(self.query('MEAS:TEMP? THER,10000,(@%d)' % address))


if __name__ == "__main__":
    from ben.devices import run_device_service
    device = A34970A('GPIB0::9::INSTR')
    run_device_service(device, 'agilent34970a')
Ejemplo n.º 2
0
    def wait_and_return(self):
        while not self.command_done():
            sleep(0.1)

        data = self.read_buffer()
        if len(data) == 1:
            return data[0]
        return data

    def command_done(self):
        """Check whether the device has finished the last command"""
        return self.read('*OPC?') == '1'

    def write(self, cmd):
        """Send one or multiple commands to the device"""
        if isinstance(cmd, (tuple, list)):
            self.device.write(';'.join(cmd))
        else:
            self.device.write(cmd)

    def abort(self):
        """Abort the current command"""
        self.write(':ABORT')


if __name__ == "__main__":
    from ben.devices import run_device_service
    device = CNT90('GPIB0::10::INSTR')
    run_device_service(device, 'cnt90')
Ejemplo n.º 3
0
    @span.setter
    def span(self, value):
        self.device.write('FREQ:SPAN %f' % value)
    
    @property
    def center_frequency(self):
        return float(self.query('FREQ:CENTER?'))
    
    @center_frequency.setter
    def center_frequency(self, value):
        self.device.write('FREQ:CENTER %f' % value)
    
    def read_spectrum(self):
        self.device.write('FORMAT ASCII')
        return [float(v) for v in self.query('TRAC1? TRACE1').split(',')]
    
    @property
    def x_axis(self):
        half_span = self.span / 2
        return list(np.linspace(
            self.center_frequency - half_span,
            self.center_frequency + half_span,
            N_POINTS
        ))


if __name__ == "__main__":
    from ben.devices import run_device_service
    device = RSSpectrumAnalyzer('192.168.1.29')
    run_device_service(device, 'rs-fsl')
Ejemplo n.º 4
0
            self.device.write(';'.join(cmd))
        else:
            self.device.write(cmd)

    def set_laser_current(self, value):
        self.write('LAS:LDI %f' % value)

    def get_laser_current(self):
        return float(self.read('LAS:LDI?'))

    def set_current_enabled(self, value):
        self.write('LAS:OUT %d' % (1 if value else 0))

    def get_current_enabled(self):
        return self.read('LAS:OUT?')

    def get_current_limit_3724C(self):
        return float(self.read('LAS:LIM:I2?'))

    def get_laser_voltage(self):
        return float(self.read('LAS:LDV?'))

    def set_current_limit_3724C(self, value):
        self.write('LAS:LIM:I2 %f' % value)


if __name__ == "__main__":
    from ben.devices import run_device_service
    device = ILX('GPIB0::1::INSTR')
    run_device_service(device, 'ilx')
Ejemplo n.º 5
0
    @property
    def span(self):
        return float(self.device.query('SP?'))

    @span.setter
    def span(self, value):
        return self.device.write('SP %f' % value)

    @property
    def units(self):
        return self.device.query('AUNITS?')

    @property
    def x_axis(self):
        cf = self.center_frequency
        span = self.span
        return np.linspace(cf - span / 2, cf + span / 2, AXIS_LENGTH)

    def acquire(self):
        return [
            float(value) for value in self.device.query('TRA?').replace(
                '\r\n', '').split(',')
        ]


if __name__ == "__main__":
    from ben.devices import run_device_service
    device = HP8951A()
    run_device_service(device, 'hp8951a')