pythonvisapyvisa

VI_ERROR_TMO (-1073807339): Timeout expired before operation completed


I try to connect my Power Analyser Rohde&Schwarz, HMC8015 ('ASRL3::INSTR') to my computer, and to read any data that my device can show with python VISA. I have a lot of problems with the code line, which allows to read my device data.

My code is:

import visa

rm = visa.ResourceManager()
name = rm.list_resources()

#using with allows to close explicitly the resource at the end of the script
with rm.open_resource('ASRL3::INSTR') as Power_Analyser:

    Power_Analyser.values_format.is_binary = True
    Power_Analyser.values_format.datatype = 'B'
    Power_Analyser.values_format.is_big_endian = False
    Power_Analyser.values_format.container = bytearray

    Power_Analyser.timeout = 25000 #2,5 seconds

    Power_Analyser.write_termination = '\n'

    Data = Power_Analyser.query_ascii_values('P?',datatype='s')[0]
    print(Data)

        #write the Data to a file on my PC
        PCfilePath = 'C:\\Users\\ApCha\\Documents\\Python Scripts\\a.txt'
        newFile = open(PCfilePath, "wb")
        newFile.write(Data)
        newFile.close()

It shows me: VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.

No matter how big the timeout is set. I'm guessing that the problem comes from the syntax in Power_Analyser.query_ascii_values('P?',datatype='s')[0] but I can't figure out what's the correct syntax.

I checked on my device manual: https://scdn.rohde-schwarz.com/ur/pws/dl_downloads/dl_common_library/dl_manuals/gb_1/h/hmc80115/HMC8015_SCPImanual_en_01.pdf

but nothing seems to work and nothing is clearly explained for python VISA and I don't have any experience with that. Does anyone know how to fix the problem ?


Solution

  • I usually do the following when trouble-shooting connection problems with (new) VISA instruments:

    Only if that fails do I configure specific communication settings, such as .write_termination, .read_termination, and .timeout. A time-out of 100 ms will usually do. Make it a second just to be sure.

    In your code, you set .values_format.is_binary to True right from the start. But then you .query_ascii_values. I'd be very surprised to see that not fail. Obviously, every instrument is different. Though after a very quick glance at the manual, I don't see any indication that your instrument actually is.

    My advice: Start with the default communication settings, try to get a response to the *IDN? command, then take it from there.