Skip to content

Instantly share code, notes, and snippets.

@csmatt
Last active May 3, 2019 22:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save csmatt/6055264 to your computer and use it in GitHub Desktop.
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
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