Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


Drive Detection


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-25-2008, 12:26 PM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 486
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
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #2 (permalink)  
Old 06-25-2008, 01:30 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,755
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
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, 01:40 PM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 486
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
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #4 (permalink)  
Old 06-25-2008, 01:42 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,755
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
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, 01:44 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,755
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
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, 02:11 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,755
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
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, 06:14 PM
Newbie
 
Join Date: Jun 2007
Location: UK
Posts: 8
Default

You might be interested in this: Desktop-only backup utility.

Please let me know if you want the source code.
Reply With Quote
  #8 (permalink)  
Old 06-30-2008, 12:38 PM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 486
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, 11 views)
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

"Defeat never comes to any man until he admits it."Josephus Daniels
Reply With Quote
  #9 (permalink)  
Old 07-03-2008, 03:15 PM
Newbie
 
Join Date: Jun 2007
Location: UK
Posts: 8
Default

Hi RandomCoder

Please find the source code attached.
Attached Files
File Type: zip RobsCopy.zip (264.3 KB, 12 views)
Reply With Quote
  #10 (permalink)  
Old 07-04-2008, 12:59 PM
RandomCoder's Avatar
Basic4ppc Veteran
 
Join Date: May 2007
Location: UK
Posts: 486
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
__________________
Desktop: Pentium D 920 (2.8GHz, 4MB L2 Cache, 800MHz FSB), 1024MB, 256MB Radeon X600, 250GB HD.
Device : Axim X51v XScale 624MHz, 3.7" VGA, 64MB SDRAM, 256MB Flash ROM + 1Gb SD.

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

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


All times are GMT. The time now is 01:57 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0