Digital Oscilloscope Series
Examples of Using Sockets
Socket communication is a basic communication technology in computer network.
It allows applications to communicate through the standard network protocol
mechanism built by network hardware and operation system.
This method is a two-way communication between the instrument and the computer
through a fixed port number.
Note that SCPI strings are terminated with a "\n" (new line) character.
Python Example
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
measurement tasks.
Environment: Windows 7 32-bit, Python v2.7.5
Description: Open a socket, send a query, and repeat this loop for 10 times, finally
close the socket.
Below is the code of the script:
#!/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.
#-----------------------------------------------------------------------------
import socket # for sockets
import sys # for exit
import time # for sleep
#-----------------------------------------------------------------------------
remote_ip = "10.11.13.32" # should match the instrument's IP address
port = 5024 # the port number of the instrument service
count = 0
221