From fa2043f9705590f3d90f3b9644425a293de27ac7 Mon Sep 17 00:00:00 2001 From: Tat-Chee Wan (USM) Date: Mon, 16 May 2011 15:59:58 +0800 Subject: work in progress Try to read more bytes than in buffer. Initial Bluetooth code (not working). --- nxt-python-fantom/nxt/fantomglue.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/nxt-python-fantom/nxt/fantomglue.py b/nxt-python-fantom/nxt/fantomglue.py index 4ba57a7..697655f 100644 --- a/nxt-python-fantom/nxt/fantomglue.py +++ b/nxt-python-fantom/nxt/fantomglue.py @@ -54,7 +54,10 @@ class BluetoothSocket: addr, port = addrport if self._sock is None: # Port is ignored - self._sock = pyfantom.NXT(addr) + paired_addr = pair_bluetooth(addr) + if self.debug: + print "BT Paired Addr: ", paired_addr + self._sock = pyfantom.NXT(paired_addr) def send(self, data): return self._sock.write( data ) @@ -194,9 +197,9 @@ if __name__ == '__main__': #rep = nxt.recv(7) # Works, since reply is 7 bytes rep = nxt.recv(5) # Works, read length < remaining buffer content length print "read", struct.unpack('%dB' % len(rep), rep) - rep = nxt.recv(2) # Works, read length <= remaining buffer content length + rep = nxt.recv(5) # Works, remaining buffer content length is non-zero print "read", struct.unpack('%dB' % len(rep), rep) - #rep = nxt.recv(1) # Doesn't work if it exceeds buffer content length (exception) + rep = nxt.recv(1) # Doesn't work if no bytes are in read buffer # Same thing, without response. #cmd = struct.pack('2B', 0x81, 0x88) #r = nxt.send(cmd) -- cgit v1.2.3