5 from contextlib
import closing
8 """ This is a patlite state class """ 40 if i == 0:
return '\x00' 41 elif i == 1:
return '\x01' 42 elif i == 2:
return '\x02' 43 elif i == 3:
return '\x03' 44 elif i == 4:
return '\x04' 48 if c ==
'\x00':
return 0
49 elif c ==
'\x01':
return 1
50 elif c ==
'\x02':
return 2
51 elif c ==
'\x03':
return 3
52 elif c ==
'\x04':
return 4
57 self.LightState.REMAIN + \
58 self.LightState.REMAIN + \
59 self.LightState.REMAIN + \
60 self.LightState.REMAIN + \
61 self.LightState.REMAIN + \
62 self.BuzzerState.REMAIN
104 return "<PatliteState '%s'>" % (
''.join([
'%x ' % ord(s)
for s
in self.
state]))
109 """ This is a controller for a network patlite """ 112 WRITE_HEADER =
'\x58\x58\x53\x00\x00\x06' 118 READ =
'\x58\x58\x47\x00\x00\x00' 121 CLEAR =
'\x58\x58\x43\x00\x00\x00' 134 def __exit__(self, exc_type, exc_value, traceback):
139 self.
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
140 self.sock.settimeout(self.
timeout)
141 return self.sock.connect((self.
host, self.
port))
144 return self.sock.close()
152 ret = self.sock.recv(self.
bufsize)
153 except socket.timeout:
155 if (ret != self.
ACK):
161 self.sock.sendall(self.
READ)
163 except socket.timeout:
171 self.sock.sendall(self.
CLEAR)
172 ret = self.sock.recv(self.
bufsize)
173 except socket.timeout:
176 if (ret != self.
ACK):
182 self.state.red(value)
187 self.state.yellow(value)
192 self.state.green(value)
197 self.state.blue(value)
202 self.state.white(value)
207 self.state.buzzer(value)
212 patlite =
Patlite(
"10.68.0.10")
214 patlite.red(patlite.state.LightState.ON)
215 patlite.yellow(patlite.state.LightState.ON)
216 patlite.green(patlite.state.LightState.ON)
218 if __name__ ==
'__main__':
def write(self, state=None)
def __init__(self, state=None)
def __exit__(self, exc_type, exc_value, traceback)
def is_valid(self, target, state)
def set_from_int(self, target, state)
def __init__(self, host, port=10000, timeout=1)