# How to use PyVisa or maybe sockets in Ignition to talk to VISA/SCPI device?

**URL:** <https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634>\
**Category:** Ignition\
**Tags:** python, ignition79, scripting\
**Created:** [November 7, 2018, 6:38pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634 "2018-11-07T18:38:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [November 7, 2018, 6:38pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/1 "2018-11-07T18:38:01Z")

</div>

I am using Ignition 7.9.4, which uses Jython 2.5.

I have an old Agilent VISA/SCPI device I want to talk to. I don’t know the name of the device and want to display a list of connected devices/instruments to the user to select from. After the user selects an instrument, I want to connect to it and start sending out VISA/SCPI commands to it.

Ideally, I would like to use PyVisa; however, an attempt to import this resulted in an error about **unicode\_literals** not being available from the **future** module. I tried updating this **future** module to include **unicode\_literals** , using the latest version of **future** from the latest version of jython, but no luck.  
Does anyone know how to get PyVisa working?

If no one knows how to get PyVisa working in Jython, what about sockets?  
There is an example of someone using [sockets here](https://github.com/antonl/scpi).  
…but they already know the name of the device and I need to find a list of connected devices for the user to pick from.

If there are any other options, please suggest them.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 7, 2018, 7:06pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/2 "2018-11-07T19:06:37Z")

</div>

In general, python libraries that access native libraries (.DLL, .so) will not (ever) work in jython. However, it is often possible to find java bindings for such native libraries, which **can** be used in jython. One would use the java examples for such bindings instead of the python examples.

There is a SourceForge project call jvisa that appears to offer what you need if you pursue this approach. If your jython is only going to run in the gateway, you could simply add the files to your gateway’s lib folder with all of the other common jars. Otherwise, you’ll need to package jvisa into a module so its parts get distributed properly to each client.

> **[Java API for VISA Devices](https://sourceforge.net/projects/jvisa/)**
>
> Download Java API for VISA Devices for free. Java wrapper for native VISA library and TDS3000 oscilloscope driver. Write VISA instrument drivers in Java for Windows and Linux. Maybe the best way to give a full description is to explain the history of...

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [November 7, 2018, 8:01pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/3 "2018-11-07T20:01:38Z")

</div>

After looking around a bit, I found that PyVisa has its own implementation of the VISA protocol. This means that it doesn’t need drivers and can operate without them, making PyVisa a viable option since it is pure python code; however, it uses C code - as you mentioned (DLL) - so it won’t work in Jython.

**I did try getting JVisa into Ignition, but it didn’t work. Here were my steps:**

1. Download & extract from site: [https://sourceforge.net/projects/jvisa/](https://sourceforge.net/projects/jvisa/)
2. Go to folder: **JVisa\_and\_JVisaOscilloscope \_2.0\JVisa\lib\64bit**
3. Open command prompt in this directory and run: **pack200 --gzip -E9 JnaVisa64.jar.pack.gz JnaVisa64.jar** to create the **jar.pack.gz** file needed for Ignition
4. Go to folder: **C:\Program Files\Inductive Automation\Ignition\lib\core\common** and paste both the **JnaVisa64 jar and jar.pack.gz files**
5. Close any open designers.
6. Restart Ignition Service: Go to services, right-click, restart. Wait for restart to finish.
7. Open new designer, go to script console, and try: **import jvisa**. It says the library doesn’t exist.

What did I miss?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 7, 2018, 9:49pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/4 "2018-11-07T21:49:54Z")

</div>

try something like `from jvisa import JVisa` or `import jvisa.JVisa`. Jvisa has a java-style hierarchy, and you must import each class individually.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 7, 2018, 9:55pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/5 "2018-11-07T21:55:59Z")

</div>

By the way, the statements “since it is pure python code” and “it uses C code” are contradictory. Pure python code does not call out to any C code. Whether the DLLs in question are “drivers” or “libraries” doesn’t matter.

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [November 8, 2018, 12:43am UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/6 "2018-11-08T00:43:02Z")

</div>

You’re absolutely right…python is built on C though, so I kinda think of python that wraps C code as still pure python. This isn’t really right, though.

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [November 8, 2018, 12:59am UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/7 "2018-11-08T00:59:05Z")

</div>

No, I am still getting **no module named jvisa**. I tried adding the **JnaVisa64\_13** and **JVisaOneJar** as well - with their **jar.pack.gz** compressed versions as well - but Ignition gave an error for **JVisaOneJar** , so I removed it and I still could not import the library.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 8, 2018, 1:36pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/8 "2018-11-08T13:36:57Z")

</div>

> [@cmaynes](#):
>
> python is built on C though, so I kinda think of python that wraps C code as still pure python

"python" is a language: syntax definition and standard library specification. CPython (the one typically installed as command line "python"), Jython, IronPython, and PyPy (not to be confused with PyPI) are implementations, each with their own native code (.DLL, .so) plug-in requirements. Pure python, as meant in the python community, runs on any of them, invoking just the standard library or other pure python libraries. There are [more implementations](https://wiki.python.org/moin/PythonImplementations) for special cases, like MicroPython, some of which are not fully compliant with the spec.

Your thoughts on pure python contradict the community, cause confusion in public fora, and create unrealistic expectations (at least for you) of what works where.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 8, 2018, 1:40pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/9 "2018-11-08T13:40:39Z")

</div>

> [@cmaynes](#):
>
> No, I am still getting no module named jvisa.

When I have some spare time, I'll look into packaging this into a module properly.

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [November 8, 2018, 4:51pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/10 "2018-11-08T16:51:19Z")

</div>

Thanks for taking the time to clarify what “pure python” means. I really appreciate it.

---

<div class="post-metadata">

**Author:** ![ghuck](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ghuck/32/8337_2.png) [@ghuck](https://forum.inductiveautomation.com/u/ghuck)\
**Post date:** [November 12, 2018, 3:48pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/11 "2018-11-12T15:48:38Z")

</div>

I have written a full usable SCPI interface using the SCPI ACSII commands send directly to a raw TCP/IP socket on Aglent/Keysight devices, it’s all run out of the gateway script, and does not use any VISA library, the only down side to all this is it’s slower then native compiled VISA drives, but if you do not need high speed then this approach works very well. If interested this approach I can post some sample code.

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [November 12, 2018, 4:56pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/12 "2018-11-12T16:56:57Z")

</div>

Timing is somewhat important. What kind of lag are you seeing relative to using VISA? Average time for running a few commands using one method over the other?

EDIT:

Also, VISA is extremely well-supported by virtually every manufacturer of these devices, but TCP/IP is fairly new and may not be supported. There is always a chance that my company pulls a very old machine and wants to start using it. I would have to go back to using VISA and that would require an external program again that runs Python 3, so I can use PyVisa.

---

<div class="post-metadata">

**Author:** ![ghuck](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ghuck/32/8337_2.png) [@ghuck](https://forum.inductiveautomation.com/u/ghuck)\
**Post date:** [November 17, 2018, 10:14pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/13 "2018-11-17T22:14:23Z")

</div>

Because I run this on a **raw device socket** , I’m not sure how fast I could push it, the main item determining speed is how fast you run the scan class for the SCPI tags, right now, using SCPI commands against 34980 Data Acquisition unit I have the scan class set to try a new command every 1/2 second. But you will always get the slower of the scan class or the SCPI device. I read 4 thermocouples at this speed, and when reading 9 it takes just over .6 seconds. But thermocouples are have a lot of overhead in the Data Acquisition, it has to auto range and auto zero the voltmeter, then after taking the reading it has to do a Ohms reading against the Thermocouple to verify there not open. Attached is a screen shot of my debugger screen, where I read 40 T/C’s in, this data is send right to tags. sh

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/7/71894d937ba17264dcc6eb55a649c64088e74a1c.PNG)

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [November 18, 2018, 8:18pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/14 "2018-11-18T20:18:44Z")

</div>

Thanks @ghuck. Since you already have the code setup for TCP, could you try a standard command that should have nothing to do really with your device, like \*IDN?

Using this command, maybe 100 times, to benchmark speed would give a clear picture of how TCP and VISA speeds compare.

---

<div class="post-metadata">

**Author:** ![ghuck](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ghuck/32/8337_2.png) [@ghuck](https://forum.inductiveautomation.com/u/ghuck)\
**Post date:** [November 18, 2018, 8:58pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/15 "2018-11-18T20:58:56Z")

</div>

I wish I could, but all of my SCPI instruments are in production, and since my instance of this is ran all thought the OPC tag system, where I have that scan class set to .5 seconds that would be the maximum speed I would get on my current systems, and since there in production I cannot play with the scan class to turn it up fast enough to make this a throughput test, with out the risk of affecting something in production.  
The way I have my systems set up, all commands are templated in a gateway tag change script, I just submit a template number(s) to tag sequencer and it runs all of the templates as fast as it can, but is limited to the scan class tag interval. So if I submitted my template number for this 100 times in the sequencer in my current systems, it would be paced at my scan class rate of .5 seconds right now, which is a design limit of are projects and is no way would be represented on the maximum speed one could get.

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/95332fbd80f8fbfc8cfb50f1fd640921e9df7025.PNG)

---

<div class="post-metadata">

**Author:** ![ecan](https://avatars.discourse-cdn.com/v4/letter/e/8edcca/32.png) [@ecan](https://forum.inductiveautomation.com/u/ecan)\
**Post date:** [March 14, 2019, 11:12am UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/16 "2019-03-14T11:12:45Z")

</div>

Did you find a solution? I am having the same problems…

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [March 29, 2019, 11:27am UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/17 "2019-03-29T11:27:54Z")

</div>

Not as of yet…priorities shifted and I had to move on to something else.

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [June 20, 2019, 4:35pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/18 "2019-06-20T16:35:11Z")

</div>

TCP/IP worked pretty well…I just tested it. I am using ASCII commands, not binary, so there might be a way to speed it up more. FYI - I am actually using the TelNet server on the analyzer. Anyway, how long commands take varies a great deal when I am working with an E5071C network analyzer using SCPI commands. Send commands, not queries, can be somewhere around 15 ms. Batching of commands is extremely critical…if you combine commands with a semicolon (😉 and send them all off at once the analyzer can process them really quickly and your average processing time per command drops dramatically. Queries take a long time, unfortunately. A query, regardless of the number of commands almost always takes 400-500 ms before getting a response back from the analyzer. I would avoid running queries, like “:system:error?” or “\*opc?”, until you have sent all your setup commands.

---

<div class="post-metadata">

**Author:** ![cmaynes](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmaynes/32/6852_2.png) [@cmaynes](https://forum.inductiveautomation.com/u/cmaynes)\
**Post date:** [June 21, 2019, 6:28pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/19 "2019-06-21T18:28:40Z")

</div>

Scratch that…telnet works great, but we are switching to another device that is cheaper and purely USB.

Now my solution is to wrap a socket server program around pyvisa, make an exe out of that, download the exe to the host computers from a shared drive, and then just use a socket to talk to it in Ignition…FYI, had to use the java socket lib, because when trying to use the python socket library in Ignition, it took 4.5 seconds to open…brutally slow.

I tried just creating the exe and using python’s subprocess module with command line args to get and send data, but it took a minimum of 400 ms just to spawn the process…even when I was sending a command and not a query, which took ~15 ms when using telnet.

---

<div class="post-metadata">

**Author:** ![ghuck](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ghuck/32/8337_2.png) [@ghuck](https://forum.inductiveautomation.com/u/ghuck)\
**Post date:** [June 21, 2019, 8:56pm UTC](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634/20 "2019-06-21T20:56:43Z")

</div>

We just the use the Ignition TCP Driver found at the bottom of the add devices page. It’s a persistent connection. Just set the driver Message Delimter type to ASCII, the Message Delimiter, and writeback delimeter to \n  
Also to keep SCPI running as fast as possible, use the four letter SCPI commands, and save any return data into the instrument memory and read it back from there. HP use to have a white paper in this subject but I have been unable to locate it, but I will keep looking.

[Next page](https://forum.inductiveautomation.com/t/how-to-use-pyvisa-or-maybe-sockets-in-ignition-to-talk-to-visa-scpi-device/20634.md?page=2)
