Attribute Error when setting VI_ATTR_TCPIP_KEEPALIVE to True
oliverpetschick opened this issue · 1 comments
Hi,
I was trying to set my TCPIPSocket resource to use tcp-keepalive using the recommended command:
inst.set_visa_attribute(pyvisa.constants.ResourceAttribute.tcpip_keepalive, True)
as written in the Docs (https://pyvisa.readthedocs.io/projects/pyvisa-py/en/latest/faq.html#can-pyvisa-py-be-used-from-a-docker-container).
The command let to AttributeError: 'socket' object has no attribute 'sock'. Upon inspection of the tcpip.py file, sock
seems to be no valid attribute of self.instrument (any more?). I could fix the _set_attribute
and _set_tcpip_keepalive
methods by removing the attribute .sock and change the method call from self.interface.sock.setsockopt to self.interface.setsockopt.
It seems that removing the deprecated "sock" attribute will fix this issue.
To reproduce a TCPIPSocket Instrument is needed!
import pyvisa
from pyvisa import constants
rm = pyvisa.ResourceManager()
inst = rm.open_resource("TCPIP::1.1.1.1::5025::SOCKET")
inst.set_visa_attribute(constants.VI_ATTR_TCPIP_KEEPALIVE, True)
Results in:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-c0c39126b630> in <module>
4 rm = pyvisa.ResourceManager()
5 inst = rm.open_resource("TCPIP::10.1.13.65::5025::SOCKET")
----> 6 inst.set_visa_attribute(constants.VI_ATTR_TCPIP_KEEPALIVE, True)
~/.local/lib/python3.10/site-packages/pyvisa/resources/resource.py in set_visa_attribute(self, name, state)
376
377 """
--> 378 return self.visalib.set_attribute(self.session, name, state)
379
380 def clear(self) -> None:
~/.local/lib/python3.10/site-packages/pyvisa_py/highlevel.py in set_attribute(self, session, attribute, attribute_state)
658 return self.handle_return_value(
659 session,
--> 660 self.sessions[session].set_attribute(attribute, attribute_state),
661 )
662 except KeyError:
~/.local/lib/python3.10/site-packages/pyvisa_py/sessions.py in set_attribute(self, attribute, attribute_state)
714 setter = value[1]
715 status = (
--> 716 setter(attribute, attribute_state)
717 if setter
718 else StatusCode.error_nonsupported_attribute
~/.local/lib/python3.10/site-packages/pyvisa_py/tcpip.py in _set_tcpip_keepalive(self, attribute, attribute_state)
1346 socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1 if attribute_state else 0
1347 )
-> 1348 self.interface.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 60)
1349 self.interface.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 60)
1350 self.interface.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 5)
AttributeError: 'socket' object has no attribute 'sock'
Output of pyvisa-info
Machine Details:
Platform ID: Linux-6.2.0-34-generic-x86_64-with-glibc2.35
Processor: x86_64
Python:
Implementation: CPython
Executable: /usr/bin/python3
Version: 3.10.12
Compiler: GCC 11.4.0
Bits: 64bit
Build: Jun 11 2023 05:26:28 (#main)
Unicode: UCS4
PyVISA Version: 1.13.0
Backends:
ivi:
Version: 1.13.0 (bundled with PyVISA)
Binary library: Not found
py:
Version: 0.7.0
ASRL INSTR: Available via PySerial (3.5)
USB INSTR: Available via PyUSB (1.2.1-1). Backend: libusb1
USB RAW: Available via PyUSB (1.2.1-1). Backend: libusb1
TCPIP INSTR: Available
Resource discovery:
- VXI-11: ok
- hislip: ok
TCPIP SOCKET: Available
VICP INSTR:
Please install PyVICP to use this resource type.
GPIB INSTR:
Please install linux-gpib (Linux) or gpib-ctypes (Windows, Linux) to use this resource type. Note that installing gpib-ctypes will give you access to a broader range of functionalities.
No module named 'gpib'
GPIB INTFC:
Please install linux-gpib (Linux) or gpib-ctypes (Windows, Linux) to use this resource type. Note that installing gpib-ctypes will give you access to a broader range of functionalities.
No module named 'gpib'
Could you make a PR ?