-
Notifications
You must be signed in to change notification settings - Fork 7
/
hp3336c.py
141 lines (121 loc) · 2.48 KB
/
hp3336c.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/local/bin/python
import sys
import time
import prologix_usb
class hp3336c(prologix_usb.gpib_dev):
def __init__(self, name = "gpib0", adr = 13):
prologix_usb.gpib_dev.__init__(self, name, adr)
self.attr("eos", 2)
self.attr("spoll_data", 0x00)
self.attr("spoll_cmd", 0x0)
self.errors()
self.id = "HP3336C"
self.AOK()
#######################
# PYLT Standard methods
#######################
def errors(self, f=sys.stderr):
r = False
while True:
x = self.ask("IER")
if x == "ER0":
break
f.write(self.id + ".ERROR: " + x + "\n")
r = True
return r
##################
# HP3336C methods
##################
def set_freq(self, hz):
self.wr("FR%.3fHZ" % hz)
self.AOK()
def read_freq(self):
x = self.ask("IFR")
self.AOK()
assert x[:2] == "FR"
assert x[-2:] == "HZ"
return float(x[2:-2])
def set_dbm(self, dbm):
self.wr("AM%.3fDB" % dbm)
self.AOK()
def read_dbm(self):
x = self.ask("IAM")
self.AOK()
assert x[:2] == "AM"
assert x[-2:] == "DB"
return float(x[2:-2])
if __name__ == "__main__":
d = hp3336c()
print("Device reponds (%s)" % d.id)
print("Freq: %.11e Hz %.1f dBm" % (d.read_freq(), d.read_dbm()))
doc="""
Commands:
---------
FF hz Frequency
FR hz Frequency
AM dbm Amplitude
PH deg Phase
ST hz Sweep Start Frequency
SP hz Sweep Stop Frequency
MF hz Marker Frequency
TI sec Sweep time
FL0 Fast Levelling off
FL1 Fast Levelling on
MD1 Data transfermode 1
MD2 Data transfermode 2 (buffered to max 48 char)
SM1 Linear Sweep
SM2 Log Sweep
AP Assign Zero Phase
SS Start Single Sweep (send twice)
SC Start Continuos Sweep
SR digit Store Program
RE digit Recall Program
MS [@-O] Masking Service Requests
A B C
OI1 75 Ohm 75 Ohm 50 Ohm
OI2 150 Ohm 124 Ohm 75 Ohm
OI3 600 Ohm 135 Ohm
OI4 600 Ohm
MA0 AM off
MA1 AM on
MP0 PM off
MP1 PM on
AB0 Amplitude Blanking off
AB1 Amplitude Blanking on
Queries:
--------
IFR Query Frequency
IFF --//--
IAM Amplitude
IPH Phase
IST Sweep Start Freq
ISP Sweep Stop Freq
IMF Marker Freq
ITI Sweep Time
IOI Impedance
ISM Sweep Mode
IMA AM mod
IMP PM mod
IER Error Code
IAB Amplitude Blocking
IFL Fast Levelling
Units:
------
HH Hertz
HZ Hertz
KH KiloHertz
MH MegaHertz
DB dBm
DE Degrees
SE Seconds
Errors:
-------
0 No error
1 Entry param data is absolutely out of bounds
2 Invalid units
4 Sweep time too small
6 Sweep BW too small (ST to small for log, ST > SP)
7 Unrecognized program from HP-IB
8 Unrecognized char received
9 Option does not exist
"""