Created
December 4, 2013 21:36
-
-
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.
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
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