Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Drive Detection

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-25-2008, 11:26 AM
RandomCoder's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire, UK
Posts: 623
Awards Showcase
Beta Tester 
Total Awards: 1
Default Drive Detection

Hi guys,

Been away for a while but just gettting back into some programming again.
Found a little tool for copying files and folders called ROBOCOPY, like the old DOS XCOPY but better (see here... Robocopy), and I'm wanting to automate this with B4PPC.

What I would like to know is if it is possible to detect when a USB drive has been plugged in?

The best I have come up with is to run a DirExist("MyBackup.etc") periodically to check if the USB drive is present but this is very hit and miss.
I'd much rather have some way of detecting that the drive has just been plugged in - is it possible?

Regards,
RandomCoder
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #2 (permalink)  
Old 06-25-2008, 12:30 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

This uses my (unpublished) Window Message libray but it is based on the same code as Dimitris used for dzEventsMagic. Make a dzEventMagic object called WMevent and change the event name to WMevent_MagicEvent.

Note that you get multiple messages, hence the check for a time window. You will have to track whether the device is present or not. Also note that you may need a delay after getting the event before the device is visible. You will have to play with this for yourself.

This event may happen for other things than a USB device. This works on my desktop for USB sticks and should work on a device with a USB port but for what range of devices I have no idea.


Code:
Sub Globals
    
'Declare the global variables here.
    WM_DEVICECHANGE = 537 ' 0x0219
    TimeChanged = Now
End Sub

Sub App_Start
    Form1.Show
    WMevent.New1(
"Form1"false)
    WMevent.Hook(WM_DEVICECHANGE)
End Sub


Sub Form1_Close
    WMevent.UnHook(WM_DEVICECHANGE)    
End Sub

Sub WMEvent_WmEvent
    msg = WMevent.wParam
    
If msg = 7 AND Now > TimeChanged + cTicksPerSecond*3 Then
        TimeChanged = Now
        
Msgbox("Device added or removed")
    
End If
End Sub
Reply With Quote
  #3 (permalink)  
Old 06-25-2008, 12:40 PM
RandomCoder's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire, UK
Posts: 623
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Agraham your amazing..... is there anything you don't know?

I've not tried it yet but have every faith it will work.

Thankyou very much,
RandomCoder
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #4 (permalink)  
Old 06-25-2008, 12:42 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Further investigation shows that you only get one each of events with these wParam values on a change. There may still be a delay before the device is accessible. Again you need to change the Sub name to WMevent_MagicEvent for the dzEventsMagic library.


Code:
Sub WMEvent_WmEvent
    msg = WMevent.wParam
    
Select msg
        
Case 32772:    
            
Msgbox("Device removed")
        
Case 32768
            
Msgbox("Device added")
    
End Select    
End Sub
Reply With Quote
  #5 (permalink)  
Old 06-25-2008, 12:44 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Quote:
Originally Posted by RandomCoder View Post
Agraham your amazing..... is there anything you don't know?
Lots, but I can Google quite well and of course have the background to interpret and use what I find
Reply With Quote
  #6 (permalink)  
Old 06-25-2008, 01:11 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 6,072
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

I've played some more and it seems, on my Vista desktop at least, that the USB drive is available as soon the drive added message arrives. This is convenient as it will save doing some timing logic before testing if it is true for all systems.
Reply With Quote
  #7 (permalink)  
Old 06-28-2008, 05:14 PM
Newbie
 
Join Date: Jun 2007
Location: UK
Posts: 8
Default

You might be interested in this: http://www.basic4ppc.com/forum/share...p-utility.html.

Please let me know if you want the source code.
Reply With Quote
  #8 (permalink)  
Old 06-30-2008, 11:38 AM
RandomCoder's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire, UK
Posts: 623
Awards Showcase
Beta Tester 
Total Awards: 1
Default

I like the twist on the ROBOCOPY name... Robscopy

If you wouldn't mind then it would be nice to see your source code as there are some things you have done different such as using a TreeView to select paths and also the ability to exclude files (not just folders).

My app is intended to run slightly differently in that I'd like to have it running in the background all of the time and then detect when x amount of time has passed (set by the user) and trigger the ROBOCOPY function, if the destination is a USB device it will wait for the device to be connected.

Attached is my source code so that you can see the direction I've taken. This is no where near finished and does not include running in the background which needs to be added now that Agraham and DZT have been so kind as to show me a way forward. Most of my programming is done during a 30 minute meal break at work
I've commented out the SHELL comand and just use a label to display the arguments for the time being.

Regards,
RandomCoder
Attached Files
File Type: zip Backup Utility.zip (2.1 KB, 19 views)
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #9 (permalink)  
Old 07-03-2008, 02:15 PM
Newbie
 
Join Date: Jun 2007
Location: UK
Posts: 8
Default

Hi RandomCoder

Please find the source code attached.
Reply With Quote
  #10 (permalink)  
Old 07-04-2008, 11:59 AM
RandomCoder's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Derbyshire, UK
Posts: 623
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Quote:
Originally Posted by robmh View Post
Hi RandomCoder

Please find the source code attached.
Thanks rob
__________________
"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Device with USB hard drive link dan kabestan Questions (Windows Mobile) 3 08-11-2008 11:47 PM
drive, file list boxes scott93727 Basic4ppc Wishlist 0 06-22-2008 01:35 AM
int 13 drive 0 bad sector problems scott93727 Questions (Windows Mobile) 1 04-11-2008 09:26 AM
leap year detection stbi Code Samples & Tips 3 07-02-2007 04:21 PM


All times are GMT. The time now is 07:23 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0