nxt_pull, a companion program for nxt_push
while working with nxt_python and a few applications written in NXC, I found I had a need to get files from the NXT Brick with a minimum of fuss. The following python script will “pull” a single file from the NXT Brick. Wildcard behavior is undefined, and is planned for version 0.2.
example usage:
[gary@motoko]# nxt_pull log.txt
code:
#!/usr/bin/env python # # nxt_pull: # Pull a file to a LEGO Mindstorms NXT brick, # based on Douglas P Lau's nxt_filer and nxt_push # Copyright (C) 2008 Gary French # Version: 0.1 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. import sys import nxt.locator from nxt.brick import FileFinder, FileReader, FileWriter def read_file( b, fname ): r = FileReader(b, fname) r.__enter__() try: f = open(fname, 'wb') print 'Pulling %s ...' % (fname), try: size = 0 for data in r: f.write(data) size += len(data) finally: f.close() print 'read %d bytes' % size finally: r.__exit__(None, None, None) if __name__ == '__main__': sock = nxt.locator.find_one_brick() #sock = nxt.locator.find_one_brick(host='00:16:53:XX:XX:XX') if sock: b = sock.connect() read_file( b, sys.argv[1] ) sock.close()
Leave a comment