예제 #1
0
def test_wrong_socket_type():

    address = '127.0.0.1'
    port = get_available_port()
    term = b'\r\n'

    t = threading.Thread(target=echo_server_udp, args=(address, port, term))
    t.start()

    time.sleep(0.1)  # allow some time for the echo server to start

    with pytest.raises(MSLConnectionError):
        EquipmentRecord(connection=ConnectionRecord(
            address='TCP::{}::{}'.format(address,
                                         port),  # trying TCP for a UDP server
            backend=Backend.MSL,
            properties=dict(termination=term, timeout=5),
        )).connect()

    record = EquipmentRecord(connection=ConnectionRecord(
        address='UDP::{}::{}'.format(address, port),
        backend=Backend.MSL,
        properties=dict(termination=term, timeout=5),
    ))

    # use the correct socket type to shutdown the server
    dev = record.connect()
    dev.write('SHUTDOWN')
 def set_stage(self):
     MotionControl.build_device_list()
     all_devices = MotionControl.get_device_list()
     recordx = EquipmentRecord(
         manufacturer='Thorlabs',
         model='KST101',
         serial=str(26001683),  # update the serial number for your KST101
         connection=ConnectionRecord(
             backend=Backend.MSL,
             address='SDK::Thorlabs.MotionControl.KCube.StepperMotor.dll',
         ),
     )
     recordy = EquipmentRecord(
         manufacturer='Thorlabs',
         model='KST101',
         serial=str(26001718),  # update the serial number for your KST101
         connection=ConnectionRecord(
             backend=Backend.MSL,
             address='SDK::Thorlabs.MotionControl.KCube.StepperMotor.dll',
         ),
     )
     self.motorx = recordx.connect()
     self.motory = recordy.connect()
     # load the configuration settings (so that we can use the get_real_value_from_device_unit() method)
     try:
         self.motory.load_settings()
         self.motorx.load_settings()
         # start polling at 200 ms
         self.motorx.start_polling(200)
         self.motory.start_polling(200)
         self.motorx.set_homing_velocity(
             204890604
         )  #1.9mm/s, sale de get_device_unit_from_real_value(2,1)
         self.motory.set_homing_velocity(
             204890604
         )  #1.9mm/s, sale de get_device_unit_from_real_value(2,1)
         self.motorx.set_homing_velocity(5392 * 100000)
         self.motory.set_homing_velocity(5392 * 100000)
         self.motorx.home()
         self.motory.home()
         time.sleep(1)
         while self.get_x_y_position() != (0.0000, 0.0000):
             time.sleep(0.1)
         log.info('Stage of stepper motors CONNECTED')
         self.motorx.set_vel_params(204890604, 110485)  # 1.9mm/s, 5mm/s^2
         self.motory.set_vel_params(204890604, 110485)
     except:
         log.error('Can-t load settings')
         self.motorx.start_polling(200)
         self.motory.start_polling(200)
         self.motorx.home()
         self.motory.home()
         time.sleep(1)
         while self.get_x_y_position() != (0.0000, 0.0000):
             time.sleep(0.1)
         log.info('Stage of stepper motors CONNECTED')
     self.motorx.set_motor_velocity_limits(3.0, 10.0)
     self.motory.set_motor_velocity_limits(3.0, 10.0)
     self.motorx.set_vel_params(204890604, 110485)  #1.9mm/s, 5mm/s^2
     self.motory.set_vel_params(204890604, 110485)
예제 #3
0
 def set_stage(self):
     #print('Building the device list...')
     MotionControl.build_device_list()
     #n_devices = MotionControl.get_device_list_size()
     '''if n_devices == 0:
         print('There are no devices in the device list')
         sys.exit(0)
     elif n_devices == 1:
         print('There is 1 device in the device list')
     else:
         print('There are {} devices in the device list'.format(n_devices))'''
     all_devices = MotionControl.get_device_list()
     #print('The serial numbers of all the devices are: {}'.format(all_devices))
     recordx = EquipmentRecord(
         manufacturer='Thorlabs',
         model='KST101',
         serial=str(26001683),  # update the serial number for your KST101
         connection=ConnectionRecord(
             backend=Backend.MSL,
             address='SDK::Thorlabs.MotionControl.KCube.StepperMotor.dll',
         ),
     )
     recordy = EquipmentRecord(
         manufacturer='Thorlabs',
         model='KST101',
         serial=str(26001718),  # update the serial number for your KST101
         connection=ConnectionRecord(
             backend=Backend.MSL,
             address='SDK::Thorlabs.MotionControl.KCube.StepperMotor.dll',
         ),
     )
     #print('The motor in the x direction is the one with serial number # ' + str(26001683))
     #print('The motor in the y direction is the one with serial number # ' + str(26001718))
     self.motorx = recordx.connect()
     self.motory = recordy.connect()
     #print('Connected to {}'.format(self.motorx))
     #print('Connected to {}'.format(self.motory))
     # load the configuration settings (so that we can use the get_real_value_from_device_unit() method)
     try:
         self.motory.load_settings()
         self.motorx.load_settings()
         # start polling at 200 ms
         self.motorx.start_polling(200)
         self.motory.start_polling(200)
         #print('Homing both motors...')
         self.motorx.home()
         self.motory.home()
         #self.wait(0,self.motorx)
         #self.wait(0,self.motory)
         print('Stage connected.')
     except:
         print("Can-t load settings")
         # start polling at 200 ms
         self.motorx.start_polling(200)
         self.motory.start_polling(200)
         #print('Homing both motors...')
         self.motorx.home()
         self.motory.home()
         print('Stage connected.')
예제 #4
0
 def set_x_and_y_motor(self, serialx, serialy):
     recordx = EquipmentRecord(
         manufacturer='Thorlabs',
         model='KST101',
         serial=str(serialx),  # update the serial number for your KST101
         connection=ConnectionRecord(
             backend=Backend.MSL,
             address='SDK::Thorlabs.MotionControl.KCube.StepperMotor.dll',
         ),
     )
     recordy = EquipmentRecord(
         manufacturer='Thorlabs',
         model='KST101',
         serial=str(serialy),  # update the serial number for your KST101
         connection=ConnectionRecord(
             backend=Backend.MSL,
             address='SDK::Thorlabs.MotionControl.KCube.StepperMotor.dll',
         ),
     )
     print('The motor in the x direction is the one with serial number # ' +
           str(serialx))
     print('The motor in the y direction is the one with serial number # ' +
           str(serialy))
     self.motorx = recordx.connect()
     self.motory = recordy.connect()
     print('Connected to {}'.format(self.motorx))
     print('Connected to {}'.format(self.motory))
     # load the configuration settings (so that we can use the get_real_value_from_device_unit() method)
     try:
         self.motory.load_settings()
         self.motorx.load_settings()
         # start polling at 200 ms
         self.motorx.start_polling(200)
         self.motory.start_polling(200)
         print('Homing both motors...')
         self.motorx.home()
         self.motory.home()
         #self.wait(0,self.motorx)
         #self.wait(0,self.motory)
         print('Homing done.')
     except:
         print("Can-t load settings")
         # start polling at 200 ms
         self.motorx.start_polling(200)
         self.motory.start_polling(200)
         print('Homing both motors...')
         self.motorx.home()
         self.motory.home()
         print('Homing done.')
예제 #5
0
def test_dmm1_group():

    # create a record with a model number that is in the _DMM1 group
    record = EquipmentRecord(model='34465A', connection=ConnectionRecord())
    dmm = dmm_factory(record.connection, ConnectionMessageBased)(record)
    cmd = dmm._cmd

    assert cmd('voltage', ACDC='AC', RANGE=None,
               RESOLUTION=None) == 'MEASURE:VOLTAGE:AC?'
    assert cmd('voltage', ACDC='DC', RANGE=None,
               RESOLUTION=None) == 'MEASURE:VOLTAGE:DC?'
    assert cmd('voltage', ACDC='AC', RANGE='AUTO',
               RESOLUTION=None) == 'MEASURE:VOLTAGE:AC? AUTO'
    assert cmd('voltage', ACDC='DC', RANGE='AUTO',
               RESOLUTION=None) == 'MEASURE:VOLTAGE:DC? AUTO'
    assert cmd('voltage', ACDC='AC', RANGE=10,
               RESOLUTION=None) == 'MEASURE:VOLTAGE:AC? 10'
    assert cmd('voltage', ACDC='DC', RANGE=10,
               RESOLUTION=None) == 'MEASURE:VOLTAGE:DC? 10'
    assert cmd('voltage', ACDC='DC', RANGE=0.001,
               RESOLUTION=None) == 'MEASURE:VOLTAGE:DC? 0.001'
    assert cmd('voltage', ACDC='DC', RANGE=0.001,
               RESOLUTION=1e-6) == 'MEASURE:VOLTAGE:DC? 0.001,1e-06'
    assert cmd('voltage', ACDC='DC', RANGE=None,
               RESOLUTION=1e-6) == 'MEASURE:VOLTAGE:DC?'
예제 #6
0
파일: dmm.py 프로젝트: MSLNZ/msl-network
    def __init__(self):
        """Initialize the communication with the digital multimeter.

        This script must be run on a computer that the multimeter is
        physically connected to.
        """

        # Initialize the Service. Set the name of the DigitalMultimeter Service,
        # as it will appear on the Network Manager, to be 'Hewlett Packard 34401A'
        # and specify that only 1 Client on the network can control the digital
        # multimeter at any instance in time. Once the Client disconnects from
        # the Network Manager another Client would then be able to link with the
        # DigitalMultimeter Service to control the digital multimeter.
        super().__init__(name='Hewlett Packard 34401A', max_clients=1)

        # Connect to the digital multimeter
        # (see MSL-Equipment for more details)
        record = EquipmentRecord(
            manufacturer='HP',
            model='34401A',
            connection=ConnectionRecord(
                address='COM4',  # RS232 interface
                backend='MSL',
            ))
        self._dmm = record.connect()
def test_termination_changed():
    c = ConnectionMessageBased(EquipmentRecord(connection=ConnectionRecord()))

    c.encoding = 'cp1252'

    assert isinstance(c.read_termination, bytes)
    assert isinstance(c.write_termination, bytes)
    assert c.read_termination == b'\n'
    assert c.write_termination == b'\r\n'

    c.encoding = 'utf-8'

    term = 'xxx'
    c.read_termination = term
    c.write_termination = term
    assert isinstance(c.read_termination, bytes)
    assert isinstance(c.write_termination, bytes)
    assert c.read_termination == b'xxx'
    assert c.write_termination == b'xxx'

    term = b'yyy'
    c.read_termination = term
    c.write_termination = term
    assert isinstance(c.read_termination, bytes)
    assert isinstance(c.write_termination, bytes)
    assert c.read_termination == term
    assert c.write_termination == term

    c.read_termination = None
    c.write_termination = None
    c.encoding = 'ascii'
    assert c.read_termination is None
    assert c.write_termination is None

    term = 'zzz'.encode('ascii')
    c.read_termination = term
    c.write_termination = term
    assert isinstance(c.read_termination, bytes)
    assert isinstance(c.write_termination, bytes)
    assert c.read_termination == term
    assert c.write_termination == term

    c.read_termination = bytes(bytearray([13, 10]))
    c.write_termination = bytes(bytearray([13]))
    assert isinstance(c.read_termination, bytes)
    assert isinstance(c.write_termination, bytes)
    assert c.read_termination == b'\r\n'
    assert c.write_termination == b'\r'

    # check that the encoding is valid
    assert c.read_termination == b'\r\n'
    assert c.write_termination == b'\r'
    with pytest.raises(LookupError):
        c.encoding = 'unknown'
    c.read_termination = None
    c.write_termination = None
    assert c.read_termination is None
    assert c.write_termination is None
    with pytest.raises(LookupError):
        c.encoding = 'unknown'
def test_termination_converted_to_bytes():
    record = EquipmentRecord(
        connection=ConnectionRecord(
            address='COM6',
            backend='MSL',
            properties={'termination': 'xyz'}
        )
    )
    assert record.connection.properties['termination'] == b'xyz'
예제 #9
0
def test_connection_serial_read():

    term = b'\r\n'

    # simulate a Serial port
    master, slave = pty.openpty()

    thread = threading.Thread(target=echo_server,
                              args=(master, term),
                              daemon=True)
    thread.start()

    time.sleep(0.5)  # allow some time for the echo server to start

    record = EquipmentRecord(connection=ConnectionRecord(
        address='ASRL' + os.ttyname(slave),
        backend=Backend.MSL,
        properties={
            'read_termination': term,
            'write_termination': term,
            'timeout': 25,
        },
    ))

    dev = record.connect()

    assert dev.read_termination == term
    assert dev.write_termination == term

    dev.write('hello')
    assert dev.read() == 'hello'

    n = dev.write('hello')
    assert dev.read(n) == 'hello' + term.decode()

    dev.write('x' * 4096)
    assert dev.read() == 'x' * 4096

    n = dev.write('123.456')
    with pytest.raises(MSLConnectionError):
        dev.read(n + 1)

    with pytest.raises(MSLConnectionError):
        dev.read(dev.max_read_size +
                 1)  # requesting more bytes than are maximally allowed

    msg = 'a' * (dev.max_read_size - len(term))
    dev.write(msg)
    assert dev.read() == msg

    dev.write(b'021.3' + term + b',054.2')
    assert dev.read() == '021.3'  # read until first `term`
    assert dev.read() == ',054.2'  # read until second `term`

    dev.write('SHUTDOWN')
예제 #10
0
def test_udp_socket_read():

    address = '127.0.0.1'
    port = get_available_port()
    term = b'\r\n'

    t = threading.Thread(target=echo_server_udp, args=(address, port, term))
    t.start()

    time.sleep(0.1)  # allow some time for the echo server to start

    record = EquipmentRecord(connection=ConnectionRecord(
        address='UDP::{}::{}'.format(address, port),
        backend=Backend.MSL,
        properties=dict(
            termination=term,  # sets both read_termination and write_termination
            timeout=30),
    ))

    dev = record.connect()

    assert dev.read_termination == term
    assert dev.write_termination == term

    dev.write('hello')
    assert dev.read() == 'hello'

    n = dev.write('hello')
    assert dev.read(n) == 'hello' + term.decode(
    )  # specified `size` so `term` is not removed

    n = dev.write(b'021.3' + term + b',054.2')
    assert dev.read(n) == '021.3' + term.decode() + ',054.2' + term.decode(
    )  # `term` is not removed

    dev.write(b'021.3' + term + b',054.2')
    assert dev.read(3) == '021'
    assert dev.read(5) == '.3' + term.decode() + ','
    assert dev.read(
    ) == '054.2'  # read the rest -- removes the `term` at the end

    dev.write(b'021.3' + term + b',054.2')
    assert dev.read() == '021.3'  # read until first `term`
    assert dev.read() == ',054.2'  # read until second `term`

    n = dev.write('12345')
    assert n == 7
    with pytest.raises(MSLTimeoutError):
        dev.read(n + 1)  # read more bytes than are available
    assert dev.read(n) == '12345' + term.decode()
    assert len(dev.byte_buffer) == 0

    dev.write('SHUTDOWN')
예제 #11
0
def test_tcp_socket_timeout():

    address = '127.0.0.1'
    port = get_available_port()
    write_termination = b'\n'

    t = threading.Thread(target=echo_server_tcp,
                         args=(address, port, write_termination))
    t.start()

    time.sleep(0.1)  # allow some time for the echo server to start

    record = EquipmentRecord(connection=ConnectionRecord(
        address='TCPIP::{}::{}::SOCKET'.format(
            address, port),  # use PyVISA's address convention
        backend=Backend.MSL,
        properties=dict(write_termination=write_termination, timeout=7),
    ))

    dev = record.connect()
    assert dev.timeout == 7
    assert dev.socket.gettimeout() == 7

    dev.timeout = None
    assert dev.timeout is None
    assert dev.socket.gettimeout() is None

    dev.timeout = 0.1
    assert dev.timeout == 0.1
    assert dev.socket.gettimeout() == 0.1

    dev.timeout = 0
    assert dev.timeout is None
    assert dev.socket.gettimeout() is None

    dev.timeout = -1
    assert dev.timeout is None
    assert dev.socket.gettimeout() is None

    dev.timeout = -12345
    assert dev.timeout is None
    assert dev.socket.gettimeout() is None

    dev.timeout = 10
    assert dev.timeout == 10
    assert dev.socket.gettimeout() == 10

    dev.write('SHUTDOWN')
def motor_startup():
    # ensure that the Kinesis folder is available on PATH
    os.environ['PATH'] += os.pathsep + 'C:/Program Files/Thorlabs/Kinesis'

    # rather than reading the EquipmentRecord from a database we can create it manually
    record = EquipmentRecord(
        manufacturer='Thorlabs',
        model='KDC101',
        serial='27002424',  # update the serial number for your KDC101
        connection=ConnectionRecord(
            backend=Backend.MSL,
            address='SDK::Thorlabs.MotionControl.KCube.DCServo.dll'))

    # connect to the KCube DC Servo
    motor = record.connect()
    print('\nConnected to {}'.format(motor))

    # load the configuration settings (so that we can use the get_real_value_from_device_unit() method)
    motor.load_settings()
    return motor
예제 #13
0
def test_connection_serial_timeout():

    term = b'\r\n'

    # simulate a Serial port
    master, slave = pty.openpty()

    thread = threading.Thread(target=echo_server,
                              args=(master, term),
                              daemon=True)
    thread.start()

    time.sleep(0.5)  # allow some time for the echo server to start

    record = EquipmentRecord(connection=ConnectionRecord(
        address='ASRL' + os.ttyname(slave),
        backend=Backend.MSL,
        properties={
            'termination': term,
            'timeout': 21,
        },
    ))

    dev = record.connect()

    assert dev.timeout == 21
    assert dev.serial.timeout == 21
    assert dev.serial.write_timeout == 21

    dev.timeout = None
    assert dev.timeout is None
    assert dev.serial.timeout is None
    assert dev.serial.write_timeout is None

    dev.timeout = 10
    assert dev.timeout == 10
    assert dev.serial.timeout == 10
    assert dev.serial.write_timeout == 10

    dev.write('SHUTDOWN')
예제 #14
0
def test_dmm2_group():

    # create a record with a model number that is in the _DMM2 group
    record = EquipmentRecord(model='3458A', connection=ConnectionRecord())
    dmm = dmm_factory(record.connection, ConnectionMessageBased)(record)
    cmd = dmm._cmd

    assert cmd('voltage', ACDC='AC', RANGE=None, RESOLUTION=None) == 'FUNC ACV'
    assert cmd('voltage', ACDC='DC', RANGE=None, RESOLUTION=None) == 'FUNC DCV'
    assert cmd('voltage', ACDC='AC', RANGE='AUTO',
               RESOLUTION=None) == 'FUNC ACV,AUTO'
    assert cmd('voltage', ACDC='DC', RANGE='AUTO',
               RESOLUTION=None) == 'FUNC DCV,AUTO'
    assert cmd('voltage', ACDC='AC', RANGE=10,
               RESOLUTION=None) == 'FUNC ACV,10'
    assert cmd('voltage', ACDC='DC', RANGE=10,
               RESOLUTION=None) == 'FUNC DCV,10'
    assert cmd('voltage', ACDC='DC', RANGE=0.001,
               RESOLUTION=None) == 'FUNC DCV,0.001'
    assert cmd('voltage', ACDC='DC', RANGE=0.001,
               RESOLUTION=1e-6) == 'FUNC DCV,0.001,1e-06'
    assert cmd('voltage', ACDC='DC', RANGE=None, RESOLUTION=1e-6) == 'FUNC DCV'
def test_encoding_errors():
    cmb = ConnectionMessageBased(
        EquipmentRecord(connection=ConnectionRecord()))

    assert cmb.encoding_errors == 'strict'

    allowed = [
        'strict', 'ignore', 'replace', 'xmlcharrefreplace', 'backslashreplace'
    ]
    if sys.version_info[:2] > (2, 7):
        allowed.append('namereplace')

    for value in allowed:
        cmb.encoding_errors = value
        assert cmb.encoding_errors == value

    for value in allowed:
        cmb.encoding_errors = value.upper()
        assert cmb.encoding_errors == value

    for item in ['doesnotexist', None, '', 888]:
        with pytest.raises(MSLConnectionError):
            cmb.encoding_errors = item
예제 #16
0
"""
Rather than loading a PicoScope from an Equipment-Register database, manually create an 
EquipmentRecord for a PicoScope.
"""
from msl.equipment import EquipmentRecord, ConnectionRecord, Backend

record = EquipmentRecord(
    manufacturer='Pico Technology',
    model='5244B',  # must update the model number for your PicoScope
    serial='DY135/055',  # must update the serial number for your PicoScope
    connection=ConnectionRecord(
        backend=Backend.MSL,
        address='SDK::C:/Program Files/Pico Technology/SDK/lib/ps5000a.dll',
        properties={
            'resolution': '14bit',  # only used for ps5000a series PicoScope's
            'auto_select_power': True,  # for PicoScopes that can be powered by an AC adaptor or by a USB cable
        },
    )
)
예제 #17
0
def test_find_resource_class():

    record = ConnectionRecord(manufacturer='XXX',
                              model='yyy',
                              backend=Backend.MSL)
    cls = resources.find_resource_class(record)
    assert cls is None

    for man in ('Bentham', 'Bentham Instruments Limited',
                'Bentham Instruments Ltd.'):
        for mod in ('TMc300', 'DTMc300'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.bentham.benhw64.Bentham

    for man in (
            'CMI',
            'Czech Metrology Institute',
    ):
        record = ConnectionRecord(manufacturer=man,
                                  model='SIA3',
                                  backend=Backend.MSL)
        cls = resources.find_resource_class(record)
        assert cls == resources.cmi.sia3.SIA3
    for man in (
            'cmi',
            'come in',
    ):
        record = ConnectionRecord(manufacturer=man,
                                  model='SIA3',
                                  backend=Backend.MSL)
        cls = resources.find_resource_class(record)
        assert cls is None

    for man in ('OMEGA', 'omega'):
        for suffix in ('w3', 'd3', 'sd', 'm', 'w', '2'):
            record = ConnectionRecord(manufacturer=man,
                                      model='ithx-' + suffix,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.omega.ithx.iTHX

    for man in ('Pico Tech', 'Pico Technologies', 'Pico Technology'):
        for mod in ('PicoScope 2104', '2104', '2105', '2202', '2203', '2204',
                    '2205', '2204A', '2205A'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.picotech.picoscope.ps2000.PicoScope2000, mod
        for mod in ('PicoScope 2205A MSO', '2205A MSO', '2205 MSO', '2206',
                    '2206A', '2206B', '2206B MSO', '2207', '2207A', '2207B',
                    '2207B MSO', '2208', '2208A', '2208B', '2208B MSO',
                    '2405A', '2406B', '2407B', '2408B'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.picotech.picoscope.ps2000a.PicoScope2000A, mod
        for mod in ('PicoScope 3204', '3204', '3205', '3206', '3224', '3424',
                    '3425'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.picotech.picoscope.ps3000.PicoScope3000, mod
        for mod in (
                'PicoScope 3203D',
                '3203D',
                '3204D',
                '3205D',
                '3206D',
                '3403D',
                '3404D',
                '3405D',
                '3406D',
                '3203D MSO',
                '3204D MSO',
                '3205D MSO',
                '3206D MSO',
                '3403D MSO',
                '3404D MSO',
                '3405D MSO',
                '3406D MSO',
                '3204A',
                '3205A',
                '3206A',
                '3207A',
                '3204B',
                '3205B',
                '3206B',
                '3207B',
                '3204 MSO',
                '3205 MSO',
                '3206 MSO',
                '3404A',
                '3405A',
                '3406A',
                '3404B',
                '3405B',
                '3406B',
        ):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.picotech.picoscope.ps3000a.PicoScope3000A, mod
        for mod in ('PicoScope 4224', '4224', '4224 IEPE', '4262', '4424'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.picotech.picoscope.ps4000.PicoScope4000, mod
        for mod in ('PicoScope 4444', '4444', '4824'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.picotech.picoscope.ps4000a.PicoScope4000A, mod
        for mod in ('PicoScope 5000', '5000'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.picotech.picoscope.ps5000.PicoScope5000, mod
        for mod in ('PicoScope 5242A', '5242A', '5243A', '5244A', '5442A',
                    '5443A', '5444A', '5242B', '5243B', '5244B', '5442B',
                    '5443B', '5444B'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.picotech.picoscope.ps5000a.PicoScope5000A, mod
        for mod in ('PicoScope 6407', '6407', '6402C', '6402D', '6403C',
                    '6403D', '6404C', '6404D'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.picotech.picoscope.ps6000.PicoScope6000, mod
        for mod in ('PT-104', 'PT104'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.picotech.pt104.PT104, mod

    for man in ('Thorlabs', 'Thorlabs Inc.'):
        for mod in ('FW102C', 'FW102CNEB', 'FW212C', 'FW212CNEB'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.thorlabs.fwxx2c.FilterWheelXX2C
        for mod in ('BSC101', 'BSC102', 'BSC103', 'BSC201', 'BSC202',
                    'BSC203'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.thorlabs.kinesis.benchtop_stepper_motor.BenchtopStepperMotor
        for mod in ('MFF101', 'MFF102', 'MFF101/M', 'MFF102/M'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.thorlabs.kinesis.filter_flipper.FilterFlipper
        for mod in ('LTS150', 'LTS150/M', 'LTS300', 'LTS300/M', 'MLJ050/M',
                    'MLJ150', 'MLJ150', 'MLJ150/M'
                    'K10CR1', 'K10CR1/M'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.thorlabs.kinesis.integrated_stepper_motors.IntegratedStepperMotors
        for mod in ('KDC101', ):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.thorlabs.kinesis.kcube_dc_servo.KCubeDCServo
        for mod in ('KSC101', ):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.thorlabs.kinesis.kcube_solenoid.KCubeSolenoid
        for mod in ('KST101', ):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.thorlabs.kinesis.kcube_stepper_motor.KCubeStepperMotor

    for man in ('OptoSigma', 'Opto Sigma', 'SigmaKoki', 'SigmaKoki',
                'Sigma Koki Co. LTD'):
        record = ConnectionRecord(manufacturer=man,
                                  model='SHOT-702',
                                  backend=Backend.MSL)
        cls = resources.find_resource_class(record)
        assert cls == resources.optosigma.shot702.SHOT702

    for man in ('Electron Dynamics', 'Electron Dynamics LTD',
                'Electron Dynamics Ltd.'):
        for mod in ('TC LV', 'TCLV', 'TC M', 'TCM', 'TC M PCB', 'TC M Unit',
                    'TC Lite', 'TClite'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.electron_dynamics.tc_series.TCSeries

    record = ConnectionRecord(manufacturer='Avantes',
                              model='does not matter!',
                              backend=Backend.MSL)
    cls = resources.find_resource_class(record)
    assert cls == resources.avantes.avaspec.Avantes

    for man in ('NKT', 'NKT Photonics', 'NKTPhotonics'):
        for mod in ('Extreme', 'SuperK', 'Koheras BasiK', 'does not matter!'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.nkt.NKT

    record = ConnectionRecord(manufacturer='Princeton Instruments',
                              model='does not matter!',
                              backend=Backend.MSL)
    cls = resources.find_resource_class(record)
    assert cls == resources.princeton_instruments.arc_instrument.PrincetonInstruments

    for man in ('DataRay', 'Data Ray', 'Data Ray Inc.', 'DataRay Inc.'):
        for mod in ('WinCamD', 'S-WCD-LCM-C-1310', 'does not matter!'):
            record = ConnectionRecord(manufacturer=man,
                                      model=mod,
                                      backend=Backend.MSL)
            cls = resources.find_resource_class(record)
            assert cls == resources.dataray.datarayocx_64.DataRayOCX64
예제 #18
0
if __name__ == '__main__':
    import os
    from pprint import pprint

    from msl.equipment import EquipmentRecord, ConnectionRecord, Backend

    # ensure that the Kinesis folder is available on PATH
    os.environ['PATH'] += os.pathsep + 'C:/Program Files/Thorlabs/Kinesis'

    # rather than reading the EquipmentRecord from a database we can create it manually
    record = EquipmentRecord(
        manufacturer='Thorlabs',
        model='LTS150/M',  # update the model number for your Integrated Stepper Motor
        serial='45870601',  # update the serial number for your Integrated Stepper Motor
        connection=ConnectionRecord(
            backend=Backend.MSL,
            address='SDK::Thorlabs.MotionControl.IntegratedStepperMotors.dll',
        ),
    )

    def wait(value):
        motor.clear_message_queue()
        message_type, message_id, _ = motor.wait_for_message()
        while message_type != 2 or message_id != value:
            position = motor.get_position()
            print('  at position {} [device units]'.format(position))
            message_type, message_id, _ = motor.wait_for_message()

    # connect to the Integrated Stepper Motor
    motor = record.connect()
    print('Connected to {}'.format(motor))
예제 #19
0
Example showing how to communicate with a PR4000B Flow and Pressure
controller from MKS Instruments.
"""

# this "if" statement is used so that Sphinx does not execute this script when the docs are being built
if __name__ == '__main__':
    from msl.equipment import EquipmentRecord, ConnectionRecord
    from msl.equipment.constants import Parity, DataBits

    record = EquipmentRecord(
        manufacturer='MKS Instruments',
        model='PR4000BF2V2',
        connection=ConnectionRecord(
            address='COM3',  # change for your device
            baud_rate=9600,  # change for your device
            parity=Parity.ODD,  # change for your device
            termination=b'\r',
            timeout=5,
            data_bits=DataBits.SEVEN,
        ))

    # connect to the controller
    mks = record.connect()

    # get the identity of the controller
    identity = mks.identity()
    print('Identity: {}'.format(identity))

    # reset to the default pressure configuration
    mks.default('pressure')

    # set the pressure range for channel 2 to be 133 Pa
예제 #20
0
Example showing how to communicate with a SuperK Fianium laser using the NKT SDK.
"""

# this "if" statement is used so that Sphinx does not execute this script when the docs are being built
if __name__ == '__main__':
    import time

    from msl.equipment import EquipmentRecord, ConnectionRecord, Backend

    record = EquipmentRecord(
        manufacturer='NKT',
        model='SuperK Fianium',  # change for your device
        connection=ConnectionRecord(
            address='COM6',  # change for your computer
            backend=Backend.MSL,
            # When installing the SDK a NKTP_SDK_PATH environment variable is created
            # and this variable is used to specify the path to the dll file. However, you
            # can also explicitly specify the location of the dll file.
            properties={'sdk_path': r'D:\NKTPDLL.dll'},
        ))

    DEVICE_ID = 15

    # Connect to the SuperK laser
    nkt = record.connect()

    # Get some info about the SuperK
    print('The status of the SuperK: {!r}'.format(nkt.get_port_status()))
    print('The following modules are available in the device:')
    for module, DEVICE_ID in nkt.get_modules().items():
        print('  ModuleType={} DeviceID={}'.format(module, DEVICE_ID))
        print('    Status bits: {}'.format(
예제 #21
0
"""
This example shows how to communicate with Thorlabs FW102C Series or
FW212C Series Motorized Filter Wheels.
"""

# this "if" statement is used so that Sphinx does not execute this script when the docs are being built
if __name__ == '__main__':
    from msl.equipment import EquipmentRecord, ConnectionRecord, Backend

    # rather than reading the EquipmentRecord from a database we can create it manually
    record = EquipmentRecord(
        manufacturer='Thorlabs',
        model='FW212C',  # specify FW102C is you are using the 6-position filter wheel (can also include the NEB suffix)
        connection=ConnectionRecord(
            backend=Backend.MSL,
            address='SDK::C:/Program Files/Thorlabs/FilterWheel102_win64.dll',  # update the location of the DLL
            properties={'port': 'COM4'},  # update the port number
        ),
    )

    # connect to the Filter Wheel
    wheel = record.connect()

    position = wheel.get_position()
    print('The initial filter position was {}'.format(position))

    # make the Filter Wheel return to the start position if it is at the last position
    if position == wheel.get_position_count():
        position = 0

    wheel.set_position(position+1)
예제 #22
0
def test_equivalent_to_importing_nidaqmx():
    record = EquipmentRecord(
        connection=ConnectionRecord(
            backend=Backend.NIDAQ
        )
    )

    daq = record.connect(demo=False)

    assert daq.CtrFreq == nidaqmx.CtrFreq
    assert daq.CtrTick == nidaqmx.CtrTick
    assert daq.CtrTime == nidaqmx.CtrTime
    assert daq.DaqError == nidaqmx.DaqError
    assert daq.DaqResourceWarning == nidaqmx.DaqResourceWarning
    assert daq.DaqWarning == nidaqmx.DaqWarning
    assert daq.Scale == nidaqmx.Scale
    assert daq.Task == nidaqmx.Task
    assert daq.constants == nidaqmx.constants
    assert daq.errors == nidaqmx.errors
    assert daq.stream_readers == stream_readers
    assert daq.stream_writers == stream_writers
    assert daq.system == nidaqmx.system
    assert daq.types == nidaqmx.types
    assert daq.utils == nidaqmx.utils

    for item in dir(nidaqmx.constants):
        if item.startswith('_'):
            continue
        assert getattr(daq.constants, item) == getattr(nidaqmx.constants, item)

    for item in dir(nidaqmx.errors):
        if item.startswith('_'):
            continue
        assert getattr(daq.errors, item) == getattr(nidaqmx.errors, item)

    for item in dir(stream_readers):
        if item.startswith('_'):
            continue
        assert getattr(daq.stream_readers, item) == getattr(stream_readers, item)

    for item in dir(stream_writers):
        if item.startswith('_'):
            continue
        assert getattr(daq.stream_writers, item) == getattr(stream_writers, item)

    for item in dir(nidaqmx.system):
        if item.startswith('_'):
            continue
        assert getattr(daq.system, item) == getattr(nidaqmx.system, item)

    for item in dir(nidaqmx.system.system):
        if item.startswith('_'):
            continue
        assert getattr(daq.system.system, item) == getattr(nidaqmx.system.system, item)

    for item in dir(nidaqmx.types):
        if item.startswith('_'):
            continue
        assert getattr(daq.types, item) == getattr(nidaqmx.types, item)

    for item in dir(nidaqmx.utils):
        if item.startswith('_'):
            continue
        assert getattr(daq.utils, item) == getattr(nidaqmx.utils, item)
예제 #23
0
    import os
    from pprint import pprint

    from msl.equipment import EquipmentRecord, ConnectionRecord, Backend
    from msl.equipment.resources.thorlabs import MotionControl

    # ensure that the Kinesis folder is available on PATH
    os.environ['PATH'] += os.pathsep + 'C:/Program Files/Thorlabs/Kinesis'

    # rather than reading the EquipmentRecord from a database we can create it manually
    record = EquipmentRecord(
        manufacturer='Thorlabs',
        model='KST101',
        serial='26000908',  # update the serial number for your KST101
        connection=ConnectionRecord(
            backend=Backend.MSL,
            address='SDK::Thorlabs.MotionControl.KCube.StepperMotor.dll',
        ),
    )

    def wait():
        motor.clear_message_queue()
        while True:
            status = motor.convert_message(*motor.wait_for_message())['id']
            if status == 'Homed' or status == 'Moved':
                break
            position = motor.get_position()
            real = motor.get_real_value_from_device_unit(position, 'DISTANCE')
            print('  at position {} [device units] {:.3f} [real-world units]'.
                  format(position, real))

    # avoid the FT_DeviceNotFound error
예제 #24
0
# this "if" statement is used so that Sphinx does not execute this script when the docs are being built
if __name__ == '__main__':
    import pprint

    try:
        import matplotlib.pyplot as plt
    except ImportError:
        plt = None

    from msl.equipment import EquipmentRecord, ConnectionRecord, Backend

    record = EquipmentRecord(
        manufacturer='DataRay',
        model='WinCamD',
        connection=ConnectionRecord(
            address='SDK::DATARAYOCX',
            backend=Backend.MSL,
        ),
    )

    # connect to the camera
    # NOTE: a GUI will be displayed (the GUI must remain open
    #       to have full access to the DataRay OCX library).
    camera = record.connect()

    # wait until we finish configuring the camera
    # (e.g, setting the ROI, the number of averages, ...)
    camera.wait_to_configure()

    # capture an image (could be an average of N images)
    info = camera.capture()
예제 #25
0
if __name__ == '__main__':
    import os
    from pprint import pprint

    from msl.equipment import EquipmentRecord, ConnectionRecord, Backend

    # ensure that the Kinesis folder is available on PATH
    os.environ['PATH'] += os.pathsep + 'C:/Program Files/Thorlabs/Kinesis'

    # rather than reading the EquipmentRecord from a database we can create it manually
    record = EquipmentRecord(
        manufacturer='Thorlabs',
        model='KDC101',
        serial='27002424',  # update the serial number for your KDC101
        connection=ConnectionRecord(
            backend=Backend.MSL,
            address='SDK::Thorlabs.MotionControl.KCube.DCServo.dll',
        ),
    )

    def wait(value):
        motor.clear_message_queue()
        message_type, message_id, _ = motor.wait_for_message()
        while message_type != 2 or message_id != value:
            position = motor.get_position()
            real = motor.get_real_value_from_device_unit(position, 'DISTANCE')
            print('  at position {} [device units] {} [real-world units]'.format(position, real))
            message_type, message_id, _ = motor.wait_for_message()

    # connect to the KCube DC Servo
    motor = record.connect()
    print('\nConnected to {}\n'.format(motor))
예제 #26
0
    import os
    import time
    from pprint import pprint

    from msl.equipment import EquipmentRecord, ConnectionRecord, Backend

    # ensure that the Kinesis folder is available on PATH
    os.environ['PATH'] += os.pathsep + 'C:/Program Files/Thorlabs/Kinesis'

    # rather than reading the EquipmentRecord from a database we can create it manually
    record = EquipmentRecord(
        manufacturer='Thorlabs',
        model='BSC201',
        serial='40876748',  # update the serial number for your BSC201
        connection=ConnectionRecord(
            address='SDK::Thorlabs.MotionControl.Benchtop.StepperMotor.dll',
            backend=Backend.MSL,
        )
    )

    def wait(value):
        motor.clear_message_queue(channel)
        message_type, message_id, _ = motor.wait_for_message(channel)
        while message_type != 2 or message_id != value:
            position = motor.get_position(channel)
            print('  at position {} [device units]'.format(position))
            message_type, message_id, _ = motor.wait_for_message(channel)

    # connect to the Benchtop Stepper Motor
    motor = record.connect()
    print('Connected to {}'.format(motor))
예제 #27
0
        print('DeviceStatusCallback: {}'.format(
            (port, dev_id, status, data_length, data)))

    # Load the SDK before before connecting to the laser just to see the PortStatusCallback messages.
    # When installing the SDK a NKTP_SDK_PATH environment variable is created
    # and this variable specifies the path of the dll file. However, you
    # can also explicitly specify the path of the dll file. For example, you
    # can use NKT.load_sdk() to automatically find the DLL file.
    NKT.load_sdk('D:/NKTPDLL.dll')
    NKT.set_callback_port_status(port_callback)

    record = EquipmentRecord(
        manufacturer='NKT',
        model='SuperK Fianium',  # change for your device
        connection=ConnectionRecord(
            address='COM9',  # change for your computer
            backend=Backend.MSL,
        ))

    # Connect to the laser
    nkt = record.connect()

    # You can also use the "nkt" object to set the callbacks
    nkt.set_callback_register_status(register_callback)
    nkt.set_callback_device_status(device_callback)

    device_id = 15

    # Check the Interlock status
    ilock = nkt.register_read_u16(device_id, 0x32)
    print('Interlock OK? {}'.format(ilock == 2))
    if ilock == 1:  # then requires an interlock reset
예제 #28
0
This example opens the connection in async mode (does not work properly in Python 2.7).
"""

# this "if" statement is used so that Sphinx does not execute this script when the docs are being built
if __name__ == '__main__':

    import time
    from msl.equipment import EquipmentRecord, ConnectionRecord, Backend

    record = EquipmentRecord(
        manufacturer='Pico Technology',
        model='5244B',
        serial='DY135/055',
        connection=ConnectionRecord(
            backend=Backend.MSL,
            address='SDK::ps5000a',
            properties={'open_async': True},  # opening in async mode is done in the properties
        )
    )

    start = time.time()

    scope = record.connect()
    while True:
        now = time.time()
        progress = scope.open_unit_progress()
        print('Progress: {}%'.format(progress))
        if progress == 100:
            break
        time.sleep(0.02)
예제 #29
0
Example showing how to communicate with an MX100TP DC power supply.
"""

# this "if" statement is used so that Sphinx does not execute this script when the docs are being built
if __name__ == '__main__':
    import time

    from msl.equipment import EquipmentRecord, ConnectionRecord, Backend

    record = EquipmentRecord(
        manufacturer='Aim-TTi',
        model='MX100TP',
        connection=ConnectionRecord(
            address='TCP::192.168.1.70::9221',  # if using the LAN port
            # address='COM5',  # if using the USB or RS232 port
            # address='Prologix::192.168.1.71::1234::6',  # if using a Prologix GPIB-ETHERNET Controller
            backend=Backend.MSL,
            timeout=5,
        ))

    # the Output channel
    channel = 1

    # establish the connection to the DC power supply
    tti = record.connect()

    # turn Output 1 on and set the voltage of Output 1 to 0.1 Volts
    tti.turn_on(channel)
    tti.set_voltage(channel, 0.1)
    print('The output voltage for Output 1 is: ', tti.get_voltage(channel))
예제 #30
0
if __name__ == '__main__':
    import os
    import time

    from msl.equipment import EquipmentRecord, ConnectionRecord, Backend

    # ensure that the Kinesis folder is available on PATH
    os.environ['PATH'] += os.pathsep + 'C:/Program Files/Thorlabs/Kinesis'

    # rather than reading the EquipmentRecord from a database we can create it manually
    record = EquipmentRecord(
        manufacturer='Thorlabs',
        model='MFF101/M',  # specify MFF102 if you have the 2" version
        serial='37871232',  # update the serial number for your MFF
        connection=ConnectionRecord(
            backend=Backend.MSL,
            address='SDK::Thorlabs.MotionControl.FilterFlipper.dll',
        ),
    )

    # connect to the Filter Flipper
    flipper = record.connect()
    print('Connected to {}'.format(flipper))

    # wait a little bit for the Thorlabs SDK to open the serial port
    time.sleep(1)

    # start polling at 200 ms
    flipper.start_polling(200)

    position = flipper.get_position()
    print('Flipper is at position {}'.format(position))