diff usb488.py @ 56:91b476ebc0f2

Run through 2to3
author Daniel O'Connor <doconnor@gsoft.com.au>
date Tue, 08 Dec 2020 14:00:45 +1030
parents ad5942d22f78
children 19045ad9f5f5
line wrap: on
line diff
--- a/usb488.py	Tue Dec 08 13:59:05 2020 +1030
+++ b/usb488.py	Tue Dec 08 14:00:45 2020 +1030
@@ -36,6 +36,7 @@
 #
 
 import usb
+from functools import reduce
 
 #
 # The usual SCPI commands are wrapped before being sent.
@@ -115,7 +116,7 @@
                 # class and then open, however in that case you can't
                 # find the endpoint number which seems pretty useless
                 # unless you want to hard code everything.
-                for confidx in xrange(len(dev.configurations)):
+                for confidx in range(len(dev.configurations)):
                     for iface in dev.configurations[confidx].interfaces:
                         for altif in iface:
                             # Check if this is a USB488 capable interface
@@ -165,7 +166,7 @@
 
         # Required for 488.2 devices, optional otherwise
         if self.intrep == None:
-            print "Can't find interrupt endpoint"
+            print("Can't find interrupt endpoint")
 
         # Data from the scope (mandatory)
         if self.bulkinep == None:
@@ -192,7 +193,7 @@
     def write(self, data):
         """Send data (string) to the instrument"""
 
-        orddata = map(ord, data)
+        orddata = list(map(ord, data))
         # The device needs a \n at the end, enfore this
         if orddata[-1] != '\n':
             orddata += [ord('\n')]
@@ -254,7 +255,7 @@
             #print "Sending " + str(pkt)
             wrote = self.handle.bulkWrite(self.bulkoutep, pkt, _timeout)
             if wrote != len(pkt):
-                print "Short write, got %d, expected %d" % (wrote, len(pkt))
+                print("Short write, got %d, expected %d" % (wrote, len(pkt)))
 
             #print "Reading.."
             read = self.handle.bulkRead(self.bulkinep, datalen, _timeout)
@@ -275,7 +276,7 @@
                 break
 
         # Stringify result for easier consumption
-        result = reduce(lambda x, y: x+y, map(chr, data))
+        result = reduce(lambda x, y: x+y, list(map(chr, data)))
         # Trim off \n if present
         if result[-1] == '\n':
             result = result[0:-1]
@@ -293,7 +294,7 @@
         # This is a reasonable proxy..
         try:
             self.handle.getString(self.dev.iManufacturer, 100)
-        except USBError, e:
+        except USBError as e:
             return False
 
         return True