Posted Tue, 07 Feb 2023 21:29:39 GMT by Li, Xiang
Every once in a while I would get issues like this. 
    lst = [float(self.query(f"MEASUrement:MEAS{meas}:mean?")),
ValueError: could not convert string to float: 'TEKTRONIX,MSO44,B026208,CF:91.1CT FV:1.34.8.1078\n'

So I'm trying to query "MEASUrement:MEAS1:mean?"
When I use tek scope utility (console tab) using that exact string, I get 44.9869573289624, as expected. 
but in the above automation script (where meas = 1), I received a string of 'TEKTRONIX,MSO44,B026208,CF:91.1CT FV:1.34.8.1078\n' (which is the IDN) instead. 
Why would the scope return IDN when I'm trying to query "MEASUrement:MEAS1:mean?". And it's not specific to "MEASUrement:MEAS1:mean?". I've seen scope returning IDN for other queries too. 
See pic too. 
 
Posted Tue, 07 Feb 2023 22:51:52 GMT by Teles, Afonso
Hi Xiang,

This usually happens when an *IDN? query was sent but no corresponding VISA Read was transmitted. Because of this, the response to the query is held in the IO buffer until it is read in the next query.
The solution is to call VISA Clear at the start of your program or before your query.
Posted Wed, 01 Mar 2023 20:08:21 GMT by Li, Xiang
I tried adding CLS in the init but I'm still having issues. 
def __init__(self, addr):
    self.addr = addr
    self.rm = pyvisa.ResourceManager()        # rm.list_resources()
    self.inst = self.rm.open_resource(self.addr)
    self.write("*CLS")
    print(self.query("*IDN?"))
    self.write("*CLS")
Do you see anything wrong with the below function? (I keep getting timeout errors at random lines in the below funciton. )
If not, can you please share a scope shot retrieving routine that's robust? 
def get_screenshot(self):
    now = str(datetime.datetime.now()).replace(":", "-")
    # print(now)
    self.write(f'SAVE:IMAGe \"C:/{now}.png\"')
    self.query("*OPC?")
    self.write(f'FILESystem:READFile \"C:/{now}.png\"')
    imgData = self.inst.read_raw(1920 * 1080)
    cwd = os.getcwd()
    full_path = cwd + "\\scope screenshots"

    Path(full_path).mkdir(exist_ok=True)

    filepath = full_path + "\\" + now + ".jpg"
    file = open(filepath, "wb")
    file.write(imgData)
    file.close()
    self.write(f'FILESystem:DELEte \"C:/{now}.png\"')
    return filepath
Posted Wed, 01 Mar 2023 20:58:16 GMT by Li, Xiang

Sometimes I get stuck on 
"*OPC?"
Sometimes I get stuck on 
read_raw(1920 * 1080)
Sometimes I get stuck on 
"*IDN?"

pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.





 

You must be signed in to post in this forum.