Exemplo n.º 1
0
def one_item_multi_values():
    """Sample for a command that answers with one item (e.g. axis) and a different number of values."""
    with GCSDevice() as pidevice:
        answer = pidevice.ReadGCSCommand('FOO? 1 2 3')
        # This will return:
        # 1 = 1.23 4 7 8
        # 2 = 2.00 5 9
        # 3 = 3.45 6

        gcscommands.getdict_oneitem(answer, items=None, itemconv=int, valueconv=(float, int))
Exemplo n.º 2
0
def one_item_one_value():
    """Sample for a command that answers with one item (e.g. axis) and one value."""
    with GCSDevice() as pidevice:
        answer = pidevice.ReadGCSCommand('FOO? 1 2 3')
        # This will return:
        # 1 = 1.23
        # 2 = 2.00
        # 3 = 3.45

        # There is a helper function to get a dict of this answer.

        gcscommands.getdict_oneitem(answer, items=None)
        # Answer: {'1': '1.23', '2': '2.00', '3': '3.45'}
        # Remember, all keys and values are strings because the function
        # does not now how to convert.

        gcscommands.getdict_oneitem(answer, items=None, itemconv=int)
        # Answer: {1: '1.23', 2: '2.00', 3: '3.45'}
        # Now the keys are int.

        gcscommands.getdict_oneitem(answer,
                                    items=None,
                                    itemconv=int,
                                    valueconv=(float, ))
        # Answer: {1: 1.23, 2: 2.0, 3: 3.45}
        # Now the keys are int and the values are float.
        # Remember the 'valueconv' argument must be a list or a tuple!

        gcscommands.getdict_oneitem(answer,
                                    items=None,
                                    itemconv=int,
                                    valueconv=(True, ))
Exemplo n.º 3
0
def one_item_two_values():
    """Sample for a command that answers with one item (e.g. axis) and two values."""
    with GCSDevice() as pidevice:
        answer = pidevice.ReadGCSCommand('FOO? 1 2 3')
        # This will return:
        # 1 = 1.23 4
        # 2 = 2.00 5
        # 3 = 3.45 6

        gcscommands.getdict_oneitem(answer, items=None)
        # Answer: {'1': ['1.23', '4'], '2': ['2.00', '5'], '3': ['3.45', '6']}
        # Remember, all keys and values are strings because the function
        # does not now how to convert.

        gcscommands.getdict_oneitem(answer, items=None, itemconv=int, valueconv=(float, int))