VXI11 lock handling - #633
Conversation
for more information, see https://pre-commit.ci
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #633 +/- ##
==========================================
+ Coverage 44.78% 48.19% +3.40%
==========================================
Files 31 33 +2
Lines 5468 5625 +157
Branches 534 545 +11
==========================================
+ Hits 2449 2711 +262
+ Misses 2987 2865 -122
- Partials 32 49 +17
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
releasing this for merge. hislip is more effort, will come in a next PR. |
| - Request a lock via ``inst.lock_excl()``. This is the most portable. See above. | ||
| - Configure the lock timeout via the PyVISA-Py specific ``rm.visalib.sessions[inst.session].lock_timeout``. |
There was a problem hiding this comment.
Why do you need to poke at the internals here ? I would prefer to not encourage such uses.
Since Keysight make use of a non standard attribute to control this parameter, we could do the same. This ways internals are not exposed.
There was a problem hiding this comment.
well, it was like that, so I left it. But yes, I prefer the keysight way.
BUT: then we also need to adapt pyvisa, since it is pyvisa that would expose that specific attribute to the user. It is not a standard attribute.
There was a problem hiding this comment.
I do not have all the code within easy reach to check but since pyvisa mostly forward directly to the library for get/set attribute we may be able to to define the extra args outside PyVISA.
There was a problem hiding this comment.
sure, can be done, the other attributes are 'hard coded' in pyvisa/constants.py. They do not refer to the backends.
Not a big issue, but then we'll have to make sure to catch any mismatching package versions.
There was a problem hiding this comment.
I'll work on something. For now, only in pyvisa-py. And making sure it can live with outdated pyvisa.
| # TODO determine how OP_FLAG_WAIT_BLOCK could be set from the outside. | ||
| # VPP-4.3 does not provide a clear definition for it. | ||
| # For now, we derive it from self.lock_timeout. | ||
| lock_timeout = self.lock_timeout | ||
| if lock_timeout != constants.VI_TMO_IMMEDIATE: | ||
| flags |= vxi11.OP_FLAG_WAIT_BLOCK | ||
|
|
There was a problem hiding this comment.
This could be factored out in a helper.
MatthieuDartiailh
left a comment
There was a problem hiding this comment.
I would expect changes to be required for serial and USB for locking when opening. And for those and GPIB since locking does not do anything we should reject non default value.
|
Implemented VI_KTATTR_LOCKWAIT, removed lock_timeout. It is all limited it to vxi-11 |
|
In fact, VPP-4.3 states that all types should support locking, both exclusive locks and shared locks, AND nested locking. For exclusive locks, VXI-11 and HiSLIP instruments handle that themselves (maybe also vicp and vxi?). |
|
Now I need to work on the timeout of the remote/local functions |
I realize this was silly since serial is by definition a unique connection and USBTMC and GPIB are likely the same. I will make another more thorough review but I think are nearly good. |
|
merged. |
MatthieuDartiailh
left a comment
There was a problem hiding this comment.
Some small comments
| flags = 0 | ||
| flags, lock_timeout = self._adapt_flags_and_lock_timeout(flags) | ||
|
|
||
| # XXX make this nicer (either validate protocol or pass it) |
There was a problem hiding this comment.
Not sure this comment still applies
| ``VI_KTATTR_LOCKWAIT`` may not be available yet in pyvisa. In that case, you could do this: | ||
|
|
||
| >>> import pyvisa | ||
| >>> rm = pyvisa.ResourceManager('@py') | ||
| >>> inst = rm.open_resource('TCPIP::192.168.1.100::INSTR') | ||
| >>> | ||
| >>> # Define the raw hex constant for VI_KTATTR_LOCKWAIT | ||
| >>> VI_KTATTR_LOCKWAIT = 0x0FFF002BL | ||
| >>> | ||
| >>> # Set lockwait to True (VI_TRUE = 1) | ||
| >>> inst.set_attribute(VI_KTATTR_LOCKWAIT, 1) | ||
| >>> # Read back the attribute value | ||
| >>> lockwait_val = inst.get_attribute(VI_KTATTR_LOCKWAIT) | ||
| >>> print("Lockwait state:", lockwait_val) | ||
| >>> | ||
| >>> # Do your operations |
There was a problem hiding this comment.
Why do you need this since we force set this attribute?
There was a problem hiding this comment.
Otherwise you get this: NameError: name 'VI_KTATTR_LOCKWAIT' is not defined
It needs to be added to pyvisa.constants
There was a problem hiding this comment.
oops. you're right. WIll correct the faq.
| #: Time to wait in ms before erroring with a timeout when trying to acquire a lock | ||
| lock_timeout: int = 10000 | ||
| # 0 = immediate, >0 = wait for that many milliseconds | ||
| # This is used for most operations (mainly except open_resource and lock_excl) | ||
| # | ||
| # NI-VISA and R&S VISA do not expose any of this. | ||
| # Keysight exposes the Keysight-specific VISA ViBoolean local (per-session) attribute VI_KTATTR_LOCKWAIT | ||
| # When False, when already locked, immediately returns VI_ERROR_RSRC_LOCKED | ||
| # When True, uses lock timeout = session timeout interval. When locked and timed out, returns VI_ERROR_TMO | ||
| # lock_timeout: int = 0 |
There was a problem hiding this comment.
This whole paragraph seems out of place.
There was a problem hiding this comment.
yes, will remove the comments
Why
This allows more compliant lock handling on VXI-11.
pre-commitwith no errors