-
Notifications
You must be signed in to change notification settings - Fork 2
/
KrammerControl.py
74 lines (44 loc) · 1.56 KB
/
KrammerControl.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import socket
import time
class KrammerControl(object):
def __init__(self,ip="10.1.10.9",port=5000):
self.ip = ip
self.port = port
self.KrammerState()
def callTCP(self, message):
socke = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socke.connect((self.ip,self.port))
socke.settimeout(10)
socke.send(message.encode('ascii'))
data = socke.recv(4096)
print("On a envoyé "+ message)
if data :
print("La réponse reçu est "+data.decode('ascii'))
else :
print("Hahaha")
socke.close()
def KrammerState(self):
print("Getting the state of the Krammer switch at the ip address "+self.ip)
self.callTCP("#VID? * \r\n")
#Get the input/output in a format "i1>o1,i2>o2...i8>o8" of the current configuration
#We can reformat this output in this function
def getInput(self,output):
message = "#VID? "+str(input)+" \r\n"
self.callTCP(message)
#Get the output corresponding to the input
def setInOut(self,input,output):
message = "#VID "+str(input)+">"+str(output)+" \r\n"
self.callTCP(message)
#Set the output to the specific input
def callPreset(self, presetnum):
#Call the preset that has the number presetnum
message = "#PRST-RCL "+str(presetnum)+" \r\n"
self.callTCP(message)
def savePreset(self, presetnum):
message = "#PRST-STO "+str(presetnum)+" \r\n"
self.callTCP(message)
#Save the current current configuration in the preset that has the number presetnum
if __name__ == '__main__':
kramkram = KrammerControl()