Controlling power supplies with USB

When I wanted to automate some of my tests and prevent myself from having to reach the power supply, I looked for a product which would allow me to switch off the power of the device remotely. I then found Cleware which provides some really useful USB-Switches.

After spending some time trying to figure out how the device works (by sniffing the USB transfer with the Windows application) I could write my own application to control those USB-Switches. It uses libusb-1.0 to talk to the device, which means the code is really simple to read and modify. The application is, of course, released under GPL so you can use it and modify it as much as you want but you have to keep the copyright notices.

Below is a simple howto explaining how to clone the repository, build the application and use it. I'm assuming you're using Debian, so if you use anything else, you might need to modify the steps.

  1. Install libusb-1.0 and libusb-1.0-dev
  2. In order to build cleware.c you need to install libusb-1.0-0 package, so here we go:

    $ sudo apt-get install libusb-1.0-0-dev libusb-1.0-0
  3. Clone the repository
  4. Now we will clone and compile the Cleware repository:

    $ git clone git://gitorious.org/usb/usb-tools.git
    $ cd usb-tools
    $ make
  5. Add a group for the Cleware device
  6. Add a group that will be the owner of Cleware devices:

    $ sudo addgroup cleware
  7. Add your user to that group
  8. Add your normal user to that group:

    $ sudo adduser  cleware
  9. Udev rule to allow your user to talk to device
  10. And add this udev rule to allow any member of cleware group to write to cleware devices:

    $ sudo vim /etc/udev/rules.d/99-cleware.rules
    
    ACTION=="add", SUBSYSTEM=="usb_device", SYSFS{idVendor}=="0d50", MODE="0664" GROUP="cleware"
    ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0d50", MODE="0664", GROUP="cleware"
  11. Restart udev
  12. We need to restart udev so it reads the new rule:

    $ sudo /etc/init.d/udev restart
  13. Simple usage
  14. To turn USB-Switch off:

    $ ./cleware -0

    To turn it on:

    $ ./cleware -1

    If you have several cleware devices attached to a usb hub, you can differ them by passing the serial number as a parameter also

    $ ./cleware -1 -s <serial number>

And that's pretty much it. If you have questions, please publish as a comment to this blog post. I hope the tool is as useful for you as it is for me :-)

VN:F [1.9.0_1079]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.0_1079]
Rating: 0 (from 0 votes)

Tags: ,

Leave a Reply