René's URL Explorer Experiment


Title: [Windows] usb.core.USBError: [Errno None] libusb0-dll:err [claim_interface] could not claim interface 1, invalid configuration 0 · Issue #46 · python-ivi/python-usbtmc · GitHub

Open Graph Title: [Windows] usb.core.USBError: [Errno None] libusb0-dll:err [claim_interface] could not claim interface 1, invalid configuration 0 · Issue #46 · python-ivi/python-usbtmc

X Title: [Windows] usb.core.USBError: [Errno None] libusb0-dll:err [claim_interface] could not claim interface 1, invalid configuration 0 · Issue #46 · python-ivi/python-usbtmc

Description: Hello, I was working on a test for a device (LadyBug LB5918A Power Sensor) and decided to use python source code that a peer had already written to communicate with it. The code was only tested in a linux environment and being the masoch...

Open Graph Description: Hello, I was working on a test for a device (LadyBug LB5918A Power Sensor) and decided to use python source code that a peer had already written to communicate with it. The code was only tested in ...

X Description: Hello, I was working on a test for a device (LadyBug LB5918A Power Sensor) and decided to use python source code that a peer had already written to communicate with it. The code was only tested in ...

Opengraph URL: https://github.com/python-ivi/python-usbtmc/issues/46

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Windows] usb.core.USBError: [Errno None] libusb0-dll:err [claim_interface] could not claim interface 1, invalid configuration 0","articleBody":"Hello,\r\n\r\nI was working on a test for a device (LadyBug LB5918A Power Sensor) and decided to use python source code that a peer had already written to communicate with it. The code was only tested in a linux environment and being the masochist I am I decided to see if I could at least just identify the device on windows. After using pip to install pyusb \u0026 usbtmc, creating an inf filter with libusb-win32, I ran a brief test script to see if I could just query the device (\"*IDN?\").  Here's the section of the __init__ from the API were the code fails.\r\n```\r\ntry:\r\n\tself.PID = PID\r\n\tself.VID = VID\r\n\t# Initialize USBTMC interface with the LadyBug.\r\n\tself.instr =  usbtmc.Instrument(self.VID, self.PID)\r\n\t#self.instr =  usbtmc.Instrument(0x1A0D, 0x15D8)\r\n\tself.connected = True\r\n\tself.log.debug('Connecting to device with VID: '+str(self.VID)+' and PID: '+str(self.PID))\r\n\tself._send('SYST:PRES DEF')\r\n\tself.log.debug(str(self._request('*IDN?')))\r\n\t#self.clearErr()\r\nexcept Exception as e: \r\n\tself.exceptionHandler(e)\r\n```\r\n\r\nAnd the `__send()` function\r\n```\r\ndef _send(self,msg):\r\n\t\tself.log.debug(str('Writing: '+str(msg)))\r\n\t\tself.instr.write(msg+'\\n')\r\n\t\terr = str(self.instr.ask('SYST:ERR?\\n'))\r\n\t\tif err != '+0,\"No error\"':\r\n\t\t\tself.log.debug(str('LadyBug Error: '+str(err)))\r\n```\r\n\r\nThe error message I get in return is as follows\r\n```\r\n2018-08-03 15:29:08,970 :: ladyBug(DEBUG) :: __init__\r\n2018-08-03 15:29:08,996 :: ladyBug(DEBUG) :: Connecting to device with VID: 6669 and PID: 5592\r\n2018-08-03 15:29:08,997 :: ladyBug(DEBUG) :: Writing: SYST:PRES DEF\r\nTraceback (most recent call last):\r\n  File \"ladyBug-test.py\", line 10, in \u003cmodule\u003e\r\n    lb = ladyBug.meter(0x1a0d,0x15d8,True)\r\n  File \"C:\\Users\\jonathan.bensing\\LadyBug-API\\ladyBug.py\", line 49, in __init__\r\n    self.exceptionHandler(e)\r\n  File \"C:\\Users\\jonathan.bensing\\LadyBug-API\\ladyBug.py\", line 249, in exceptionHandler\r\n    self.instr.open()\r\n  File \"C:\\Python27\\lib\\site-packages\\usbtmc\\usbtmc.py\", line 313, in open\r\n    usb.util.claim_interface(self.device, self.iface)\r\n  File \"C:\\Python27\\lib\\site-packages\\usb\\util.py\", line 205, in claim_interface\r\n    device._ctx.managed_claim_interface(device, interface)\r\n  File \"C:\\Python27\\lib\\site-packages\\usb\\core.py\", line 102, in wrapper\r\n    return f(self, *args, **kwargs)\r\n  File \"C:\\Python27\\lib\\site-packages\\usb\\core.py\", line 167, in managed_claim_interface\r\n    self.backend.claim_interface(self.handle, i)\r\n  File \"C:\\Python27\\lib\\site-packages\\usb\\backend\\libusb0.py\", line 521, in claim_interface\r\n    _check(_lib.usb_claim_interface(dev_handle, intf))\r\n  File \"C:\\Python27\\lib\\site-packages\\usb\\backend\\libusb0.py\", line 431, in _check\r\n    raise USBError(errmsg, ret)\r\nusb.core.USBError: [Errno None] libusb0-dll:err [claim_interface] could not claim interface 1, invalid configuration 0\r\n```\r\n\r\nAfter a lot of googling, I couldn’t seem to find any conclusive reason why this shouldn’t work on windows seeing that I had followed all the steps correctly for both PyUSB and USBTMC setup. I tried just the PyUSB module to identify the device which I was able to do and I then tried to write to the device commands which I know I was most likely doing wrong. I did notice that for most of the examples of PyUSB, the `set_configuration()` function was used a lot to attach to a device. One post that had a similar error said that `set_configuration(1)` should be used and in a rather fluke way I was able to get the device working, so below is the script that cause the device to function properly.\r\n```\r\nmyVendorId =0x1a0d\r\nmyProductId=0x15d8\r\nimport usb.core\r\ndev = usb.core.find(idVendor=myVendorId, idProduct=myProductId)\r\nprint dev\r\ndev.set_configuration(1)\r\nimport ladyBug\r\nlb = ladyBug.meter(0x1a0d,0x15d8,True)\r\nexit()\r\n```\r\nSo I then decided to go through the USBTMC api to see where the issue may be occurring. I believe that the culprit is here in the `open()` function:\r\n```\r\n    def open(self):\r\n        if self.connected:\r\n            return\r\n        # initialize device\r\n        # find first USBTMC interface\r\n        for cfg in self.device:\r\n            for iface in cfg:\r\n                if (self.device.idVendor == 0x1334) or \\\r\n                   (iface.bInterfaceClass == USBTMC_bInterfaceClass and\r\n                    iface.bInterfaceSubClass == USBTMC_bInterfaceSubClass):\r\n                    self.cfg = cfg\r\n                    self.iface = iface\r\n                    break\r\n                else:\r\n                    continue\r\n            break\r\n        if self.iface is None:\r\n            raise UsbtmcException(\"Not a USBTMC device\", 'init')\r\n        try:\r\n            self.old_cfg = self.device.get_active_configuration()\r\n        except usb.core.USBError:\r\n            # ignore exception if configuration is not set\r\n            pass\r\n        if self.old_cfg is not None and self.old_cfg.bConfigurationValue == self.cfg.bConfigurationValue:\r\n            # already set to correct configuration\r\n            # release kernel driver on USBTMC interface\r\n            self._release_kernel_driver(self.iface.bInterfaceNumber)\r\n        else:\r\n            # wrong configuration or configuration not set\r\n            # release all kernel drivers\r\n            if self.old_cfg is not None:\r\n                for iface in self.old_cfg:\r\n                    self._release_kernel_driver(iface.bInterfaceNumber)\r\n            # set proper configuration\r\n            self.device.set_configuration(self.cfg)\r\n\r\n        # claim interface\r\n        usb.util.claim_interface(self.device, self.iface)\r\n``` \r\nAfter stepping through the code manually, the issue is where `self.device.set_configuration(self.cfg)` is never being called. I’m not sure the reasoning behind having the configuration not being set, because it seems that (on windows at least) the old_cfg bConfigurationValue will always be the same as the active cfg bConfigurationValue. And within the usbtmc code I simple moved `self.device.set_configuration(self.cfg)` out of the if statement so that the device will always be set.\r\n```\r\n        if self.old_cfg is not None and self.old_cfg.bConfigurationValue == self.cfg.bConfigurationValue:\r\n            # already set to correct configuration\r\n\r\n            # release kernel driver on USBTMC interface\r\n            self._release_kernel_driver(self.iface.bInterfaceNumber)\r\n        else:\r\n            # wrong configuration or configuration not set\r\n\r\n            # release all kernel drivers\r\n            if self.old_cfg is not None:\r\n                for iface in self.old_cfg:\r\n                    self._release_kernel_driver(iface.bInterfaceNumber)\r\n\r\n        # set proper configuration\r\n        self.device.set_configuration(self.cfg)\r\n```\r\n\r\nI’m not sure if this is intended but I believe that this is how it should be in the code. I hope this helps!\r\n\r\nJon\r\n","author":{"url":"https://github.com/JonBensi","@type":"Person","name":"JonBensi"},"datePublished":"2018-08-06T14:27:49.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/46/python-usbtmc/issues/46"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:69bcaeea-41a6-55e5-76bd-475ecc2dc64e
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB690:6230D:56F31:6E7E9:69781EB3
html-safe-nonce5aa00b29a7cff12667392966f0aaf572245165f6cc43cb8d02b2f27ffc36fad1
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNjkwOjYyMzBEOjU2RjMxOjZFN0U5OjY5NzgxRUIzIiwidmlzaXRvcl9pZCI6IjE5NDY2MTU5MjM0ODU0NDk5MDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmace3d533422558c97b4174da316cf5096c4c28266dfd3388b6daf6c61b02128296
hovercard-subject-tagissue:347947330
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-ivi/python-usbtmc/46/issue_layout
twitter:imagehttps://opengraph.githubassets.com/eda814a9926b61ea0f7f6650e7a94515d985c0321d5270d8a3cadf8061b5f99c/python-ivi/python-usbtmc/issues/46
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/eda814a9926b61ea0f7f6650e7a94515d985c0321d5270d8a3cadf8061b5f99c/python-ivi/python-usbtmc/issues/46
og:image:altHello, I was working on a test for a device (LadyBug LB5918A Power Sensor) and decided to use python source code that a peer had already written to communicate with it. The code was only tested in ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameJonBensi
hostnamegithub.com
expected-hostnamegithub.com
Nonee71ed39771d00f42ce2fc9320895c8c608c164191e118eae487fc3bd0af6886d
turbo-cache-controlno-preview
go-importgithub.com/python-ivi/python-usbtmc git https://github.com/python-ivi/python-usbtmc.git
octolytics-dimension-user_id6889594
octolytics-dimension-user_loginpython-ivi
octolytics-dimension-repository_id10878556
octolytics-dimension-repository_nwopython-ivi/python-usbtmc
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id10878556
octolytics-dimension-repository_network_root_nwopython-ivi/python-usbtmc
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release4919f24054c1e9bf76d7b543cb2ac018075b18ce
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/issues/46#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-ivi%2Fpython-usbtmc%2Fissues%2F46
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython-ivi%2Fpython-usbtmc%2Fissues%2F46
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python-ivi%2Fpython-usbtmc
Reloadhttps://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/issues/46
Reloadhttps://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/issues/46
Reloadhttps://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/issues/46
python-ivi https://patch-diff.githubusercontent.com/python-ivi
python-usbtmchttps://patch-diff.githubusercontent.com/python-ivi/python-usbtmc
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-ivi%2Fpython-usbtmc
Fork 72 https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-ivi%2Fpython-usbtmc
Star 170 https://patch-diff.githubusercontent.com/login?return_to=%2Fpython-ivi%2Fpython-usbtmc
Code https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc
Issues 23 https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/issues
Pull requests 9 https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/pulls
Actions https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/actions
Projects 0 https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/projects
Wiki https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/wiki
Security 0 https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/security
Insights https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/pulse
Code https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc
Issues https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/issues
Pull requests https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/pulls
Actions https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/actions
Projects https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/projects
Wiki https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/wiki
Security https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/security
Insights https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/python-ivi/python-usbtmc/issues/46
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/python-ivi/python-usbtmc/issues/46
[Windows] usb.core.USBError: [Errno None] libusb0-dll:err [claim_interface] could not claim interface 1, invalid configuration 0https://patch-diff.githubusercontent.com/python-ivi/python-usbtmc/issues/46#top
https://github.com/JonBensi
https://github.com/JonBensi
JonBensihttps://github.com/JonBensi
on Aug 6, 2018https://github.com/python-ivi/python-usbtmc/issues/46#issue-347947330
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.