From 05b196d6bf26b0fe70a43607269f88187f595673 Mon Sep 17 00:00:00 2001 From: Tat-Chee Wan (USM) Date: Wed, 4 May 2011 08:17:53 +0800 Subject: work in progress Tracing Exception in NXTIterator.get_nxt() which is triggered when invoking fantomglue.find_devices() --- nxt-python-fantom/nxt/fantomglue.py | 12 +++++++++--- nxt-python-fantom/nxt/pyusbglue.py | 2 +- nxt-python-fantom/nxt/usbsock.py | 4 +++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/nxt-python-fantom/nxt/fantomglue.py b/nxt-python-fantom/nxt/fantomglue.py index ac125ed..96bcd3c 100644 --- a/nxt-python-fantom/nxt/fantomglue.py +++ b/nxt-python-fantom/nxt/fantomglue.py @@ -16,6 +16,8 @@ import pyfantom +USB_BUFSIZE = 64 + RFCOMM=11 # lightblue const FANTOM_BT = RFCOMM # For compatibilty with lightblue FANTOM_USB = 0 @@ -66,9 +68,12 @@ def _check_brick(arg, value): def find_devices(lookup_names=False): # parameter is ignored devicelist = [] for d in pyfantom.NXTIterator(False): - #name = d.get_name() - #print "NXT name: ", name + addr = d.get_resource_string() + print "NXT addr: ", addr nxt = d.get_nxt() + # BUG?: If nxt.get_firware_version() is enabled, d.get_nxt() will throw an exception + # Related to Reference Counting for Obj-C Objects? + #print " firmware version:", nxt.get_firmware_version() devicelist.append(nxt) return devicelist @@ -90,6 +95,7 @@ class USBSocket: def __init__(self, device=None): # We instantiate a NXT object only when we connect if none supplied + # FIXME: The addr is not passed in, so we can't actually create a NXT object later #self.device = device self._sock = device self.debug = False @@ -101,7 +107,7 @@ class USBSocket: def connect(self): if self._sock is None: # Port is ignored - self._sock = pyfantom.NXT(addr) + self._sock = pyfantom.NXT(addr) # FIXME: No address! def send(self, data): return self._sock.write( data ) diff --git a/nxt-python-fantom/nxt/pyusbglue.py b/nxt-python-fantom/nxt/pyusbglue.py index 40f708b..c0f8792 100644 --- a/nxt-python-fantom/nxt/pyusbglue.py +++ b/nxt-python-fantom/nxt/pyusbglue.py @@ -16,6 +16,7 @@ import usb +USB_BUFSIZE = 64 ID_VENDOR_LEGO = 0x0694 ID_PRODUCT_NXT = 0x0002 @@ -44,7 +45,6 @@ class USBSocket: self.handle.reset() if self.debug: print 'Connected.' - return Brick(self) def close(self): 'Use to close the connection.' diff --git a/nxt-python-fantom/nxt/usbsock.py b/nxt-python-fantom/nxt/usbsock.py index 9df7792..aa766a8 100644 --- a/nxt-python-fantom/nxt/usbsock.py +++ b/nxt-python-fantom/nxt/usbsock.py @@ -12,6 +12,8 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. +USB_BUFSIZE = 64 + try: import fantomglue as usb except ImportError: @@ -55,7 +57,7 @@ class USBSock(object): def recv(self): 'Use to recieve raw data over USB connection ***ADVANCED USERS ONLY***' - data = self.sock.recv(64) + data = self.sock.recv(USB_BUFSIZE) if self.debug: print 'Recv:', print ':'.join('%02x' % (c & 0xFF) for c in data) -- cgit v1.2.3