-
Notifications
You must be signed in to change notification settings - Fork 73
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
Keithley 195A #307
Comments
Well, it looks like this issue permeates to a lot of functions. I can't do a measure, a read, set the input range. For example:
By the way, this value I do get with the query command is correct. I have about 147 ohms connected to the meter. So I think the communication is good, it's just the parsing string vs bytes problem. |
Looks like it might be a VISA issue, either on our end or pyvisa updated
and we're not compatible
I'll see what I can do
…On Wed, Jun 30, 2021, 6:09 AM Chris Lott ***@***.***> wrote:
Well, it looks like this issue permeates to a lot of functions. I can't do
a measure, a read, set the input range. For example:
(venv) ***@***.*** gpib$ python
Python 3.7.3 (default, Jun 30 2021, 13:45:48)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import instruments as ik
/files/gpib/venv/lib/python3.7/site-packages/visa.py:23: FutureWarning: The visa module provided by PyVISA is being deprecated. You can replace `import visa` by `import pyvisa as visa` to achieve the same effect.
The reason for the deprecation is the possible conflict with the visa package provided by the https://github.com/visa-sdk/visa-python which can result in hard to debug situations.
FutureWarning,
>>> dmm = ik.keithley.Keithley195.open_visa('GPIB0::5::INSTR')
>>> dmm.mode = dmm.Mode.resistance
>>> dmm.measure()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/keithley/keithley195.py", line 267, in measure
mode = self.mode
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/keithley/keithley195.py", line 97, in mode
return self.parse_status_word(self.get_status_word())['mode']
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/keithley/keithley195.py", line 306, in parse_status_word
terminator) = ***@***.***', statusword[4:])
TypeError: a bytes-like object is required, not 'str'
>>> print(dmm.measure(dmm.Mode.resistance))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/keithley/keithley195.py", line 261, in measure
current_mode = self.mode
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/keithley/keithley195.py", line 97, in mode
return self.parse_status_word(self.get_status_word())['mode']
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/keithley/keithley195.py", line 306, in parse_status_word
terminator) = ***@***.***', statusword[4:])
TypeError: a bytes-like object is required, not 'str'
>>> dmm.input_range
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/keithley/keithley195.py", line 195, in input_range
index = self.parse_status_word(self.get_status_word())['range']
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/keithley/keithley195.py", line 306, in parse_status_word
terminator) = ***@***.***', statusword[4:])
TypeError: a bytes-like object is required, not 'str'
>>> dmm.input_range = 2000
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/keithley/keithley195.py", line 216, in input_range
mode = self.mode
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/keithley/keithley195.py", line 97, in mode
return self.parse_status_word(self.get_status_word())['mode']
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/keithley/keithley195.py", line 306, in parse_status_word
terminator) = ***@***.***', statusword[4:])
TypeError: a bytes-like object is required, not 'str'
>>> dmm.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/abstract_instruments/instrument.py", line 164, in read
return self._file.read(size, encoding)
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/abstract_instruments/comm/abstract_comm.py", line 209, in read
return self.read_raw(size).decode(encoding)
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/abstract_instruments/comm/visa_communicator.py", line 134, in read_raw
msg = self._buf + self._conn.read()
TypeError: can't concat str to bytearray
>>> dmm.query('?')
'+0.14725E+3'
>>> dmm.write('F2X')
>>> dmm.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/abstract_instruments/instrument.py", line 164, in read
return self._file.read(size, encoding)
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/abstract_instruments/comm/abstract_comm.py", line 209, in read
return self.read_raw(size).decode(encoding)
File "/files/gpib/venv/lib/python3.7/site-packages/instruments/abstract_instruments/comm/visa_communicator.py", line 134, in read_raw
msg = self._buf + self._conn.read()
TypeError: can't concat str to bytearray
>>> dmm.query('?')
'+0.14710E+3'
>>>
By the way, this value I do get with the query command is correct. I have
about 147 ohms connected to the meter. So I think the communication is
good, it's just the parsing string vs bytes problem.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#307 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAL3S6OZROIZEXO65BQGB5LTVLUOFANCNFSM47R6TIHQ>
.
|
It seems very close to the issue addressed in #262. But those corrections aren’t formally incorporated into a release yet. I wonder if I goofed up trying to install from the HEAD |
Yeah try uninstalling the version from pypi first, then try `pip install -e
.`
…On Wed, Jun 30, 2021 at 10:31 AM Chris Lott ***@***.***> wrote:
It seems very close to the issue addressed in #262
<#262>. But those
corrections aren’t formally incorporated into a release yet. I wonder if I
goofed up trying to install from the HEAD
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#307 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAL3S6OTELGIGSUSFCQYCELTVMTD3ANCNFSM47R6TIHQ>
.
--
Steven Casagrande, MSc
Waterloo, Ontario
|
I was at first surprised surprised that dmm.sendcmd('U0DX')
retval = dmm._file.read_raw()
print(f"retval: {retval}")
print(f"type: {type(retval)}") and post the output? Really curious what comes back form the Keithley. I don't have one of those around, but quoting @scasagrande from #262:
|
Sure. Just woke up (crack of dawn here in South Korea). I’ll send the results shortly. BTW, I am able to communicate and operate the meter directly from pyvisa, if that helps any. |
|
In the IK in the def read_raw(self, size=-1):
"""
Read bytes in from the pyVISA connection.
:param int size: The number of bytes to read in from the VISA
connection.
:return: The read bytes from the VISA connection
:rtype: `bytes`
"""
if size >= 0:
self._buf += self._conn.read_bytes(size)
msg = self._buf[:size]
# Remove the front of the buffer.
del self._buf[:size]
elif size == -1:
# Read the whole contents, appending the buffer we've already read.
msg = self._buf + self._conn.read()
# Reset the contents of the buffer.
self._buf = bytearray()
else:
raise ValueError("Must read a positive value of characters, or "
"-1 for all characters.")
return msg The return type here should be Should above routine use |
I think that you are correct in that it should be replaced.
On Thu, Jul 1, 2021 at 9:11 AM Reto Trappitsch ***@***.***> wrote:
In the visa_communicator.py, query simply calls PyVISA's own routine,
which sends a message, and then reads it out with the read(). PyVISA's
read() returns a string. So far this makes sense and is according to the
docs
<https://pyvisa.readthedocs.io/en/latest/api/resources.html#pyvisa.resources.SerialInstrument.read>
.
IK in the visa_communicator.py has the following routine for read_raw:
def read_raw(self, size=-1):
""" Read bytes in from the pyVISA connection. :param int size: The number of bytes to read in from the VISA connection. :return: The read bytes from the VISA connection :rtype: `bytes` """
if size >= 0:
self._buf += self._conn.read_bytes(size)
msg = self._buf[:size]
# Remove the front of the buffer.
del self._buf[:size]
elif size == -1:
# Read the whole contents, appending the buffer we've already read.
msg = self._buf + self._conn.read()
# Reset the contents of the buffer.
self._buf = bytearray()
else:
raise ValueError("Must read a positive value of characters, or "
"-1 for all characters.")
return msg
The return type here should be bytes, however, if called with the default
argument for size, which is done where the Keithley195 calls the read_raw,
IK calls on pyvisa's read() routine, which we already said returns a
string. @scasagrande <https://github.com/scasagrande>: Is this the right
interpretation of this?
Should above routine use read_raw() - see here
<https://pyvisa.readthedocs.io/en/latest/api/resources.html#pyvisa.resources.SerialInstrument.read_raw>
- instead of read?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#307 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAL3S6JW3WZ2T4TVSIRJ6B3TVRSO7ANCNFSM47R6TIHQ>
.
--
Steven Casagrande, MSc
Waterloo, Ontario
|
Put the fix in and wrote tests for the visa communicator, see #308. @thestumbler: Would be great if you could test it out with the and the actual instrument to make sure it fixes your issue! |
I did a test, and it seems okay. Here is a short program I wrote:
Here is the error message from the read_raw() function
|
By the way, is there any way to get to the PyVisa resource manager associated with an IK device? When I'm finished doing computer controlled testing, I want to put things back in a reasonable state. This seems to require some manipulation of GPIB signals (although I'm not 100% sure of myself). I've been reasonably successful doing some combination of dmm.clear() and ctl.control_ren(x) commands, but these require access to the PyVisa instances:
I looked in the visa_communicator() module but it wasn't obvious to me if/how I could get ahold of those objects or their equivalent. |
I'm not surprised the The visa communicator has a close function, which will simply pass it up the chain to pyvisa and send the Finally, when you open the instrument as shown above via IK, you basically create an instrument in ins = pyvisa.ResourceManager().open_resource(resource_name) This dmm._conn.clear() for example. Not the nicest way and there might be an argument for exposing |
Also, if you really need to get to the PyVISA ResourceManager, you can use a resource's |
I read issue #262 about parsing the status byte.
So, using 0.6.0 latest release from Jan 2020, I can read the status byte, but parsing function fails (as mentioned in the issue thread).
I think I pulled in the HEAD and tried it out (at least the behavior was different). I cloned the repository, went into that directory and did a
python -m pip install -e .
Well, this may or may not parse the status word correctly, I don't know. Because now reading the status word causes an error, as does just a plain read().I'm going to go back to the 0.6.0 version for now.
The text was updated successfully, but these errors were encountered: