Programming Example: Controlling an SPD power supply via Sockets over LAN

January 4, 2021

Here is a Python 3.6 example of using sockets to control an SPD power supply connected to a computer using LAN.

Here is a zip file of the working program:

NOTE: The SPD uses VXI-11 protocol for LAN. On some systems, it is helpful to use the VXI-11 format for the IP address:


Here is the program in full:

#!/usr/bin/env python
#-*- coding:utf-8 –*-
# The short script is a example that open a socket, sends a query,
# print the return message and closes the socket.
#No warranties expressed or implied
#SIGLENT/JAC 05.2018
import socket # for sockets
import sys # for exit
import time # for sleep

remote_ip = "" # should match the instrument’s IP address
port = 5025 # the port number of the instrument service

#Port 5024 is valid for the following:
#SIGLENT SDS1202X-E, SDG1/2X Series, SDG6X Series
#SDM3055, SDM3045X, and SDM3065X
#Port 5025 is valid for the following:
#SIGLENT SVA1000X series, SSA3000X Series, and SPD3303X/XE

count = 0
def SocketConnect():
        #create an AF_INET, STREAM socket (TCP)
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    except socket.error:
        print ('Failed to create socket.')
        #Connect to remote server
        s.connect((remote_ip , port))
    except socket.error:
        print ('failed to connect to ip ' + remote_ip)
    return s
def SocketClose(Sock):
    #close the socket

def main():
    global remote_ip
    global port
    global count

    # Body: send the SCPI commands *IDN? 10 times and print the return message
    s = SocketConnect()
    for i in range(1):
        s.sendall(b'OUTPUT CH1,ON')
        s.sendall(b'OUTPUT CH1,OFF')
        print (str(count))
        count = count + 1
    print('Test complete. Exiting program')

if __name__ == '__main__':
    proc = main()