[已解决]新手:检测USB手机 [英] [Solved] Newbie: Detect USB phone
问题描述
嗨
我在玩VB.net,为我的手机创建程序
.
我已经建立了连接等(USB-串行端口),并且一切正常.
但是我的问题是当我取下手机时,出现程序错误(当然是:-).
我试图找到一种方法来检测电话是否已连接到USB端口,但是未能成功找到一种方法来检测硬件是否已连接.
我想创建一个可以在通讯之前执行的功能,可以在其中检查USB设备是否存在.
还是有更好的方法?
在此先感谢您,并为我的愚蠢问题感到抱歉:-)
/Graves
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
推荐答案
本文可能对您有所帮助:检测USB在C#程序中删除驱动器 [ ^ ]
(我知道它是C#而不是VB,但不要让它阻止了您!)
干杯
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
嗨
感谢您的回答:-)
我把这个构建放在一起,似乎可以满足我的要求.
认为我正在将其集成到一个类中,并通过DeviceID识别手机.
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.
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
/Graves
我认为最好是与电话制造商联系-他们可能有一个可以用于此目的的SDK,甚至可能还有代码示例...
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...
这篇关于[已解决]新手:检测USB手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!