Last active
May 3, 2019 22:33
-
-
Save csmatt/6055264 to your computer and use it in GitHub Desktop.
A simple python script to send commands to the LG AN-WL100 Wireless Media Kit through its TRS service port. Requires serial library. Tested with Python 2.7
This file contains hidden or 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
import sys, re, serial | |
def showHelp(): | |
print "" | |
print "\t%s COM_PORT_NUMBER COMMAND" % sys.argv[0] | |
print "\t\t commands can have spaces (xb 00 70) or not (xb0070)" | |
print "" | |
def getDeviceFromStr(deviceArg): | |
# if it's just an int, we'll assume it's a windows COM port | |
# otherwise, we'll take assume the whole string should be used | |
device = deviceArg | |
try: | |
device = int(deviceArg) | |
finally: | |
return device | |
def main(): | |
if (sys.argv[1] == '--help'): | |
# display help menu | |
showHelp() | |
return | |
args = sys.argv[2:] | |
# add spaces to command if not present. also always append CRLF | |
command = ' '.join(re.findall('..?', args[0]) if len(args) == 1 else args)+'\r\n' | |
h = None | |
try: | |
device = getDeviceFromStr(sys.argv[1]) | |
h = serial.Serial(device, 9600, parity=serial.PARITY_NONE) | |
h.write(command) | |
except: | |
showHelp() | |
finally: | |
if h: h.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment