Click here to Skip to main content
15,899,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I am playing at bit with VB.net, creating a program for my phone
.
I have established the connection etc. (USB - serial port), and everything is working fine.

But my problem is when I remove the phone, I get a program error (of course :-).

I have tried to find a way to detect if the phone is connected to the USB port, but I have not been successful in finding a good way to detect if the hardware is connected.
I would like to create a function that I can execute before communication, where I can check if the USB device is present.
Or is there a better way?

Thanks on advance and sorry for my stupid question :-)

/Graves
Posted
Updated 15-Jul-10 22:50pm
v2

Maybe this article helps : Detecting USB Drive Removal in a C# Program[^]
(I know it's C# and not VB but don't let that stop you!)

Cheers
 
Share this answer
 
v2
Comments
Johnny J. 13-Jul-10 5:39am    
I doubt that would be of much help in this case, but I could be wrong...
Hi
Thanks for your answers :-)
I got this build together, and it seems to do what I want.

Think that I am integrating it in a class and identify the phone from via the DeviceID.


VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      Me.ListBox1.Items.Clear()
      Dim ManageObjSearcher As New ManagementObjectSearcher("SELECT * FROM  Win32_PnPEntity")
      Dim ManageObj As ManagementObject
      For Each ManageObj In ManageObjSearcher.Get()
          If Not ManageObj("Service") Is Nothing Then
              If ManageObj("DeviceID").ToString().StartsWith("USB") Then
                  Me.ListBox1.Items.Add(ManageObj("Name").ToString() + " - " + ManageObj("DeviceID").ToString())
              End If
          End If
      Next ManageObj
  End Sub



/Graves
 
Share this answer
 
Comments
Sandeep Mewara 14-Jul-10 1:57am    
Don't push answer button when it is not. Use Comment feature to respond to an answer.
Update question in case you need to edit/update with more details or add a resolution you found (setting [Solved] in title.)
I think the best would be to contact the phone manufacturer - they might have a SDK that you can use for this, and perhaps even code samples...
 
Share this answer
 
A thousand thank-yous for this code! VERY helpful. -- Bopert
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900