pyvisa to communicate results in (encoding) error?

35 views Asked by At

I have been trying to communicate with the MKS946 mass flow controller using pyvisa. I can write commands to it easily, but queries return an error. A stripped down version of the code is:

import pyvisa


class MKS946:
    def __init__(self, com_port):
        self.port = int(com_port)
     
    def __enter__(self):
        rm = pyvisa.ResourceManager()
        self.mks946 = rm.open_resource(f"ASRL{self.port}::INSTR")
        
        #self.mks946.read_termination = ";FF"
       
     
        self.mks946.write_termination = ";FF"
      
        return self
    
    def __exit__(self, exc_type, exc_val, exc_tb):
        self.mks946.close()

    @property
    def flow1(self):
        return self.mks946.query("@253FR1?")

    @setpoint1.setter
    def setpoint1(self, val):
        self.mks946.write(f"@253QSP1!{val}")

if __name__ == "__main__":
    with MKS946(4) as mfc_box:
        print(mfc_box.get_id())

        mfc_box.setpoint1 = 0.26  # set set point (in sccm) of channel 1
        print(mfc_box.flow1)  # show current flow rate of channel 1 in sccm

The last line where I query the flow rate gives me an error that I can't quite understand i.e.

Traceback (most recent call last):

  File ~\anaconda3\envs\py310\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File y:\csv data log programs\specific experiment scripts\mfc_mks946.py:103
    print(mfc_box.flow1)  # show current flow rate of channel 1 in sccm

  File y:\csv data log programs\specific experiment scripts\mfc_mks946.py:37 in flow1
    return self.mks946.query("@253FR1?")

  File ~\anaconda3\envs\py310\lib\site-packages\pyvisa\resources\messagebased.py:648 in query
    return self.read()

  File ~\anaconda3\envs\py310\lib\site-packages\pyvisa\resources\messagebased.py:486 in read
    message = self._read_raw().decode(enco)

  File ~\anaconda3\envs\py310\lib\site-packages\pyvisa\resources\messagebased.py:442 in _read_raw
    chunk, status = self.visalib.read(self.session, size)

  File ~\anaconda3\envs\py310\lib\site-packages\pyvisa\ctwrapper\functions.py:2337 in read
    ret = library.viRead(session, buffer, count, byref(return_count))

  File ~\anaconda3\envs\py310\lib\site-packages\pyvisa\ctwrapper\highlevel.py:226 in _return_handler
    return self.handle_return_value(session, ret_value)  # type: ignore

  File ~\anaconda3\envs\py310\lib\site-packages\pyvisa\highlevel.py:251 in handle_return_value
    raise errors.VisaIOError(rv)

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

Is this an encoding error? Any advice would be appreciated.

Regards, L

0

There are 0 answers