Issue #159 [New/open] - TypeError when using MCP4921 or MCP4922

Posted by zopatista

WebIOPi version used? => 0.7.1

Python version used? => 3.2

Raspberry Pi board revision? (1 or 2) => 2

Issue #48 added a new vref parameter to the webiopi.devices.analog.mcp492X.MCP492X class but the 2 subclasses for MCP4921 and MCP4922 were not correctly updated to reflect this.

As a result trying to use either results in:

Traceback (most recent call last): File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.1-py3.2-linux-armv7l.egg/webiopi/", line 75, in <module> main(sys.argv) File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.1-py3.2-linux-armv7l.egg/webiopi/", line 69, in main server = Server(port=port, configfile=configfile, scriptfile=scriptfile) File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.1-py3.2-linux-armv7l.egg/webiopi/server/", line 66, in __init__ manager.addDevice(name, driver, args) File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.1-py3.2-linux-armv7l.egg/webiopi/devices/", line 28, in addDevice dev = devClass() File "/usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.1-py3.2-linux-armv7l.egg/webiopi/devices/analog/", line 52, in __init__ MCP492X.__init__(self, chip, 2) TypeError: __init__() takes exactly 4 arguments (3 given)

The fix is simple; pass on the vref parameter to the base class:

class MCP4921(MCP492X): def __init__(self, chip=0, vref=3.3): MCP492X.__init__(self, chip, 1, vref)

class MCP4922(MCP492X): def __init__(self, chip=0, vref=3.3): MCP492X.__init__(self, chip, 2, vref)