-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGPIB.py
85 lines (62 loc) · 1.95 KB
/
GPIB.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import socket
# addr when in the tape room
#addr = '10.16.96.174'
# addr when in the equipment room
#addr = '10.16.98.79'
class GPIB:
"""
This code opens a socket to the GPIB->lan controller, and uses it
to set the synthesizer frequency.
It's not very smart or bulletproof...
"""
def __init__(self, addr, test = True, freq = None, ampl = None):
self.test = test
self.addr = addr
self.sock = None
if not test:
try:
self.sock = socket.socket()
self.sock.connect((self.addr, 1234))
except:
print "*** Could not connect GPIB to: ", self.addr
self.test = True
self.freq_cmd= ":FREQ:CW"
self.pwr_cmd= ":POW:LEV"
# history of all cmds sent to socket
self.cmds = []
self.freq = None
self.ampl = None
if freq is not None:
self.set_freq(freq)
if ampl is not None:
self.set_ampl(ampl)
self.set_rf_power("ON")
def send(self, cmd):
self.cmds.append(cmd)
if not self.test:
self.sock.send(cmd)
def set_rf_power(self, state):
cmd_str = "%s %s\r" % (":OUTP:STAT", state)
self.send(cmd_str)
def set_freq(self, freq):
self.freq = freq
self.set_frequency(str(freq)+"E6")
def set_frequency(self, freq):
cmd_str = "%s %s\r" % (self.freq_cmd, freq)
self.send(cmd_str)
def set_ampl(self, ampl):
self.ampl = ampl
self.set_power(str(ampl))
def set_power(self, pwr ):
cmd_str = "%s %s DBM\r" % (self.pwr_cmd, pwr)
self.send(cmd_str)
def close(self):
if not self.test:
self.sock.close()
def clean_up(self):
self.set_rf_power("OFF")
self.close()
if __name__ == "__main__":
gpib = GPIB("", test = True, freq = 10.0, ampl = 1.0)
gpib.clean_up()
print gpib.cmds