Created
September 2, 2012 21:53
-
-
Save anonymous/3604866 to your computer and use it in GitHub Desktop.
Control your printer ;D
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/python | |
import socket, sys, os | |
_hostname = '10.44.3.92'; | |
_port = 9100; | |
_pjlUEL = '%-12345X'; | |
def sendString(string): | |
command = chr(27) + _pjlUEL + '@PJL \r\n' \ | |
+ string + ' \r\n' \ | |
+ chr(27) + _pjlUEL; | |
sock = socket.socket(); | |
sock.connect((_hostname, _port)); | |
print "Sending message:"; | |
print command; | |
print "... " + str(sock.send(command)); | |
sock.close(); | |
def sendFile(name): | |
if os.path.exists(name) == False: | |
print "File doesn't exist." | |
return; | |
f = open(name, 'r'); | |
raw = f.read(); | |
f.close(); | |
command = '@PJL ENTER LANGUAGE = POSTSCRIPT \r\n'; | |
command = command + raw; | |
sendString(command); | |
def multiplex(command, param): | |
if command == "screen" : | |
sendString('@PJL RDYMSG DISPLAY="' + param + '"'); | |
return; | |
if command == "status" : | |
sendString('@PJL STMSG DISPLAY="' + param + '"'); | |
return; | |
if command == "file" : | |
sendFile(param); | |
return; | |
print "Unknown." | |
if __name__ == "__main__": | |
""" Logically, we want the weirdest chaos. """ | |
if len(sys.argv) < 2: | |
print 'usage: ./script.py "<message>"'; | |
exit(); | |
if len(sys.argv) > 2: | |
multiplex(sys.argv[1], sys.argv[2]); | |
else: | |
sendString(sys.argv[1]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment