~rumpelsepp/netzteil

netzteil/netzteil -rwxr-xr-x 1.8 KiB View raw
f4d0e1adStefan Tatschner New defaults a month ago
                                                                                
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
#!/usr/bin/python3

import argparse
import socket
import time


class PowerSupply:

    def __init__(self, host, port):
        self.host = host
        self.port = port
        self.s = socket.create_connection((host, port))

    def send_cmd(self, cmd):
        self.s.send(str(cmd+'\n').encode())

    def default_setup(self):
        self.send_cmd("*RST")
        time.sleep(5)
        self.send_cmd("INST OUT1")
        self.send_cmd("VOLT 12")
        self.send_cmd("CURR 2.6")
        self.send_cmd("OUTP:CHAN ON")

        self.send_cmd("INST OUT2")
        self.send_cmd("VOLT 12")
        self.send_cmd("CURR 1.3")
        self.send_cmd("OUTP:CHAN ON")

        self.send_cmd("INST OUT3")
        self.send_cmd("VOLT 12")
        self.send_cmd("CURR 1.2")
        self.send_cmd("OUTP:CHAN ON")

        self.send_cmd("OUTP:MAST ON")

    def set_chan(self, chan, val):
        if val.lower() not in ("on", "off"):
            raise ValueError
        if chan == "master":
            self.send_cmd(f"OUTP:MAST {val}")
        else:
            self.send_cmd(f"INST {chan}")
            self.send_cmd(f"OUTP:CHAN {val}")


def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument("host", help="The hostname or IP of the device")
    parser.add_argument("-p", type=int, help="TCP port to connect to")
    parser.add_argument("-d", action='store_true', help="Apply default settings")
    parser.add_argument("-s", default=None, help="Set channel")
    parser.add_argument("-c", default="master", help="Channel to operate on")
    return parser.parse_args()


def main():
    args = parse_args()
    p = PowerSupply(args.host, args.p)
    if args.d:
        p.default_setup()
    if args.s is not None:
        p.set_chan(args.c, args.s)


if __name__ == '__main__':
    main()