-
-
Notifications
You must be signed in to change notification settings - Fork 274
migrate siglent power backend vxi11 -> pyvisa, add power show/config options #1926
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
Open
Rubusch
wants to merge
6
commits into
labgrid-project:master
Choose a base branch
from
Rubusch:lothar/siglent
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
efe6826
driver: power: siglent: migrate driver to pyvisa
Rubusch ee9e9b8
driver: power: add show and config options
Rubusch af5b198
Driver: power: read and report measured power
Thomas-Vreys 6b23014
driver: power: siglent: add tests and documentation
Thomas-Vreys 36ab887
Merge pull request #1 from Thomas-Vreys/siglent-extension
Rubusch 75b4ab0
Merge branch 'master' into lothar/siglent
Rubusch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,62 @@ | ||
| """tested with Siglent SPD3303X-E, and should be compatible with all SPD3000X series modules""" | ||
| """ tested with Siglent SPD3303X-E, SPD1168X and should be compatible with all SPD3000X series modules """ | ||
|
|
||
| import warnings | ||
|
|
||
| import vxi11 | ||
| import pyvisa | ||
|
|
||
| def _get_psu(host): | ||
| """Helper to initialize the raw network socket resource session via PyVISA.""" | ||
| rm = pyvisa.ResourceManager("@py") | ||
| resource_string = f"TCPIP0::{host}::5025::SOCKET" | ||
| psu = rm.open_resource(resource_string) | ||
| # Siglent scopes and PSUs require explicit newline termination on raw sockets | ||
| psu.read_termination = "\n" | ||
| psu.write_termination = "\n" | ||
| psu.timeout = 5000 # 5 second safety timeout | ||
| return psu | ||
|
|
||
| def power_set(host, port, index, value): | ||
| warnings.warn( | ||
| "siglent power backend uses vxi11 module using deprecated xdrlib module, see https://github.com/labgrid-project/labgrid/issues/1507", | ||
| DeprecationWarning, | ||
| ) | ||
|
|
||
| assert port is None | ||
| index = int(index) | ||
| assert 1 <= index <= 2 | ||
| value = "ON" if value else "OFF" | ||
| psu = vxi11.Instrument(host) | ||
| psu.write(f"OUTPUT CH{index},{value}") | ||
|
|
||
| with _get_psu(host) as psu: | ||
| psu.write(f"OUTPUT CH{index},{value}") | ||
|
|
||
| def power_get(host, port, index): | ||
| warnings.warn( | ||
| "siglent power backend uses vxi11 module using deprecated xdrlib module, see https://github.com/labgrid-project/labgrid/issues/1507", | ||
| DeprecationWarning, | ||
| ) | ||
|
|
||
| assert port is None | ||
| index = int(index) | ||
| assert 1 <= index <= 2 | ||
| psu = vxi11.Instrument(host) | ||
| state = psu.ask("SYSTEM:STATUS?") | ||
| with _get_psu(host) as psu: | ||
| state = psu.query("SYSTEM:STATUS?") | ||
| state = int(state, 16) | ||
| bitmask = 1 << (index + 3) | ||
| return bool(state & bitmask) | ||
|
|
||
| def power_show(host, port, index): | ||
| assert port is None | ||
| index = int(index) | ||
| assert 1 <= index <= 2 | ||
| with _get_psu(host) as psu: | ||
| v_measured = psu.query(f"MEAS:VOLT? CH{index}") | ||
| a_measured = psu.query(f"MEAS:CURR? CH{index}") | ||
| v_set = psu.query(f"CH{index}:VOLT?") | ||
| a_set = psu.query(f"CH{index}:CURR?") | ||
| return { | ||
| "voltage": float(v_measured), | ||
| "amps": float(a_measured), | ||
| "v_limit": float(v_set), | ||
| "a_limit": float(a_set) | ||
| } | ||
|
|
||
| def power_voltage(host, port, index, voltage): | ||
| assert port is None | ||
| index = int(index) | ||
| assert 1 <= index <= 2 | ||
| with _get_psu(host) as psu: | ||
| psu.write(f"CH{index}:VOLT {voltage}") | ||
|
|
||
| def power_amps(host, port, index, amps): | ||
| assert port is None | ||
| index = int(index) | ||
| with _get_psu(host) as psu: | ||
| psu.write(f"CH{index}:CURR {amps}") | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,17 @@ def off(self): | |
| @abc.abstractmethod | ||
| def cycle(self): | ||
| raise NotImplementedError | ||
|
|
||
|
|
||
| class ProgrammablePowerProtocol(PowerProtocol): | ||
| @abc.abstractmethod | ||
| def show(self, index): | ||
| raise NotImplementedError | ||
|
|
||
| @abc.abstractmethod | ||
| def voltage(self, index, voltage): | ||
| raise NotImplementedError | ||
|
|
||
| @abc.abstractmethod | ||
| def amps(self, index, amps): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is 'current' not more suiteable i.s.o. amps? |
||
| raise NotImplementedError | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could power (W) also be added? Some PowerSupplies (also Siglent) do allow this.
Reading Voltage and Current and multiply it in software will introduce and error because the time difference between the two reads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vermaete : I'll try to have a look into it this weekend and push something, after that I'm travelling for around four weeks. So, in general "amps" -> "current" and "power" in [W]. Let me know if something else is missing. I have to have a look into our siglent material here, let's see. ty
@Bastian-Krause : There seems to be some interest in this. Pls, what should I additionally need to provide as test and documentation here? Can you point me to something similar/driver you'd like to see? If not, I might figure out and come up with anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Rubusch Thomas-Vreys did some work on your fork and has created a PR with some of the remarks solved.
Thomas will be available at Wednesday to continue with it, if needed.
We do have some power-supplies to test this.
Thanks for the useful Labgrid feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vermaete I merged this. I had a look at my hardware, unfortunately I cannot verify power readings. So, I appreaciate the effort. Thanks.
I still agree in "current" being more suitable than "amps". Now, I did not like to change before merging and currently busy/travelling. Shall I still add a commit to rename it, or can we live with that as is? I think to user interface it exposes "current".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for merging. Naming as it is now is fine for me.