PythonからTCP/IPでDMM 34410Aを制御

IoTで使うPython入門Step3-計測 (1) DMM 34461A-① こちらの記事を参考にやってみた
ソース
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python3
"""
 Function Test Program
 Measuring instrument control
  
 Python3 OS:Windows or Linux
 DATE        VER   NAME     COMMENT
 2020/02/21  0.00  garyo  NEW
"""
import socket
import time
  
#ipAddr = "K-34461A-16054.local"
ipAddr = "133.100.30.202"
ports = 5025
  
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ipAddr, ports))
 
s.send(b"*IDN?\n")
print('ID: ' + str(s.recv(256)))
  
s.send(b'CONF:VOLT:AC 100,0.001\n')
s.send(b'VOLT:AC:BAND 20\n')
s.send(b'READ?\n')
print( 'AC: ' + str(s.recv(64)))
  
s.send(b'CONF:VOLT:DC 10,0.001\n')
s.send(b'READ?\n')
print( 'DC: ' + str(s.recv(64)))
 
s.send(b'READ?\n')
a1 = float(str(s.recv(64),encoding='utf-8'))
print(a1)
s.send(b'READ?\n')
a2 = float(str(s.recv(64),encoding='utf-8'))
s.send(b'READ?\n')
a3 = float(str(s.recv(64),encoding='utf-8'))
print((a1 + a2 + a3)/3)
 
s.send(b'ROUT:TERM?\n')
ret = str(s.recv(64),encoding='utf-8')
 
if ret == 'FRON\n':
    print("FRONT\n")
elif ret == 'REAR\n':
    print("REAR\n")
else:
    print("?[" + ret + "]")
 
s.send(b'SYST:BEEP\n')
time.sleep(.3)
s.send(b'SYST:BEEP\n')
time.sleep(.3)
s.send(b'SYST:BEEP\n')
 
s.close()

コメント

このブログの人気の投稿

Python OpenCVとWebカメラでバーコードリーダー

VB.net Dictionaryクラスの初期化