8000 Support for multi-character read terminations? · Issue #808 · pyvisa/pyvisa · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support for multi-character read terminations? #808

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
neutrinonerd3333 opened this issue Mar 15, 2024 · 2 comments
Open

Support for multi-character read terminations? #808

neutrinonerd3333 opened this issue Mar 15, 2024 · 2 comments

Comments

@neutrinonerd3333
Copy link

I'm working with an instrument that only provides responses terminated with CRLF ('\r\n'). I see that VISA doesn't support multi-character read terminations, instead treating the final character, e.g. LF, as a termchar. I also see that pyvisa provides some minimal support on top of that by raising a warning if a read yields a string that ends with the termchar but not the full termination string:

if not message.endswith(termination):
warnings.warn(
"read string doesn't end with " "termination characters", stacklevel=2
)
return message

In my case, the instrument actually returns multi-line responses (with LF as delimiter) terminated with a final CRLF, so the only workaround would be to do multiple VISA reads until we get a CRLF and concatenate the responses. I do plan on implementing this, but I am wondering: would it make sense for pyvisa to provide this kind of added support for multi-character read terminations? I think it would be natural to implement this workaround at the pyvisa level rather than in client code, but there's of course an argument to be made to keep the library more a wrapper around VISA routines rather than to introduce additional features/complexity/abstraction.

@DavidLutton
Copy link

For the case of multiple reads to collect a response.
I did this last week for a power meter with known number of reads to collect calibration data from it:

inst.write('SI')   # Command for calibration data, follow with read() 31 times
calibration_data = [inst.read().strip() for i in range(1,32)]

@neutrinonerd3333
Copy link
Author

Just to be clear — I'm aware that one can just call MessageBasedResource.read() multiple times to read a multi-line response. As I wrote, I'm opening this issue to ask whether it makes sense to include support in pyvisa to handle the situation where a single logical response (terminated by a multi-char string) must be read by VISA as a sequence of individual reads because the final character of the termination string occurs in the body of the response.

< 5A52 div class="pr-review-reactions ">

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

No branches or pull requests

2 participants
0