Blame view
instruments/AG34972A.py
2.2 KB
6cdd466f1 Add files via upload |
1 2 3 4 5 6 7 8 9 10 |
from abstract_instrument import abstract_instrument import socket #============================================================================== ALL_VAL_TYPE = "DCV, ACV, DCI, ACI, RES2W, RES4W, FREQ" #============================================================================== class AG34972A(abstract_instrument): |
10016888c replace 4 spaces ... |
11 12 13 14 |
def __init__(self, adress="192.168.0.72", vtype="DCV"): self.adress = adress self.port = 5025 self.vtype = vtype |
6cdd466f1 Add files via upload |
15 |
|
10016888c replace 4 spaces ... |
16 17 18 |
def model(self): self.send("*IDN?") return self.read() |
6cdd466f1 Add files via upload |
19 |
|
10016888c replace 4 spaces ... |
20 21 22 23 24 25 26 27 28 |
def connect(self): try: print('Connecting to device @%s:%s...' %(self.adress, self.port)) self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) self.sock.settimeout(2.0) # Don't hang around forever self.sock.connect((self.adress, self.port)) print(' --> Ok') |
6cdd466f1 Add files via upload |
29 |
|
10016888c replace 4 spaces ... |
30 |
print(self.model()) |
6cdd466f1 Add files via upload |
31 |
|
10016888c replace 4 spaces ... |
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
if self.vtype == "DCV": self.send("CONF:VOLT:DC (@102:103)") elif self.vtype == "ACV": self.send("CONF:VOLT:AC (@102:103)") elif self.vtype == "DCI": self.send("CONF:CURR:DC (@102:103)") elif self.vtype == "ACI": self.send("CONF:CURR:AC (@102:103)") elif self.vtype == "RES2W": self.send("CONF:RES (@102:103)") elif self.vtype == "RES4W": self.send("CONF:FRES (@102:103)") elif self.vtype == "FREQ": self.send("CONF:FREQ (@102:103)") else: print("Wrong -v argument") raise |
6cdd466f1 Add files via upload |
49 |
|
10016888c replace 4 spaces ... |
50 51 52 53 54 55 56 57 58 |
except socket.timeout: print("Socket timeout error during connection.") raise except socket.error as er: print("Socket error during connection: " + str(er)) raise except Exception as er: print("Unexpected error during connection: " + str(er)) raise |
6cdd466f1 Add files via upload |
59 |
|
10016888c replace 4 spaces ... |
60 61 62 |
def getValue(self): self.send("MEAS? AUTO,DEF,(@102:103)") return self.read() |
6cdd466f1 Add files via upload |
63 |
|
10016888c replace 4 spaces ... |
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
def read(self): ans = '' nb_data_list = [] nb_data = '' try: while ans != ' ': ans = self.sock.recv(1) nb_data_list.append(ans) # Return the number of data list_size = len(nb_data_list) for j in range (0, list_size): nb_data = nb_data+nb_data_list[j] return nb_data except socket.timeout: print "Socket timeout error when reading." raise |
6cdd466f1 Add files via upload |
80 |
|
10016888c replace 4 spaces ... |
81 82 83 |
def disconnect(self): self.send('*RST') self.sock.close() |
6cdd466f1 Add files via upload |
84 |
|
10016888c replace 4 spaces ... |
85 86 87 |
def send(self, command): self.sock.send("%s "%command) |