diff usb488.py @ 2:adaff1c4fd6b

Rip out procedural interface and use the OO one.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 13 May 2009 15:26:42 +0930
parents e2089824735a
children 62ffab79227e
line wrap: on
line diff
--- a/usb488.py	Wed May 13 15:02:09 2009 +0930
+++ b/usb488.py	Wed May 13 15:26:42 2009 +0930
@@ -251,74 +251,13 @@
             result = result[0:-1]
 
         return result
-    
-def find488():
-    """Search for a USB488 device, returns a handle, iface, dev tuple for it"""
-
-    busses = usb.busses()
-    
-    found = False
-    for bus in busses:
-        for dev in bus.devices:
-            for confidx in xrange(len(dev.configurations)):
-                # XXX: what do multi-interface devices look like?
-                iface = dev.configurations[confidx].interfaces[0][0]
-                # Check if this is a USB488 capable interface
-                if iface.interfaceClass == USB_CLASS_APP_SPECIFIC and \
-                   iface.interfaceSubClass == USB_SUBCLASS_TMC and \
-                   iface.interfaceProtocol == USB_PROTOCOL_488:
-                    handle = dev.open()
-                    handle.setConfiguration(1)
-                    handle.claimInterface(0)
-                    handle.setAltInterface(0)
-                    #handle.setConfiguration(confidx)
-                    #handle.claimInterface(0)
-                    found = True
-                    break
-
-        if found:
-            break
-    
-    if not found:
-        raise "Could not find scope, check perms"
-    
-    return (handle, iface, dev)
-
-def geteps(iface):
-    """Returns a tuple of intr,input,output addresses of endpoints for the interface"""
-    intrep = bulkinep = bulkoutep = None
-    
-    for ep in iface.endpoints:
-        if ep.type == usb.ENDPOINT_TYPE_INTERRUPT and \
-               ep.address & usb.ENDPOINT_IN == usb.ENDPOINT_IN:
-            intrep = ep.address
-
-        if ep.type == usb.ENDPOINT_TYPE_BULK:
-            if ep.address & usb.ENDPOINT_IN == usb.ENDPOINT_IN:
-                bulkinep = ep.address
-            else:
-                bulkoutep = ep.address
-
-    # Required for 488.2 devices, optional otherwise
-    if intrep == None:
-        print "Can't find interrup endpoint"
-
-    # Data from the scope
-    if bulkinep == None:
-        raise "Can't find bulk-in endpoint"
-
-    # Data to the scope
-    if bulkoutep == None:
-        raise "Can't find bulk-out endpoint"
-
-    return intrep, bulkinep, bulkoutep
-
 def main():
-    handle, iface, dev = find488()
+    u = USB488Device()
     print "Found device"
 
-    intrep, bulkinep, bulkoutep = geteps(iface)
-    print "Found endpoints"
+    print "ID is.."
+    u.write("*IDN?")
+    print u.read()
     
 if __name__ == "__main__":
     main()