Turn off specific USB port in windows with python

3.6k views Asked by At


This is my first post, and I kind of have seen that the more specific the better, so I'll try to be super clear, and thanks in advance!

What I want:
I need to scan images from 2 or more scanners at the same time, these scanners are from the same brand and model, in this case Epson Perfection V600, I need different time intervals for at least 40 captures over a course of 20 hours.

My approach
I decided to use Windows, I already have a program in Python that does what I want with just one scanner, or with two from different models. But here is where you guys come in:

The problem
Windows always prints with the same scanner, Since they are from the same brand and model it always uses the same one, and I cannot use two different scanners because that will cause the images not to be comparable. Nevertheless, when I use two different scanners, I don't have such problem. I need to find a way to print with each scanner. I thought in buying a USB hub and control it with python as well, but apparently given libsub implementation in windows, I will not be able to control it. So I'm currently Looking for a way to disable an specific USB port so the program will only recognize one device, scan with it, disable that one, re-enable the other one, and so on.


What I have access to:

  • Right now I'm using Windows 10, 64 bits, python kernel 3 in a python 3.5 version inside a Conda environment, conda version (4.5.11).
  • Ubuntu 16.04, 64 bits, with pyinsane working, in a python 3.5 environment inside conda (don't have the conda version at hand).
  • One Epson perfection V600.
  • Two Canon Lide200, working only in windows, because drivers are not available in Ubuntu.

What I have also tried

  • Using Ubuntu,
    I thought it was a good Idea, but the Epson drivers webpage fails to connect to the repository containing the rest of the Epson files, letting me only partially download the files, I already tried to contact the owner of the Docky repository, but he fails to contact me.
    The error:

W: The repository 'http://ppa.launchpad.net/docky-core/ppa/ubuntu Xenial Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Failed to fetch http://ppa.launchpad.net/docky-core/ppa/ubuntu/dists/xenial/main/binary-amd64/Packages 404 Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.

  • when I manually try to enter the site's repository I found that All links to XENIAL drivers are down, actually the whole Xenial Folder is missing.

  • Also then thought it was a good idea to ignore this message, but I Need the Epwoka driver to run Epson scanners in Ubuntu, and that a whole problem by itself. Aside from that, is not known if Epson Perfection V600 is going to be possible to be controlled by the PyInsane lib, since is marked as untested.

Using Windows

  • I thought in buying an USB hub and to controlled as shown in this thread, but apparently is not possible in windows.

  • I already installed libsub, usb.util, libusb1,USB (for the core functions) and usb1, but I don't know (I think is not possible) to disable and re-enable a specific USB port with them.

  • Can't disable the drivers since that mean all USB will be down to connect with the scanners.

  • Device manager is not helping, because of the inability of telling which device is which.

  • Cannot change the name of the scanner (yes, printers can have specific names) but scanners can't.

  • Can't buy another scanner, I'm stuck with Epson.


My code for Scanning

import pyinsane2
def Scan(Device, dpi):
pyinsane2.init()
try:
    pyinsane2.set_scanner_opt(Device, 'resolution', [dpi])
    pyinsane2.set_scanner_opt(Device, 'mode', ['Color'])
    pyinsane2.maximize_scan_area(Device)
    scan_session = Device.scan(multiple=False)
    try:
        while True:
            scan_session.scan.read()
    except EOFError:
        pass
    Image = scan_session.images[-1]
finally:
    pyinsane2.exit()
return(Image)

devices = pyinsane2.get_devices()
image_a = Scan(devices[0], 75)
image_b = Scan(devices[1], 75)
a = devices[1]
b = devices[0]
a == b                                  #Different
a.dev_type == b.dev_type
a.model == b.model
a.name == b.name                        #Different
a.nice_name == b.nice_name
a.options == b.options
a.reload_options == b.reload_options    #Different
a.scan == b.scan                        #Different
a.srcs == b.srcs                        #Different
a.vendor == b.vendor

I put a sticki note inside each Scanner, one with an "a" the other one with a "b" and it always scans with the scanner that I plugged in first

This is what I would like to do (and doing it manually works): **This is what I'm trying to do**.



This is what I get when trying in python:

This is what I get

Any solution will help me, get creative! I was thinking on using a .bat file to disable an specific port and calling it with Python. But I couldn't find a way to make it.Keep in mind that doing it manually is not an option 'cause of the 20 to 40 hours of continuous image acquisition.
Thanks!

~Diego

0

There are 0 answers