Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/princetoninstruments #994

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

NitramC
Copy link

@NitramC NitramC commented Dec 13, 2023

Driver for the Princeton Instruments SP2300i spectrograph/monochromator.

It's a weirdly designed instrument... when connected via RS232 the commands are echoed back. Also, the instrument will not return the termination character until the command has been fully processed (sometimes 10's of seconds). The routes I took around these issues are a bit hacky, but hopefully it's still a useful starting point.

Copy link
Member

@BenediktBurger BenediktBurger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for your contribution.

A few comments for the first round.

It is the second instrument to use pint, see #929 for the first one.

Some solutions might have to be discussed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is a new manufacturer, you have to add this file to the parent folder's index.rst as well, see https://pymeasure.readthedocs.io/en/latest/dev/adding_instruments/instrument.html#adding-documentation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some protocol tests, especially as the instrument seems to need some hacks. For the tests, see https://pymeasure.readthedocs.io/en/latest/dev/adding_instruments/tests.html#protocol-tests


# RAD_TO_COUNTS inferred from default INIT-OFFSET values and three grating
# positions on a turret.
RAD_TO_COUNTS = 4_608_000/(2*np.pi) # [counts/rad]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I've never seen a number defined with underscores.

By the way, it is good practice (mandated by some PEP) to have spaces around operators:

Suggested change
RAD_TO_COUNTS = 4_608_000/(2*np.pi) # [counts/rad]
RAD_TO_COUNTS = 4_608_000 / (2 * np.pi) # [counts/rad]

Comment on lines +119 to +120
kwargs.setdefault('write_termination', '\r')
kwargs.setdefault('read_termination', '\r\n')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can include these into the asrl dictionary as well with the same effects.

'stop_bits': pyvisa.constants.StopBits.one,
'parity': pyvisa.constants.Parity.none,
},
**kwargs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add, whether the device supports SCPI or not (includeSCPI parameter).

Comment on lines +208 to +222
def write_bytes(self):
"""Not implemented -- use adapter method."""
raise NotImplementedError("Use adapter method")

def read_bytes(self):
"""Not implemented -- use adapter method."""
raise NotImplementedError("Use adapter method")

def write_binary_values(self):
"""Not implemented -- use adapter method."""
raise NotImplementedError("Use adapter method")

def read_binary_values(self):
"""Not implemented -- use adapter method."""
raise NotImplementedError("Use adapter method")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove these blocking methods.

Set as a pint compatible value.
""",
get_process=lambda v: ureg.Quantity(v), # convert to quantity
set_process=lambda v: ureg.Quantity(v).m_as('nm/min'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For ease of use, could you add some method, which assumes the correct unit, for example something like:

def generate_magnitude_extractor(units)
    def get_quantity_magnitude(value):
        if isinstance(value, ureg.Quantity):
            return value.m_as(units)
        else:
            return value
    return get_quantity_magnitude


scan_rate = Instrument.control(...
    set_process=generate_magnitude_extractor("nm/min")

That will make it easier to use for people who do not use pint (yet).

For another instrument with pint, see #929

Comment on lines +286 to +287
# GRATING
# ?GRATING
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's already in the control defined, you do not need to repeat it in front.

# ?GRATING
grating = Instrument.control(
"?GRATING", "%d GRATING",
"""Control grating being used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Control grating being used.
"""Control which grating to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants