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

Tests and BFs for Keithley 195 #262

Merged
merged 3 commits into from
Sep 14, 2020

Conversation

trappitsch
Copy link
Contributor

Full coverage test suite

BFs:

  • Transfer queried values to bytes before using struct.unpack.
  • Do subsequent comparisons on bytes as well.
  • Remove if self._testing statement to skip a sleep time. In the test,
    mock time.sleep for speedup and ensure it was called with
    a 2 seconds argument.

Full coverage test suite

BFs:
- Transfer queried values to bytes before using `struct.unpack`.
- Do subsequent comparisons on bytes as well.
- Remove `if self._testing` statement to skip a sleep time. In the test,
  mock `time.sleep` for speedup and ensure it was called with
  a 2 seconds argument.
@coveralls
Copy link

coveralls commented Sep 12, 2020

Coverage Status

Coverage increased (+0.5%) to 94.187% when pulling c0224ec on trappitsch:test_keithley195 into 77c6f0a on Galvant:master.

@@ -301,18 +300,19 @@ def parse_status_word(statusword): # pylint: disable=too-many-locals

(trigger, function, input_range, eoi, buf, rate, srqmode, relative,
delay, multiplex, selftest, data_fmt, data_ctrl, filter_mode,
terminator) = struct.unpack('@4c2s3c2s5c2s', statusword[4:])
terminator) = struct.unpack('@4c2s3c2s5c2s', bytes(statusword[4:],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Keithley does answer with mostly integers according to the manual, those can be decocded with "utf-8". For the unpacking later, need to put them into bytes again. This is analog to how the keithley485.py handles the same issue on line 362.
The statusword is well defined, thus read_raw could be used. However, if an error is returned by the instrument, we will have stuff left in the buffer, thus making query and re-encoding for subsequent unpacking the preferred method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you saying that in get_status_word we can end in a condition where we haven't cleared out the buffer if we use read_raw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When read_raw is called with size=-1, it should read until a terminator is encountered, is that correct? If so, that would actually work as well and would be the preferred method. Sorry, I might have mixed this up with binblockread from looking at all the scopes.
I'm worried to read back a given size - if the instrument has a failure mode (seems like they tend to have those from your comment below) the size of what it would send might be different, and then get things into weird states. Of course, this always assumes that weird states send termination characters...

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes read_raw with size=-1 will go until the termination character is found. In fact, read does not check for termination characters, it is only the impl of read_raw that does this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes a lot more sense, thanks for the clarification @scasagrande!
I changed it such that the status word now gets read using read_raw, thus it does not need to be encoded with bytes afterwards.
To use read raw: I'm now first sending the command with sendcmd and then get the response with read_raw. Is this the preferred way? query basically wraps the sendcmd and read into one, but I guess there's no query_raw equivalent?

Copy link
Contributor

Choose a reason for hiding this comment

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

That seems correct to me. Perhaps something like that can be added. Or, we could add support for something like encoding=None which would mean to not encode the returned bytes. Not sure how I feel about that later suggestion though, since we would be changing return type.

Anyways that's a conversation for another time, but your current version is what I would have done.

@scasagrande
Copy link
Contributor

I actually have a 195, and I will say that its a pain to get working. If you don't do everything perfectly, it gets into a strange state and you have to power cycle it. At least, that's what I had to do.

Changed the read to use `read_raw` to read the instrument. Thus,
no need to re-encode the status word using `bytes`.
@scasagrande
Copy link
Contributor

lgtm

@scasagrande scasagrande merged commit 4f30520 into instrumentkit:master Sep 14, 2020
@trappitsch trappitsch deleted the test_keithley195 branch September 14, 2020 16:42
@thestumbler thestumbler mentioned this pull request Jun 30, 2021
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.

3 participants