aboutsummaryrefslogtreecommitdiff
path: root/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py
diff options
context:
space:
mode:
authorTC Wan2011-05-04 15:20:50 +0800
committerTC Wan2011-05-04 15:20:50 +0800
commita37cdc84494a314a1f67701c0c1beafc6c98c034 (patch)
tree1d33cc55706ad9c916d6bdb825fca1a4fb278be3 /AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py
parentb97df7cade4aef09d7af6433483b6d23858b3f10 (diff)
parent667197864959c669690dedd4de835328a5560201 (diff)
Merge branch 'master' of ssh://svc.cs.usm.my/~/gitrepo-bare/armdebug
Diffstat (limited to 'AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py')
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py48
1 files changed, 46 insertions, 2 deletions
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py
index aa766a8..70af774 100644
--- a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py
@@ -28,7 +28,7 @@ class USBSock(object):
def __init__(self, device):
self.sock = usb.USBSocket(device)
- self.debug = False
+ self.debug = True
def __str__(self):
return 'USB (%s)' % (self.sock.device_name())
@@ -57,7 +57,7 @@ class USBSock(object):
def recv(self):
'Use to recieve raw data over USB connection ***ADVANCED USERS ONLY***'
- data = self.sock.recv(USB_BUFSIZE)
+ data = self.sock.recv(USB_BUFSIZE) # FIXME: This will cause an exception since we cannot read more than the actual buffer contents
if self.debug:
print 'Recv:',
print ':'.join('%02x' % (c & 0xFF) for c in data)
@@ -68,7 +68,51 @@ def _check_brick(arg, value):
return arg is None or arg == value
def find_bricks(host=None, name=None):
+ get_info = False
'Use to look for NXTs connected by USB only. ***ADVANCED USERS ONLY***'
for d in usb.find_devices(lookup_names=True):
+ if get_info:
+ print " firmware version:", d.get_firmware_version()
+ print " get device info:", d.get_device_info()
+ rs = d.get_resource_string()
+ print " resource string:", rs
# FIXME: probably should check host and name
yield USBSock(d)
+
+if __name__ == '__main__':
+ write_read = True
+ socks = find_bricks()
+ for s in socks:
+ print s.sock
+ brick = s.connect()
+ if write_read:
+ import struct
+ # Write VERSION SYS_CMD.
+ # Query:
+ # SYS_CMD: 0x01
+ # VERSION: 0x88
+ cmd = struct.pack('2B', 0x01, 0x88)
+ #brick.sock.send(cmd)
+ #s.send(cmd)
+ s.sock.send(cmd)
+ print "wrote", len(cmd)
+ # Response:
+ # REPLY_CMD: 0x02
+ # VERSION: 0x88
+ # SUCCESS: 0x00
+ # PROTOCOL_VERSION minor
+ # PROTOCOL_VERSION major
+ # FIRMWARE_VERSION minor
+ # FIRMWARE_VERSION major
+ #rep = brick.sock.recv()
+ #rep = s.recv()
+ rep = s.sock.recv(7)
+ print "read", struct.unpack('%dB' % len(rep), rep)
+ # Same thing, without response.
+ #cmd = struct.pack('2B', 0x81, 0x88)
+ #brick.sock.send(cmd)
+ #print "wrote", cmd
+ #rep = brick.sock.recv()
+ #print "read", struct.unpack('%dB' % len(rep), rep)
+ del brick
+