-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ether_basic.py
executable file
·109 lines (97 loc) · 2.64 KB
/
Ether_basic.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
# Built-in python functions
import sys
import time
from socket import socket, SOCK_STREAM, AF_INET
# Check the python version
if sys.version_info.major == 2:
print("\nKikusui PMX control only works with Python 3\n"
"Usage: sudo python3 command_supply.py")
sys.exit()
pass
sock = socket(AF_INET, SOCK_STREAM)
#sock.connect(('169.254.35.156', 5025))
#sock.connect(('192.168.0.10',5025))
sock.connect(('3.3.3.3', 5025))
wait_time = 0.05
buffer_size = 128
def check_output():
sock.sendall(b'output?\n')
val = int(sock.recv(buffer_size).decode('utf-8'))
if val == 0:
msg = "Measured output state = OFF"
elif val == 1:
msg = "Measured output state = ON"
else:
msg = "Failed to measure output..."
return msg, val
pass
def check_current():
sock.sendall(b'curr?\n')
val = float(sock.recv(buffer_size).decode('utf-8'))
msg = "Measured current = %.3f A" % (val)
return msg, val
pass
def check_voltage():
sock.sendall(b'volt?\n')
val = float(sock.recv(buffer_size).decode('utf-8'))
msg = "Measured voltafe = %.3f V" % (val)
return msg, val
pass
def set_current(curr_lim):
sock.sendall(b'curr %a\n' % curr_lim)
wait()
sock.sendall(b'curr?\n')
wait()
val = float(sock.recv(buffer_size).decode('utf-8'))
msg = "Current set = {}".format(val)
return msg, val
pass
def set_voltage(vol_lim):
sock.sendall(b'volt %a\n' % vol_lim)
wait()
sock.sendall(b'volt?\n')
wait()
val = float(sock.recv(buffer_size).decode('utf-8'))
msg = "Voltage set = {}".format(val)
return msg, val
pass
def turn_on(notmakesure=False):
""" Turn the PMX on """
if notmakesure == True:
sock.sendall(b'output 1\n')
msg = "PMX turned ON perhaps\n"
return msg
pass
else:
sock.sendall(b'output 1\n')
wait()
sock.sendall(b'output?\n')
wait()
val = int(sock.recv(buffer_size).decode('utf-8'))
msg = "Output state = {}".format(val)
return msg
pass
pass
def turn_off(notmakesure=False):
""" Turn the PMX on """
if notmakesure == True:
sock.sendall(b'output 0\n')
msg = "PMX turned OFF perhaps\n"
return msg
pass
else:
sock.sendall(b'output 0\n')
wait()
sock.sendall(b'output?\n')
wait()
val = int(sock.recv(buffer_size).decode('utf-8'))
msg = "Output state = {}".format(val)
return msg
pass
pass
def wait():
time.sleep(wait_time)
return 0
pass
if __name__ == '__main__':
print('this is basic functions for ethernet control')