GIDForums  

Go Back   GIDForums > Computer Programming Forums > Python Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Dec-2006, 19:13
Soccerplayer131 Soccerplayer131 is offline
New Member
 
Join Date: Sep 2006
Posts: 4
Soccerplayer131 is on a distinguished road

USB Hub Python programming


So this new wireless USB hub from Belkin is coming out very soon its date is mid December, so soon, but I was wondering if anyone knew how I could write a program in python or could you possibly do it for me which would tell the computer to extract the images from the camera automatically to the computer once it it plugged into the usb hub. How the usb hub works is, there is a hub and a flash drive dongle looking thing, which is hooked up into a computers USB port. Now what will be done is the camera will be hooked up into the hub a distance away and it will be recognized on the computer b/c signals will be sent to the dongle and the camera will appear on the computer. Next the images can be extracted manually, but I was wondering if anyone knew how to write a program that would tell the computer as soon as the camera is connected into the hub and appears connected on the computer to automatically download all the pictures into a folder on the computers hard drive without me having to go to the computer personally and do it manually?
  #2  
Old 23-Dec-2006, 13:59
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,628
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: USB Hub Python programming


Are you saying you want to write the program yourself? I have no experience with this personally so you might want to check out the Python newsgroup on Google Groups.

I would imagine that the program would simply look for the USB "drive" and simply move the data files from there to your computer's drive. As long as you treat everything as a simple HD and not worry about what it actually is, it should work.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
  #3  
Old 23-Dec-2006, 16:36
Soccerplayer131 Soccerplayer131 is offline
New Member
 
Join Date: Sep 2006
Posts: 4
Soccerplayer131 is on a distinguished road

Re: USB Hub Python programming


since now the camera isn't a mass storage device I changed it up. Now I am making a program that when the memory stick is put into a usb port it gets assigned a drive letter well from that drive it will copy the files into another folder and the program runs every 5 seconds, now what I need help on is what do I add into my program that would Ignore the errors when the memory stick isn't plugged in, but still have the program run every 5 seconds and once the memory stick is inserted and the directory exist for the program to copy the files once it has come to one of its 5 second runs.
Python Code:
import os, shutil
from time import time

def dir_list(dir_name):
    fileList = []
    try:
        for file in os.listdir(dir_name):
            dirfile = os.path.join(dir_name, file)
            if os.path.isfile(dirfile):
                fileList.append(dirfile)
                  return fileList

if __name__ == '__main__':
    def CopyFiles():
       dirNameS = (os.path.join('E:\\', 'DCIM', '140canon'))
        dirNameT = (os.path.join('C:\\', 'Camera'))
        fileList = dir_list(dirNameS)
        for f in fileList:
            shutil.copy(f, dirNameT)

    duration = 30 # run for 30 seconds total
    hasrunfor = 0 # count how long we have run
    while hasrunfor < duration:
        endTime = time() + 5  # time() counts in seconds
        CopyFiles()
        while time() < endTime:
            pass
        hasrunfor += 5
Last edited by LuciWiz : 23-Dec-2006 at 18:05. Reason: Please insert your Python code between [py] & [/py] tags
  #4  
Old 23-Dec-2006, 20:50
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,628
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: USB Hub Python programming


I assume you want the exception that is missing from your try block. I'm not sure what the actual exception would be if the memory stick isn't inserted (I'd have to look it up but maybe something like FileNotFound). I'd imagine that once the exception is caught, indicating that the memory stick isn't found, you'd probably just want it to ignore the exception (unless you have something else in mind). If that's the case, then a simple:
Python Code:
exception:
    pass
should work; it will catch any exceptions that occur but not do anything.

I think that's what you're looking for.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Beginning Python Tutorial (Part 9) crystalattice Python Forum 0 19-Feb-2006 02:04
Sockets Programming in Python crystalattice Python Forum 0 07-Oct-2005 23:49
Re: Beginning Python Tutorial (Part 5) crystalattice Python Forum 0 04-Oct-2005 05:27
Re: Beginning Python Tutorial (Part 1) crystalattice Python Forum 5 01-Aug-2005 18:14
Re: Beginning Python Tutorial (Part 2) crystalattice Python Forum 2 31-Jul-2005 13:25

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:28.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.