Skip to content

Commit a28bb9c

Browse files
authored
Add files via upload
1 parent 4bcfa96 commit a28bb9c

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

LAN_Capture.py

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env python 3.4.3
2+
#-*- coding:utf-8 –*-
3+
#-----------------------------------------------------------------------------
4+
#The short script is a example that open a socket, sends a query to return a
5+
#screen dump from the scope, saves the screen dump as a BMP in the python folder,
6+
#and closes the socket.
7+
#
8+
#Currently tested on SDS1000X-E,2000X-E, and 5000X models
9+
#
10+
#No warranties expressed or implied
11+
#
12+
#SIGLENT/JAC 03.2019
13+
#
14+
#-----------------------------------------------------------------------------
15+
import socket # for sockets
16+
import sys # for exit
17+
import time # for sleep
18+
#-----------------------------------------------------------------------------
19+
20+
remote_ip = "192.168.0.11" # should match the instrument’s IP address
21+
port = 5025 # the port number of the instrument service
22+
23+
def SocketConnect():
24+
try:
25+
#create an AF_INET, STREAM socket (TCP)
26+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
27+
except socket.error:
28+
print ('Failed to create socket.')
29+
sys.exit();
30+
try:
31+
#Connect to remote server
32+
s.connect((remote_ip , port))
33+
s.setblocking(0) # non-blocking mode, an exception occurs when no data is detected by the receiver
34+
#s.settimeout(3)
35+
except socket.error:
36+
print ('failed to connect to ip ' + remote_ip)
37+
return s
38+
39+
def SocketQuery(Sock, cmd):
40+
try :
41+
#Send cmd string
42+
Sock.sendall(cmd)
43+
Sock.sendall(b'\n') #Command termination
44+
time.sleep(1)
45+
except socket.error:
46+
#Send failed
47+
print ('Send failed')
48+
sys.exit()
49+
50+
data_body = bytes()
51+
while True:
52+
try:
53+
time.sleep(0.01)
54+
server_replay = Sock.recv(8000)
55+
#print(len(server_replay))
56+
data_body += server_replay
57+
except BlockingIOError:
58+
print("data received complete..")
59+
break
60+
return data_body
61+
'''
62+
PACK_LEN = 768067#the packet length you will receive;
63+
#SDS5000X is 2457659;SDS1000X-E/2000X-E is 768067
64+
had_received = 0
65+
data_body = bytes()
66+
67+
while had_received < PACK_LEN:
68+
part_body= Sock.recv(PACK_LEN - had_received)
69+
data_body += part_body
70+
part_body_length = len(part_body)
71+
#print('part_body_length', part_body_length)
72+
had_received += part_body_length
73+
return data_body
74+
'''
75+
76+
def SocketClose(Sock):
77+
#close the socket
78+
Sock.close()
79+
time.sleep(5)
80+
81+
def main():
82+
global remote_ip
83+
global port
84+
global count
85+
86+
#Open a file
87+
file_name = "SCDP.bmp"
88+
89+
# Body: Open a socket, query the screen dump, save and close
90+
s = SocketConnect()
91+
qStr = SocketQuery(s, b'SCDP') #Request screen image
92+
print(len(qStr))
93+
f=open(file_name,'wb')
94+
f.write(qStr)
95+
f.flush()
96+
f.close()
97+
98+
SocketClose(s)
99+
sys.exit
100+
101+
if __name__ == '__main__':
102+
proc = main()

0 commit comments

Comments
 (0)