Created
December 11, 2013 23:47
-
-
Save inbinder/7920694 to your computer and use it in GitHub Desktop.
This is a program I wrote while working as a projectionist at a movie theater after their automation which controls the projector power failed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from Tkinter import * | |
from socket import * | |
port = 7142 | |
on = '02 00 00 00 00' | |
off = '02 01 00 00 00' | |
lamp = "03 2F 00 00 02 12" | |
shutter = "02 17 00 00 00" | |
def callback_power_on(data, host): | |
try: | |
connection = socket(AF_INET, SOCK_STREAM) | |
connection.connect((host, port)) | |
connection.sendall(add_checksum(data)) | |
connection.close() | |
test_var = add_checksum(data) | |
print test_var | |
return 1 | |
except: pass | |
def callback_shutter(data, host): | |
try: | |
connection = socket(AF_INET, SOCK_STREAM) | |
connection.connect((host, port)) | |
connection.sendall(add_checksum(data)) | |
onnection.close() | |
# test_var = add_checksum(data) | |
print test_var | |
return 1 | |
except: pass | |
def callback_power_off(data): | |
try: | |
connection = socket(AF_INET, SOCK_STREAM) | |
connection = socket(AF_INET, SOCK_STREAM) | |
connection.connect((host, port)) | |
connection.sendall(add_checksum(data)) | |
connection.close() | |
test_var = add_checksum(data) | |
print test_var | |
return 1 | |
except: pass | |
connection = socket(AF_INET, SOCK_STREAM) | |
connection = socket(AF_INET, SOCK_STREAM) | |
connection.connect((host, port)) | |
connection.sendall(add_checksum(data)) | |
connection.close() | |
def add_checksum(s): | |
result = [] | |
acc = 0 | |
for hexcode in s.split(): | |
code = int(hexcode, 16) | |
acc += code | |
result.append(chr(code)) | |
result.append(chr(acc)) | |
return ''.join(result) | |
def format_wih_checksum(s): | |
"""Given a string of whitespace-separated, two-digit hexadecimal | |
representations of byte values, returns a string of the represented byte | |
values, followed by a checksum byte. The checksum is the sum of the input | |
string's byte values, modulo 256. | |
""" | |
xs = [int(x, 16) for x in s.split()] | |
return ''.join(chr(x) for x in xs) + chr(sum(xs)) | |
print ''.join(chr(x) for x in xs) + chr(sum(xs)) | |
master = Tk() | |
host = StringVar() | |
Radiobutton(master, text="Silas",indicatoron = 0, variable = host, value ='172.25.13.10').pack(anchor=W) | |
Radiobutton(master, text="Beatrice", indicatoron = 0, variable = host, value ='172.25.13.12').pack(anchor=W) | |
b = Button( | |
master, | |
text="Power On", | |
command=lambda: callback_power_on(on, host.get())) | |
b.pack() | |
c = Button( | |
master, | |
text="Power Off", | |
command=lambda: callback_power_off(off, host.get())) | |
c.pack() | |
d = Button( | |
master, | |
text="Dowser Open", | |
command=lambda: callback_shutter(shutter, host.get())) | |
d.pack() | |
mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment