-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransLight.py
More file actions
121 lines (92 loc) · 2.82 KB
/
transLight.py
File metadata and controls
121 lines (92 loc) · 2.82 KB
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
#-------------------------------------------------------------------------------
# Name: transLight
# Purpose: Transmission Light module thingy
#
# Author: Robert Walker
#
# Created: 15/11/2013
# Copyright: (c) Robert Walker 2013
# Licence: GPLv3
#-------------------------------------------------------------------------------
import device
import telnet as tel
from time import sleep
host = 'localhost'
port = 2004
class TransmissionLight(tel.Telnet, device.Device):
t = False
r = False
def getTStatus(self):
return self.t
def getRStatus(self):
return self.r
def getLightState(self):
if self.host is not None:
self.open()
self.write('s')
state = self.read_until('\r\n', 0.1)
self.close()
state = state.split('\r\n')
state = state[0]
if state == 't':
self.t = True
self.r = False
elif state == 'r':
self.r = True
self.t = False
elif state == 'o':
self.r = False
self.t = False
elif state =='b':
self.r = True
self.t = True
def setTransmissionLight(self, light, state = None):
"""
string light: single char string of either r or t
to signify which light to change
bool state: True for on, False for off"""
if light == 't':
lightBool = self.t
elif light == 'r':
lightBool = self.r
else:
return 'Unrecognised light'
if state == None:
state = not lightBool
if lightBool == state:
return False
self.open()
if state and not self.t and not self.r:
self.write(light)
elif state and (not self.t or not self.r):
self.write('b')
elif not state and (self.t != self.r):
self.write('o')
elif (self.t or self.r):
if light == 't':
self.write('r')
elif light == 'r':
self.write('t')
self.getLightState()
self.close()
def setRehearsalLight(self, state):
pass
def update(self):
self.getLightState()
def __init__(self, host, port):
tel.Telnet.__init__(self, host, port)
self.setName('trans')
def main():
trans = TransmissionLight(host, port)
trans.update()
print trans.getRStatus()
trans.setTransmissionLight('t', True)
print trans.getRStatus()
trans.setTransmissionLight('r', True)
print trans.getRStatus()
trans.setTransmissionLight('t', False)
print trans.getRStatus()
trans.setTransmissionLight('r', False)
print trans.getRStatus()
if __name__ == '__main__':
main()