53 User Manual
EAR99 technology subject to restrictions on copyrights page.
Socket-based programming examples
Python programming examples
Because the operating system itself supports Socket communication, this
communication method is relatively concise. Note that the T3PS16081P /
30051P use a fixed port number of 5025 for Socket communication, and the
"\ n" (newline) must be added to the end of the SCPI command string.
Environment:
Windows 7 32-bit system, Python v2.7.5
Example content:
Access control devices via Socket, send commands to
read the return value.
The following is the script content:
#!/usr/bin/env python
#-*- coding:utf-8 –*-
#------------------------------------------------------------------------------------------------
# Access the control device via Socket, send a command, read and print
the return #value.
#------------------------------------------------------------------------------------------------
import socket # for sockets
import sys # for exit
import time # for sleep
#------------------------------------------------------------------------------------------------
remote_ip = "10.11.13.32"
port = 5025
count = 0
def SocketConnect():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print ('Failed to create socket.')
sys.exit();
try:
s.connect((remote_ip , port))
except socket.error:
print ('failed to connect to ip ' + remote_ip)
return s