using a USB HID device

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wouter van Ooijen

    using a USB HID device

    I want to use Python to interface with an USB HID device (not a
    keyboard or mouse, just something that uses the HID driver to avoid
    the need for a specific driver). Is this possible in pure Python on
    Windows, or even better, in a portable way?

    Wouter van Ooijen

    -- ------------------------------------

    PICmicro chips, programmers, consulting
  • Martin v. Löwis

    #2
    Re: using a USB HID device

    Wouter van Ooijen (www.voti.nl) wrote:[color=blue]
    > I want to use Python to interface with an USB HID device (not a
    > keyboard or mouse, just something that uses the HID driver to avoid
    > the need for a specific driver). Is this possible in pure Python on
    > Windows, or even better, in a portable way?[/color]

    What is the Win32 API for such devices? If it is plain
    CreateFile/ReadFile/WriteFile/DeviceIoControl , you should be
    able to do it in pure Python, using the PythonWin extensions.

    Likewise, on Unix, you can use device nodes, and the fcntl module.

    I don't think there is a platform-independent Python module for
    such devices, yet, but you could write your own abstraction layer
    using those building blocks.

    HTH,
    Martin

    Comment

    • Samuel Schulenburg

      #3
      Re: using a USB HID device

      wouter@voti.nl (Wouter van Ooijen (www.voti.nl)) wrote in message news:<40827ce3. 1151345337@news .xs4all.nl>...[color=blue]
      > I want to use Python to interface with an USB HID device (not a
      > keyboard or mouse, just something that uses the HID driver to avoid
      > the need for a specific driver). Is this possible in pure Python on
      > Windows, or even better, in a portable way?
      >
      > Wouter van Ooijen
      >
      > -- ------------------------------------
      > http://www.voti.nl
      > PICmicro chips, programmers, consulting[/color]

      I have developed routines for Windows that address mass storage
      devices using the Windows SCSIPASSTHROUGH layer. I found that USB
      devices do not use this layer, and as a result I am also investigating
      using python to access USB devices. So far it looks like a seperate
      driver along with a interfaceing DLL will needed.

      Sam Schulenburg

      Comment

      • Wouter van Ooijen

        #4
        Re: using a USB HID device

        >> I want to use Python to interface with an USB HID device (not a[color=blue][color=green]
        >> keyboard or mouse, just something that uses the HID driver to avoid
        >> the need for a specific driver). Is this possible in pure Python on
        >> Windows, or even better, in a portable way?[/color]
        >
        >What is the Win32 API for such devices?[/color]

        To be honest, I don't have the faintest idea. I hoped there would be
        some abstraction layer (freferrably a portable one) like for serial
        ports.


        Wouter van Ooijen

        -- ------------------------------------

        PICmicro chips, programmers, consulting

        Comment

        • Jeff Epler

          #5
          Re: using a USB HID device

          libusb is portable to Linux, BSD including OS X, and Windows.
          I don't know of a Python wrapper, however, and my experience using
          libusb on windows is limited.


          Download libusb-win32 for free. libusb-win32 is a port of libusb-0.1 under Windows. libusb-win32 is a port of the USB library libusb-0.1 (http://sf.net/projects/libusb/) to 32/64bit Windows. The library allows user space applications to access many USB device on Windows.


          For my own application, I wrote my device's API in C and wrapped it
          using Pyrex.

          Jeff

          Comment

          • Roger Binns

            #6
            Re: using a USB HID device

            Samuel Schulenburg wrote:[color=blue]
            > wouter@voti.nl (Wouter van Ooijen (www.voti.nl)) wrote in message news:<40827ce3. 1151345337@news .xs4all.nl>...[color=green]
            > > I want to use Python to interface with an USB HID device (not a[/color]
            >
            > I found that USB
            > devices do not use this layer, and as a result I am also investigating
            > using python to access USB devices. So far it looks like a seperate
            > driver along with a interfaceing DLL will needed.[/color]

            Here is one I made earlier:



            It is a Python wrapper (using SWIG) around libusb (including libusb-win32).
            My BitPim project currently ships using it on Windows, Linux and Mac.

            Roger


            Comment

            • Martin v. Löwis

              #7
              Re: using a USB HID device

              Jeff Epler wrote:[color=blue]
              > libusb is portable to Linux, BSD including OS X, and Windows.
              > I don't know of a Python wrapper, however, and my experience using
              > libusb on windows is limited.
              >
              > http://libusb.sf.net
              > http://libusb-win32.sf.net/[/color]

              It looks like libusb, on Windows, installs its own kernel driver,
              which generates devices named \\.\libusb*. So this is not exactly
              a pure-python solution :-)

              OTOH, it may well be that USB devices, on Windows, cannot be
              accessed purely from user mode, and that you always need some
              sort of kernel driver.

              Regards,
              Martin

              Comment

              • Wouter van Ooijen

                #8
                Re: using a USB HID device

                >OTOH, it may well be that USB devices, on Windows, cannot be[color=blue]
                >accessed purely from user mode, and that you always need some
                >sort of kernel driver.[/color]

                But I can live with something that appears to be pure python, like one
                which only requires a win-specific addition. after all win32all is
                windows-specific too, but I regard it as part of the windows-python
                installation. One more dll is no problem, as long as I don't have to
                write (and maintain!) it :)



                Wouter van Ooijen

                -- ------------------------------------

                PICmicro chips, programmers, consulting

                Comment

                • Martin v. Löwis

                  #9
                  Re: using a USB HID device

                  Wouter van Ooijen (www.voti.nl) wrote:[color=blue]
                  >
                  > But I can live with something that appears to be pure python, like one
                  > which only requires a win-specific addition. after all win32all is
                  > windows-specific too, but I regard it as part of the windows-python
                  > installation. One more dll is no problem, as long as I don't have to
                  > write (and maintain!) it :)[/color]

                  So libusb-win32 might be the solution for you (with other libusb
                  incarnations for other systems).

                  Notice, however, that your users need administrator privileges to
                  install a kernel mode driver.

                  Regards,
                  Martin

                  Comment

                  • Roger Binns

                    #10
                    Re: using a USB HID device

                    Martin v. Löwis wrote:[color=blue]
                    > Notice, however, that your users need administrator privileges to
                    > install a kernel mode driver.[/color]

                    Yup. However you can access a device if there is a device driver
                    attached as well, as long as it is not open. For example if you
                    have a USB to serial device, you can open it under libusb-win32
                    providing no other user space code has it open as a com port device.

                    Unfortunately with both Linux and Mac, libusb can only open devices
                    for which there is no driver currently attached (irrespective of
                    whether there is a user space program with the device open).

                    Windows also requires that a driver be present. There is a do
                    nothing driver included with libusb-win32 that can be used.

                    Roger


                    Comment

                    • Samuel Schulenburg

                      #11
                      Re: using a USB HID device

                      wouter@voti.nl (Wouter van Ooijen (www.voti.nl)) wrote in message news:<40827ce3. 1151345337@news .xs4all.nl>...[color=blue]
                      > I want to use Python to interface with an USB HID device (not a
                      > keyboard or mouse, just something that uses the HID driver to avoid
                      > the need for a specific driver). Is this possible in pure Python on
                      > Windows, or even better, in a portable way?
                      >
                      > Wouter van Ooijen
                      >
                      > -- ------------------------------------
                      > http://www.voti.nl
                      > PICmicro chips, programmers, consulting[/color]

                      I have been trying different approches to accessing mass storage
                      flash memory cards via the SCSIPASSTHROUGH layer under windows. I was
                      able to issue the reduced instruction scsi command set with a windows
                      DeviceIoControl () call. The main problem is finding information on how
                      Microsoft merged the usb mass storage interface to the scsi routines.

                      Sam Schulenburg

                      Comment

                      Working...