pythontcppyvisa

VI_ERROR_TMO when a computer does a query to a function generator


I am using a peaktech 4046 : 160MHz Function/arbitrary Waveform Generator. I developping on pyton and I am using the pyvisa librairy. The connection is well established and the generator applies the query. But it generates the following error and stops the program (it doesn't do anything after the error).

Here is the code :

import pyvisa
rm = pyvisa.ResourceManager()
inst = rm.open_resource('TCPIP0::130.79.192.123::5025::SOCKET')
print(inst.session)
print(inst.io_protocol)

inst.query("source1:function squ")

And here is what I have in my terminal :

2
IOProtocol.normal
Traceback (most recent call last):
  File "c:\Users\Labo préclinique\Desktop\ProjetPython\importation de librairies\Forum.py", line 7, in <module>
    inst.query("source1:function squ ")
  File "C:\Users\Labo préclinique\AppData\Local\Programs\Python\Python39\lib\site-packages\pyvisa\resources\messagebased.py", line 644, in query
    return self.read()
  File "C:\Users\Labo préclinique\AppData\Local\Programs\Python\Python39\lib\site-packages\pyvisa\resources\messagebased.py", line 486, in read
    message = self._read_raw().decode(enco)
  File "C:\Users\Labo préclinique\AppData\Local\Programs\Python\Python39\lib\site-packages\pyvisa\resources\messagebased.py", line 442, in _read_raw
    chunk, status = self.visalib.read(self.session, size)
  File "C:\Users\Labo préclinique\AppData\Local\Programs\Python\Python39\lib\site-packages\pyvisa\ctwrapper\functions.py", line 2337, in read
    ret = library.viRead(session, buffer, count, byref(return_count))
  File "C:\Users\Labo préclinique\AppData\Local\Programs\Python\Python39\lib\site-packages\pyvisa\ctwrapper\highlevel.py", line 222, in _return_handler
    return self.handle_return_value(session, ret_value)  # type: ignore
  File "C:\Users\Labo préclinique\AppData\Local\Programs\Python\Python39\lib\site-packages\pyvisa\highlevel.py", line 251, in handle_return_value
    raise errors.VisaIOError(rv)
pyvisa.errors.VisaIOError: VI_ERROR_TMO (-1073807339): Timeout expired before operation completed.

I have tried (to no avail) : -changing SOCKET to INSTR -using a timout much longeur ( inst.timeout = 10000) -adding a end term (tried \n and \r) with : inst.read_termination = '\n'

So I don't know what to do anymore... I need to give more than one command, so the program must not stop so fast. I suspect that my function generator is not sending anything back, but I don't know how to make sure this is the case.

What I wish to know is : Why do I have a time out error if the connection is well established and the request is executed on the device ? How to do the request in a proper way ?

Thank you in advance !!

PS : I know how to catch the error (with try except) but I'd rather have an Ok answer thant a KO one.


Solution

  • Try to get a list of resources by

    rm.list_resources()
    

    and check that your resource TCPIP0::130.79.192.123::5025::SOCKET in it.

    Then check the standard request to the resource from tutorial:

    inst.query("*IDN?")
    

    query is a short form for a write operation to send a message, followed by a read. So you could do this in two actions to specify the error(read or write error?):

    inst.write('"source1:function squ"')
    print(inst.read())
    

    Please, check the name of query source1:function squ because I don't see it in the documentation. Maybe you should use "source1:am:interanal:function square(p. 57 of documentation) or change squ -> square?

    Accordingly documentation, you could try to set infinite timeout to your request by

    del inst.timeout
    

    Also, you could add read_termination/write_termination option to specify when you'll finish your reading/writing by

    inst = rm.open_resource('TCPIP0::130.79.192.123::5025::SOCKET', read_termination='\r')
    

    And the last chance is changing the options query_delay and send_end.