Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Unexpected response from SCPI command over TCP/PyVISA

I am remotely controlling a Yokogawa WT5000 power analyzer over TCP using SCPI commands through PyVISA in Python Spyder. I am able to successfully connect to the instrument and send most queries/commands with no issues. However when I try to retrieve waveform data through resource.query_ascii_values(':WAVEFORM:SEND?'), I get the error:

 

UnicodeDecodeError: 'ascii' codec can't decode byte 0xb1 in position 8154: ordinal not in range(128)

 

This seems to say that PyVISA is expecting ASCII and encountering a byte coded in hex, which obviously throws an error. However, I have set the ':WAVEFORM:FORMAT ASCII' and confirmed it is set, so I'm not sure why it would return non-ASCII code. According to my instrument programming manual, the ASCII format option should return comma-delimited NR3 values terminated with \n. However if I try the more manual resource.write(':WAVEFORM:SEND?') followed by resource.read_raw() I get a weird response, with the output starting with NR3 values, then a long string of what appears to be bytes written in hex, then references to path names relating to my Python IDE (Spyder), then more NR3 data ending with the expected termination, all interspersed with sequences of characters which I can't identify as any particular format (I am relatively new to programming).

 

What's weird is if I the read_raw method with any other query, it works fine. For example, reading the raw output of ':WAVEFORM:FORMAT?' gives the expected b':WAV:FORM ASC\n' indicating that the instrument is indeed trying to send in ASCII. Why would the send command in particular give issues? Why would the raw output include path information on my computer? It is possible this is a bug on the instrument end, I am in contact with the manufacturer, but figured I'd try to tackle the issue from both ends. Any help greatly appreciated.

 

 

0 Kudos
Message 1 of 3
(213 Views)

The weird path information is likely because the read_raw does some weird interpretation of the returned buffer, likely reading over the end of the actual buffer. Which would seem a bug in pyvisa.

Rolf Kalbermatter
My Blog
Message 2 of 3
(178 Views)

Thank you, I had assumed I could use either ascii or binary because my power analyzer is supposed to be able to output data directly in ascii format by setting 'WAVEFORM:FORMAT ASC'. I am trying to replicate someone else's setup and they've never had an issue going this route, however this doesn't appear to work for me. If I set to the other option (IEEE 4-byte float), and use the query_binary_values command, it works like a charm (I actually did check this before and for some reason it was crashing my script, but no longer). Seems the machine thinks it's outputting ascii and it's not, or there's an encoding issue I'm not identifying. Question for the manufacturer I guess.

 

Thanks again! (I would like to set your response as a solution but for some reason can l no longer see the original response where you recommend checking the binary). 

0 Kudos
Message 3 of 3
(160 Views)