Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python3 compatibility #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
4 changes: 2 additions & 2 deletions src/configure
Original file line number Diff line number Diff line change
Expand Up @@ -3517,8 +3517,8 @@ done

if ! test $PYLIB
then
echo "import sys" > pylib.py
echo "for path in sys.path: print path" >> pylib.py
echo "import sys, os" > pylib.py
echo "for path in sys.path: sys.stdout.write(path + os.linesep)" >> pylib.py
PYLIB="$(python pylib.py | grep -e '-packages$' | head -1)"
rm -f pylib.py
fi
Expand Down
2 changes: 1 addition & 1 deletion src/mpsse.i
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

%typemap(out) swig_string_data
{
$result = PyString_FromStringAndSize($1.data, $1.size);
$result = PyBytes_FromStringAndSize($1.data, $1.size);
free($1.data);
}

Expand Down
50 changes: 25 additions & 25 deletions src/mpsse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

MPSSE_OK = _mpsse.MPSSE_OK
MPSSE_FAIL = _mpsse.MPSSE_FAIL

MSB = _mpsse.MSB
LSB = _mpsse.LSB

Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(self, mode=None, frequency=ONE_HUNDRED_KHZ, endianess=MSB):
if mode is not None:
self.context = _mpsse.MPSSE(mode, frequency, endianess)
if self.context.open == 0:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())

def __enter__(self):
return self
Expand Down Expand Up @@ -100,7 +100,7 @@ def Open(self, vid, pid, mode, frequency=ONE_HUNDRED_KHZ, endianess=MSB, interfa
"""
self.context = _mpsse.OpenIndex(vid, pid, mode, frequency, endianess, interface, description, serial, index)
if self.context.open == 0:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())
return MPSSE_OK

def Close(self):
Expand All @@ -111,7 +111,7 @@ def Close(self):
"""
retval = _mpsse.Close(self.context)
self.context = None

def ErrorString(self):
"""
Returns the last libftdi error string.
Expand All @@ -125,12 +125,12 @@ def SetMode(self, mode, endianess):

@mode - The MPSSE mode to use, one of: SPI0, SPI1, SPI2, SPI3, I2C, GPIO, BITBANG.
@endianess - The endianess of data transfers, one of: MSB, LSB.

Returns MPSSE_OK on success.
Raises an exception on failure.
"""
if _mpsse.SetMode(self.context, mode, endianess) == MPSSE_FAIL:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())
return MPSSE_OK

def EnableBitmode(self, tf):
Expand Down Expand Up @@ -165,7 +165,7 @@ def SetClock(self, frequency):
Raises an exception on failure.
"""
if _mpsse.SetClock(self.context, frequency) == MPSSE_FAIL:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())
return MPSSE_OK

def GetClock(self):
Expand All @@ -188,7 +188,7 @@ def GetPid(self):

def GetDescription(self):
"""
Returns the description of the FTDI chip, if any.
Returns the description of the FTDI chip, if any.
This will only be populated if __init__ was used to open the device.
"""
return _mpsse.GetDescription(self.context)
Expand All @@ -203,7 +203,7 @@ def SetLoopback(self, enable):
Raises an exception on failure.
"""
if _mpsse.SetLoopback(self.context, enable) == MPSSE_FAIL:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())
return MPSSE_OK

def SetCSIdle(self, idle):
Expand All @@ -224,7 +224,7 @@ def Start(self):
Raises an exception on failure.
"""
if _mpsse.Start(self.context) == MPSSE_FAIL:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())
return MPSSE_OK

def Stop(self):
Expand All @@ -235,20 +235,20 @@ def Stop(self):
Raises an exception on failure.
"""
if _mpsse.Stop(self.context) == MPSSE_FAIL:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())
return MPSSE_OK

def Write(self, data):
"""
Writes bytes out via the selected serial protocol.

@data - A string of bytes to be written.

Returns MPSSE_OK on success.
Raises an exception on failure.
"""
if _mpsse.Write(self.context, data) == MPSSE_FAIL:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())
return MPSSE_OK

def Read(self, size):
Expand Down Expand Up @@ -310,57 +310,57 @@ def GetAck(self):
def PinHigh(self, pin):
"""
Sets the specified GPIO pin high.

@pin - Pin number 0 - 11 in GPIO mode.
In all other modes, one of: GPIOL0, GPIOL1, GPIOL2, GPIOL3, GPIOH0, GPIOH1, GPIOH2, GPIOH3, GPIOH4, GPIOH5, GPIOH6, GPIOH7.

Returns MPSSE_OK on success.
Raises an exception on failure.
"""
if _mpsse.PinHigh(self.context, pin) == MPSSE_FAIL:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())
return MPSSE_OK

def PinLow(self, pin):
"""
Sets the specified GPIO pin low.

@pin - Pin number 0 - 11 in GPIO mode.
In all other modes, one of: GPIOL0, GPIOL1, GPIOL2, GPIOL3, GPIOH0, GPIOH1, GPIOH2, GPIOH3, GPIOH4, GPIOH5, GPIOH6, GPIOH7.

Returns MPSSE_OK on success.
Raises an exception on failure.
"""
if _mpsse.PinLow(self.context, pin) == MPSSE_FAIL:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())
return MPSSE_OK

def SetDirection(self, direction):
"""
Sets the input/output direction of pins as determined by direction (1 = Output, 0 = Input).
Sets the input/output direction of pins as determined by direction (1 = Output, 0 = Input).
For use in BITBANG mode only.

@direction - Byte indicating input/output direction of each bit (1 is output, 0 is input).
@direction - Byte indicating input/output direction of each bit (1 is output, 0 is input).

Returns MPSSE_OK on success.
Raises an exception on failure.
"""
if _mpsse.SetDirection(self.context, direction) == MPSSE_FAIL:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())
return MPSSE_OK

def WriteBits(self, bits, n):
"""
Performs a bitwise write of up to 8 bits at a time.

@bits - An integer of bits to be written.
@n - Transmit n number of least-significant bits.

Returns MPSSE_OK on success.
Raises an exception on failure.
"""
if _mpsse.WriteBits(self.context, bits, n) == MPSSE_FAIL:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())
return MPSSE_OK

def ReadBits(self, n):
Expand All @@ -384,7 +384,7 @@ def WritePins(self, data):
Raises an exception on failure.
"""
if _mpsse.WritePins(self.context, data) == MPSSE_FAIL:
raise Exception, self.ErrorString()
raise Exception(self.ErrorString())
return MPSSE_OK

def ReadPins(self):
Expand All @@ -401,7 +401,7 @@ def PinState(self, pin, state=-1):
Checks the current state of the pins.
For use in BITBANG mode only.

@pin - The pin number whose state you want to check.
@pin - The pin number whose state you want to check.
@state - The value returned by ReadPins. If not specified, ReadPins will be called automatically.

Returns a 1 if the pin is high, 0 if the pin is low.
Expand Down