summaryrefslogtreecommitdiff
path: root/nxt-python-fantom/nxt/lightblueglue.py
diff options
context:
space:
mode:
authorTat-Chee Wan (USM)2011-03-01 09:10:13 +0800
committerTat-Chee Wan (USM)2011-03-01 09:10:13 +0800
commit5b5271e98c6d7f0ffea9d6b3fbf2cec43d283d64 (patch)
tree87624772defa75852f127d519a252686b2a338ba /nxt-python-fantom/nxt/lightblueglue.py
parenta017874bb2a7881aaaf57832049fe281191c05c2 (diff)
Imported nxt-python baseline (v2.1.0)
Diffstat (limited to 'nxt-python-fantom/nxt/lightblueglue.py')
-rw-r--r--nxt-python-fantom/nxt/lightblueglue.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/nxt-python-fantom/nxt/lightblueglue.py b/nxt-python-fantom/nxt/lightblueglue.py
new file mode 100644
index 0000000..f2ab92f
--- /dev/null
+++ b/nxt-python-fantom/nxt/lightblueglue.py
@@ -0,0 +1,53 @@
+# bluetooth.py module -- Glue code from NXT_Python to Lightblue, allowing
+# NXT_Python to run on Mac without modification. Supports subset of
+# PyBluez/bluetooth.py used by NXT_Python.
+#
+# Copyright (C) 2007 Simon D. Levy
+#
+# 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 3 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 lightblue
+
+RFCOMM=11
+
+def discover_devices(lookup_names=False): # parameter is ignored
+ pairs = []
+ d = lightblue.finddevices()
+ for p in d:
+ h = p[0]
+ n = p[1]
+ pairs.append((h, n))
+ return pairs
+
+class BluetoothSocket:
+
+ def __init__(self, proto = RFCOMM, _sock=None):
+ if _sock is None:
+ _sock = lightblue.socket(proto)
+ self._sock = _sock
+ self._proto = proto
+
+ def connect(self, addrport):
+ addr, port = addrport
+ self._sock.connect( (addr, port ))
+
+ def send(self, data):
+ return self._sock.send( data )
+
+ def recv(self, numbytes):
+ return self._sock.recv( numbytes )
+
+ def close(self):
+ return self._sock.close()
+
+class BluetoothError(IOError):
+ pass
+