msoon / PyMonsoon

Monsoon Power Monitor Python Library
MIT License
55 stars 23 forks source link

AttributeError: 'NoneType' object has no attribute 'ctrl_transfer' #24

Open sf-wind opened 6 years ago

sf-wind commented 6 years ago

I suspect this is because USB is not detected by monsooon. But monsoon installation includes libusb1, and I have also installed libusb manually.

So how to address this issue?

msoonjared commented 6 years ago

What OS are you running?

roy-uiowa commented 5 years ago

I wonder if this project is still maintained, I am having the same problem. And i'm using ubuntu 18.04 LTS. Another thing is in pmapi.py file at line 23, devices = usb.core.find(find_all=True, idVendor = 0x2AB9, idProduct = 0x0001) the device id is very specific. Do I need to change the device id for my device cause it doesn't match this vendor and product ID.

odmnk commented 3 years ago

Perhaps a little bit late, but better late than never ;).

I encountered this problem as well and what fixed it for me was running your script with sudo e.g.,

sudo python3 my_script.py

If you are running PyMonsoon in a virtual environment please make sure you provide the path to the python3 binary in the virtual environment as sudo python3 will use your global python3 installation by default.

So first get the path of the python3 executable in your virtual environment: which python3

Then use that path when running your script: sudo <my_python3_path> my_script.py or as a one-liner: sudo $(which python3) my_script.py.

If this does not work:

  1. Is the Monsoon actually turned on ;)?
  2. Did you set the serial for your Monsoon?
funkywok commented 2 years ago

Hi guys. I am having the same issue. I use LVPM and follow the example code in the official API document:

import Monsoon.LVPM as LVPM
import Monsoon.sampleEngine as sampleEngine
import Monsoon.Operations as op
Mon = LVPM.Monsoon()
Mon.setup_usb(serialno=13379)  # my monsoon's serial number

Mon.setVout(4.0)
engine = sampleEngine.SampleEngine(Mon)
engine.enableCSVOutput("Main Example.csv")
engine.ConsoleOutput(True)
numSamples=5000 #sample for one second
engine.startSampling(numSamples)

I have tried it on Ubuntu 18.04 and Windows 10 with Python 3.6, and both cases show errors like:

File "[testMonsoon.py](http://testmonsoon.py/)", line 8, in <module>
    Mon.setVout(4.0)
  File "/home/xxx/.local/lib/python3.6/site-packages/Monsoon/LVPM.py", line 59, in setVout
    self.Protocol.sendCommand(op.OpCodes.setMainVoltage,vout)
  File "/home/xxx/.local/lib/python3.6/site-packages/Monsoon/pmapi.py", line 85, in sendCommand
    if not self.verifyReady(operation):
  File "/home/xxx/.local/lib/python3.6/site-packages/Monsoon/pmapi.py", line 163, in verifyReady
    firmwareRev = self.getValue(op.OpCodes.FirmwareVersion,1)
  File "/home/xxx/.local/lib/python3.6/site-packages/Monsoon/pmapi.py", line 128, in getValue
    result = self.DEVICE.ctrl_transfer(op.Control_Codes.USB_IN_PACKET,op.Control_Codes.USB_SET_VALUE,0,wIndex,4,5000)
AttributeError: 'NoneType' object has no attribute 'ctrl_transfer'

Perhaps a little bit late, but better late than never ;).

I encountered this problem as well and what fixed it for me was running your script with sudo e.g.,

sudo python3 my_script.py

If you are running PyMonsoon in a virtual environment please make sure you provide the path to the python3 binary in the virtual environment as sudo python3 will use your global python3 installation by default.

So first get the path of the python3 executable in your virtual environment: which python3

Then use that path when running your script: sudo <my_python3_path> my_script.py or as a one-liner: sudo $(which python3) my_script.py.

If this does not work:

  1. Is the Monsoon actually turned on ;)?
  2. Did you set the serial for your Monsoon?

I have tried to sudo but it does not help. Monsoon is on during the test.

Any suggestion for this issue? Thanks.

funkywok commented 2 years ago

I wonder if this project is still maintained, I am having the same problem. And i'm using ubuntu 18.04 LTS. Another thing is in pmapi.py file at line 23, devices = usb.core.find(find_all=True, idVendor = 0x2AB9, idProduct = 0x0001) the device id is very specific. Do I need to change the device id for my device cause it doesn't match this vendor and product ID.

Hi @roy-uiowa. I got the same concern. I tried changing the vid and pid in pmapi.py but still not working. Have u solved this problem? Thanks!

PeterDuy commented 2 years ago

Hi guys. I am having the same issue. I use LVPM and follow the example code in the official API document:

import Monsoon.LVPM as LVPM
import Monsoon.sampleEngine as sampleEngine
import Monsoon.Operations as op
Mon = LVPM.Monsoon()
Mon.setup_usb(serialno=13379)  # my monsoon's serial number

Mon.setVout(4.0)
engine = sampleEngine.SampleEngine(Mon)
engine.enableCSVOutput("Main Example.csv")
engine.ConsoleOutput(True)
numSamples=5000 #sample for one second
engine.startSampling(numSamples)

I have tried it on Ubuntu 18.04 and Windows 10 with Python 3.6, and both cases show errors like:

File "[testMonsoon.py](http://testmonsoon.py/)", line 8, in <module>
    Mon.setVout(4.0)
  File "/home/xxx/.local/lib/python3.6/site-packages/Monsoon/LVPM.py", line 59, in setVout
    self.Protocol.sendCommand(op.OpCodes.setMainVoltage,vout)
  File "/home/xxx/.local/lib/python3.6/site-packages/Monsoon/pmapi.py", line 85, in sendCommand
    if not self.verifyReady(operation):
  File "/home/xxx/.local/lib/python3.6/site-packages/Monsoon/pmapi.py", line 163, in verifyReady
    firmwareRev = self.getValue(op.OpCodes.FirmwareVersion,1)
  File "/home/xxx/.local/lib/python3.6/site-packages/Monsoon/pmapi.py", line 128, in getValue
    result = self.DEVICE.ctrl_transfer(op.Control_Codes.USB_IN_PACKET,op.Control_Codes.USB_SET_VALUE,0,wIndex,4,5000)
AttributeError: 'NoneType' object has no attribute 'ctrl_transfer'

Perhaps a little bit late, but better late than never ;). I encountered this problem as well and what fixed it for me was running your script with sudo e.g., sudo python3 my_script.py If you are running PyMonsoon in a virtual environment please make sure you provide the path to the python3 binary in the virtual environment as sudo python3 will use your global python3 installation by default. So first get the path of the python3 executable in your virtual environment: which python3 Then use that path when running your script: sudo <my_python3_path> my_script.py or as a one-liner: sudo $(which python3) my_script.py. If this does not work:

  1. Is the Monsoon actually turned on ;)?
  2. Did you set the serial for your Monsoon?

I have tried to sudo but it does not help. Monsoon is on during the test.

Any suggestion for this issue? Thanks.

Hi @dfguooo, I recommend you should install ubs filter on your Window machine and try it again. I installed a quite old version: libusb-win32-devel-filter-1.2.6.0.exe and it works fine.

LY-ai commented 1 year ago

Download and use libUSB but do not open the powertool tool. This is my solution [windows]