Programming Example: Open Socket LAN connection using Python

October 20, 2017

Automating a test can dramatically increase the productivity, throughput, and accuracy of a process. Automating a setup involves connecting a computer to the test instrumentation using a standard communications bus like USB or LAN and then utilizing code entered via a software layer (like LabVIEW, .NET, Python, etc..) to sequence the specific instrument commands and process data.

In this note, we are going to show how to use Python to create a communications link between an instrument and a remote computer using a LAN connection. Once the connection is verified, you can begin to work on the control software.

NOTE: This example requires open sockets on the instrumentation. At this time, not all SIGLENT products feature open sockets. Check the product page FAQs or with your local SIGLENT support office for more information.

Python is an interpreted programming language that lets you work quickly and is very portable. Python has a low-level networking module that provides access to the socket interface. Python scripts can be written for sockets to do a variety of test and measurements tasks.

Here is a Python 2.7 script that opens a socket, sends a query and closes the socket. It performs this operation in a loop 10 times:


You can follow the instructions below to build your own example:

1. Power on and connect the instrument to the network via LAN

2. Verify that the Gateway, Subnet Mask, and IP address of the instrument are valid for the network you wish to use. This information is typically located in the System Information or IO menu. See the specific instrument user’s guide for more information on LAN settings.

3. Download python and your favorite python editor (I use IDLE):

Start your python editor:

5. Open a new file by pressing File > New File.. and name the file

6. Copy and paste the code at the end of this note into the file editing window:

7. Change the IP address and port number so that they match the IP address and port for the instrument you wish to connect to:

Save the file:

8. To Run, select Run and Run Module: