Free Shipping logo FREE SHIPPING £75+
50 years of Telonic Instruments Ltd logo CELEBRATING 50+ YEARS
Price Match logo PRICE MATCH GUARANTEE

Programming Example: Using Python to configure a basic waveform with an SDG X series generator via o

Posted on: December 15th, 2020 by Doug Lovell

#!/usr/bin/env python 2.7.13
#-*- coding:utf-8 –*-
#—————————————————————————–
# The short script is a example that open a socket, sends basic commands
# to set the waveform type, amplitude, and frequency and closes the socket.
#
#No warranties expressed or implied
#
#SIGLENT/JAC 11.2018
#
#—————————————————————————–
import socket # for sockets
import sys # for exit
import time # for sleep
#—————————————————————————–

remote_ip = “192.168.55.110” # should match the instrument’s IP address
port = 5024 # the port number of the instrument service

#Port 5024 is valid for the following:
#SIGLENT SDS1202X-E, SDG2X 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():
try:
#create an AF_INET, STREAM socket (TCP)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print (‘Failed to create socket.’)
sys.exit();
try:
#Connect to remote server
s.connect((remote_ip , port))
except socket.error:
print (‘failed to connect to ip ‘ + remote_ip)
return s

def SocketSend(Sock, cmd):
try :
#Send cmd string
Sock.sendall(cmd)
Sock.sendall(b’\n’)
time.sleep(1)
except socket.error:
#Send failed
print (‘Send failed’)
sys.exit()
#reply = Sock.recv(4096)
#return reply

def SocketClose(Sock):
#close the socket
Sock.close()
time.sleep(1)

def main():
global remote_ip
global port
global count

# Body: send the SCPI commands and print the return message
s = SocketConnect()
qStr = SocketSend(s, b’*RST’) #Reset to factory defaults
time.sleep(1)

qStr = SocketSend(s, b’C1:BSWV WVTP,SQUARE’) #Set CH1 Wavetype to Square
qStr = SocketSend(s, b’C1:BSWV FRQ,1000′) #Set CH1 Frequency
qStr = SocketSend(s, b’C1:BSWV AMP,1′) #Set CH1 amplitude

SocketClose(s) #Close socket
print(‘Query complete. Exiting program’)
sys.exit

if __name__ == ‘__main__’:
proc = main()