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

Small addition to allow context managers #23

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

Conversation

orgua
Copy link

@orgua orgua commented Feb 9, 2022

main problem I had: faulty scripts leave the SMU in a weird state - so restarting the script often fails at basic tasks (like accessing keithley.smua) because the TSP-Commant-Set wasn't read successfully (or other weird behavior).

i added the option to use this module in a context and haven't had the problem since. This way of accessing remote devices allows to automatically disconnect on exceptions.

with Keithley2600(f"TCPIP0::{smu_ip}::INSTR") as kth:
    kth.reset()
    smu = kth.smua
    smu.sense = smu.SENSE_REMOTE
    smu.source.limiti = current_A
    smu.source.autorangev = smu.AUTORANGE_ON
    smu.source.func = smu.OUTPUT_DCVOLTS
    smu.measure.autozero = smu.AUTOZERO_AUTO
    smu.measure.autorangei = smu.AUTORANGE_ON
    smu.measure.nplc = 16
    smu.source.levelv = voltage_V
    smu.source.output = smu.OUTPUT_ON

add support for "with ..." context-manager
Copy link
Member

@samschott samschott left a comment

Choose a reason for hiding this comment

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

This looks good to me. Could also add some documentation about using the object as a context manager? The doc string should probably be fine.

keithley2600/keithley_driver.py Show resolved Hide resolved
@orgua
Copy link
Author

orgua commented Sep 23, 2022

Sorry, i got no notification about new messages in this thread :(
I added a doc-string and extended the main readme with the example.

@orgua orgua requested a review from samschott September 24, 2022 13:57
@orgua
Copy link
Author

orgua commented Jan 8, 2024

Any chance that it gets ever mainlined? It's a small but helpful feature for cleaner and more pythonic code.

@orgua
Copy link
Author

orgua commented Jul 22, 2024

Is there a reason to stall this? Your requested changes were implemented almost 2 years ago. i rather prefer that this PR is closed if it is unwanted so I can delete my fork.

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.

2 participants