Skip to content

Instantly share code, notes, and snippets.

@thusoy
Created December 4, 2013 21:36
Show Gist options
  • Save thusoy/7796033 to your computer and use it in GitHub Desktop.
Save thusoy/7796033 to your computer and use it in GitHub Desktop.
A short example of how to log output from a NXT device using python. and jaraco.nxt.
def log():
print("Establishing connection...")
conn = Connection(3, timeout=5)
print('Logging output...')
while True:
print('Listening for output...')
try:
resp = conn.receive()
except struct.error:
print("Timed out")
conn.close()
time.sleep(1)
conn.open()
else:
print(parse_message(resp))
def parse_message(msg):
raw_content = msg.payload
(msg_length,) = struct.unpack('B', raw_content[0])
return raw_content[1:msg_length + 1]
if __name__ == '__main__':
log()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment