Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to a specific Ethernet port using Python and PyVisa

Tags:

python

visa

I am trying to connect to a temperature chamber via an Ethernet connection using pyVisa in Python. The device only allows connections through port 2049. I have no problems connecting to it via PuTTY or HyperTerminal, but when I try this command in Python

import visa
chamber = visa.instrument("TCPIP::10.2.17.130::2049")

I get this error:

VI_ERROR_RSRC_NFOUND: Insufficient location information or the requested device or resource is not present in the system

I know the device is there because I can talk through it in PuTTY, but I cannot seem to get the Python code to work. Any hints? Does pyvisa use SSH by default?

like image 330
KMB Avatar asked Jul 17 '12 11:07

KMB


People also ask

How do you fix PyVISA Cannot find any USB instruments?

Solution: In order for pyvisa-py to be able to connect to USB instruments, you need to install the Python usb library! In case you still don't see the output, run python3 -m visa info or python -m visa info (for Python 2. x).

What is PyVISA-py?

PyVISA-py is a backend for PyVISA. It implements most of the methods for Message Based communication (Serial/USB/GPIB/Ethernet) using Python and some well developed, easy to deploy and cross platform libraries.


3 Answers

The simplest way (IMHO) to access a VISA resource is still by using the VISA device detection which would be through:

  • visa.ResourceManager().list_resources(), if you're using pyVisa
  • or viFindRsrc() and viFindNext() if you use the visa32.dll library.

Now by default, LAN connections are not detected using either method. This leaves you with two choices:

  • If you have installed NI-MAX (the Measurement & Automation Explorer from National Instruments is a free download), go under 'Devices & Interfaces', right-click on 'Network Devices', select 'Create New VISA TCP/IP Resource...' and follow the instructions. NI-MAX will auto detect your instrument and provide its VISA resource name. Note that now this resource will be listed by both list_resources() and viFindRsrc()/viFindNext()
  • If not, you will have to provide VISA with the right resource name. If you use a VISA passport (e.g. VICP for LeCroy oscilloscopes) then you should change the VISA header appropriately (replace TCPIP with VICP). Then, the syntax is the following: [visa-header]::[instrument-ip]::INSTR or [visa-header]::[instrument-ip]::[instrument-port]::INSTR

Actually, it's not always INSTR, depending on the resource class (see http://zone.ni.com/reference/en-XX/help/371361J-01/lvinstio/visa_resource_name_generic/).

Be sure to send byte strings to the instrument (especially if using Python 3+), otherwise you will get the following error:

VI_ERROR_RSRC_NFOUND: Insufficient location information or the requested device or resource is not present in the system

which can also be identified by 0xBFFF0011 or a return value of -1073807343.

like image 88
Tonio Avatar answered Sep 18 '22 03:09

Tonio


Are you sure the temp chamber supports the LAN instrument protocol?

If unsure, try using raw socket instead, i.e.

chamber = visa.instrument("TCPIP::10.2.17.130::2049::SOCKET")

(pyvisa does not use SSH by default)

like image 41
Qiau Avatar answered Sep 17 '22 03:09

Qiau


Try this:

import socket
HOST = "10.2.17.130"    # The remote host
PORT = 2049             # The same port as used by the server

    s = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))
like image 44
Joseph Avatar answered Sep 20 '22 03:09

Joseph