From 99c3816f4ae37ed3f99fa6fd2da67f752fd55cfa Mon Sep 17 00:00:00 2001 From: Tat-Chee Wan (USM) Date: Wed, 4 May 2011 08:46:36 +0800 Subject: added test case for fantomglue using pyfantom test case --- nxt-python-fantom/nxt/fantomglue.py | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/nxt-python-fantom/nxt/fantomglue.py b/nxt-python-fantom/nxt/fantomglue.py index 96bcd3c..5df42c6 100644 --- a/nxt-python-fantom/nxt/fantomglue.py +++ b/nxt-python-fantom/nxt/fantomglue.py @@ -118,3 +118,52 @@ class USBSocket: def close(self): if self._sock is not None: del self._sock + +if __name__ == '__main__': + #get_info = False + get_info = True + write_read = True + for i in pyfantom.NXTIterator(False): + # Enable Bluetooth Interface + #for i in pyfantom.NXTIterator(True): + if get_info: + print "name:", i.get_name() + print "resource string:", i.get_resource_string() + print "get_nxt:" + nxt = i.get_nxt() + print " firmware version:", nxt.get_firmware_version() + print " get device info:", nxt.get_device_info() + rs = nxt.get_resource_string() + print " resource string:", rs + del nxt + print "NXT():" + nxt = pyfantom.NXT(rs) + print " resource string:", nxt.get_resource_string() + del nxt + if write_read: + nxt = i.get_nxt() + import struct + # Write VERSION SYS_CMD. + # Query: + # SYS_CMD: 0x01 + # VERSION: 0x88 + cmd = struct.pack('2B', 0x01, 0x88) + r = nxt.write(cmd) + print "wrote", r + # Response: + # REPLY_CMD: 0x02 + # VERSION: 0x88 + # SUCCESS: 0x00 + # PROTOCOL_VERSION minor + # PROTOCOL_VERSION major + # FIRMWARE_VERSION minor + # FIRMWARE_VERSION major + rep = nxt.read(7) + print "read", struct.unpack('%dB' % len(rep), rep) + # Same thing, without response. + cmd = struct.pack('2B', 0x81, 0x88) + r = nxt.write(cmd) + print "wrote", r + rep = nxt.read(7) + print "read", struct.unpack('%dB' % len(rep), rep) + del nxt -- cgit v1.2.3