summaryrefslogtreecommitdiff
path: root/AT91SAM7S256
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-05-05 14:19:57 +0800
committerTat-Chee Wan (USM)2011-05-05 14:19:57 +0800
commit95844a4c56675f5130893ef0c52caa58567cb352 (patch)
treee7d34ce728be74b678b3f28870cbb4d1f465240e /AT91SAM7S256
parenta37cdc84494a314a1f67701c0c1beafc6c98c034 (diff)
parentb8c8045ffdff1e0d5337398563ed6b86d3661040 (diff)
Merge branch 'master' of ssh://svc.cs.usm.my/~/gitrepo-bare/armdebug
Diffstat (limited to 'AT91SAM7S256')
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/brick.py1
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/fantomglue.py26
-rw-r--r--AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py35
3 files changed, 51 insertions, 11 deletions
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/brick.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/brick.py
index 740ccbd..240ba27 100644
--- a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/brick.py
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/brick.py
@@ -217,6 +217,7 @@ class Brick(object): #TODO: this begs to have explicit methods
sleep(duration / 1000.0)
def __del__(self):
+ print "Deleting Brick"
self.sock.close()
find_files = FileFinder
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/fantomglue.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/fantomglue.py
index 359427d..16d9608 100644
--- a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/fantomglue.py
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/fantomglue.py
@@ -64,7 +64,16 @@ class BluetoothSocket:
def close(self):
if self._sock is not None:
del self._sock
-
+ self._sock = None
+
+ def __del__(self):
+ """Destroy interface."""
+ if self._sock is not None:
+ del self._sock
+ print "NXT object deleted"
+ else:
+ print "No NXT Object when calling __del__ for BluetoothSocket"
+
class BluetoothError(IOError):
pass
@@ -127,10 +136,25 @@ class USBSocket:
def recv(self, numbytes):
return self._sock.read( numbytes )
+
+ #def poll_command(self, numbytes):
+ # I'm not sure if this is specific to Direct Command Processing
+ # Or if it refers to any data transmission
+ #print "Bytes Available:", self._sock.bytes_available()
+ #return self._sock.read_buffer( numbytes, 0 )
def close(self):
if self._sock is not None:
del self._sock
+ self._sock = None
+
+ def __del__(self):
+ """Destroy interface."""
+ if self._sock is not None:
+ del self._sock
+ print "NXT object deleted"
+ else:
+ print "No NXT Object when calling __del__ for USBSocket"
if __name__ == '__main__':
#get_info = False
diff --git a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py
index 70af774..5ff2b36 100644
--- a/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py
+++ b/AT91SAM7S256/armdebug/nxt-python-fantom/nxt/usbsock.py
@@ -45,6 +45,7 @@ class USBSock(object):
if self.debug:
print 'Closing USB connection...'
self.sock.close()
+ #self.sock = None
if self.debug:
print 'USB connection closed.'
@@ -55,14 +56,21 @@ class USBSock(object):
print ':'.join('%02x' % ord(c) for c in data)
self.sock.send(data)
- def recv(self):
+ def recv(self, num_bytes=USB_BUFSIZE):
'Use to recieve raw data over USB connection ***ADVANCED USERS ONLY***'
- data = self.sock.recv(USB_BUFSIZE) # FIXME: This will cause an exception since we cannot read more than the actual buffer contents
+ data = self.sock.recv(num_bytes)
if self.debug:
print 'Recv:',
- print ':'.join('%02x' % (c & 0xFF) for c in data)
- # NOTE: bulkRead returns a tuple of ints ... make it sane
- return ''.join(chr(d & 0xFF) for d in data)
+ print ':'.join('%02x' % ord(c) for c in data)
+ return data
+
+ def __del__(self):
+ """Destroy interface."""
+ if self.sock is not None:
+ del self.sock
+ if self.debug:
+ print 'Deleted USBSocket.'
+
def _check_brick(arg, value):
return arg is None or arg == value
@@ -72,6 +80,7 @@ def find_bricks(host=None, name=None):
'Use to look for NXTs connected by USB only. ***ADVANCED USERS ONLY***'
for d in usb.find_devices(lookup_names=True):
if get_info:
+ # pyfantom specific debug info
print " firmware version:", d.get_firmware_version()
print " get device info:", d.get_device_info()
rs = d.get_resource_string()
@@ -83,6 +92,9 @@ if __name__ == '__main__':
write_read = True
socks = find_bricks()
for s in socks:
+ #llsocks = usb.find_devices()
+ #for ls in llsocks:
+ #s = USBSock(ls)
print s.sock
brick = s.connect()
if write_read:
@@ -92,9 +104,9 @@ if __name__ == '__main__':
# SYS_CMD: 0x01
# VERSION: 0x88
cmd = struct.pack('2B', 0x01, 0x88)
- #brick.sock.send(cmd)
+ brick.sock.send(cmd)
#s.send(cmd)
- s.sock.send(cmd)
+ #s.sock.send(cmd)
print "wrote", len(cmd)
# Response:
# REPLY_CMD: 0x02
@@ -104,9 +116,9 @@ if __name__ == '__main__':
# PROTOCOL_VERSION major
# FIRMWARE_VERSION minor
# FIRMWARE_VERSION major
- #rep = brick.sock.recv()
- #rep = s.recv()
- rep = s.sock.recv(7)
+ rep = brick.sock.recv(7)
+ #rep = s.recv(7)
+ #rep = s.sock.recv(7)
print "read", struct.unpack('%dB' % len(rep), rep)
# Same thing, without response.
#cmd = struct.pack('2B', 0x81, 0x88)
@@ -114,5 +126,8 @@ if __name__ == '__main__':
#print "wrote", cmd
#rep = brick.sock.recv()
#print "read", struct.unpack('%dB' % len(rep), rep)
+ #s.close()
+ #del s
+ #brick.sock.close()
del brick