关于vb.netusb插拔的信息
怎样用VB读来自USB口的数据
VB可用MsComm控件读取来自USB转RS232接口的数据。或者使用Winsock 控件接收来自USB网卡的数据。
为李沧等地区用户提供了全套网页设计制作服务,及李沧网站建设行业解决方案。主营业务为网站制作、成都网站设计、李沧网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
MSComm 控件通过串行端口传输和接收数据,为应用程序提供串行通讯功能。
利用 WinSock 控件可以与远程计算机建立连接,并通过用户数据文报协议 (UDP)或者传输控制协议
(TCP)进行数据交换。这两种协议都可以用来创建客户与服务器应用程序。
vb.net 如何判断u盘是否接入
窗体上添加两个标签:Label1和Label2
下面代码经过VB 2005测试通过。
Imports System.IO
Public Class Form1
Public Const WM_DEVICECHANGE = H219
Public Const DBT_DEVICEARRIVAL = H8000
Public Const DBT_CONFIGCHANGECANCELED = H19
Public Const DBT_CONFIGCHANGED = H18
Public Const DBT_CUSTOMEVENT = H8006
Public Const DBT_DEVICEQUERYREMOVE = H8001
Public Const DBT_DEVICEQUERYREMOVEFAILED = H8002
Public Const DBT_DEVICEREMOVECOMPLETE = H8004
Public Const DBT_DEVICEREMOVEPENDING = H8003
Public Const DBT_DEVICETYPESPECIFIC = H8005
Public Const DBT_DEVNODES_CHANGED = H7
Public Const DBT_QUERYCHANGECONFIG = H17
Public Const DBT_USERDEFINED = HFFFF
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_DEVICECHANGE Then
Select Case m.WParam
Case WM_DEVICECHANGE
Case DBT_DEVICEARRIVAL 'U盘插入
Dim s() As DriveInfo = DriveInfo.GetDrives
For Each drive As DriveInfo In s
If drive.DriveType = DriveType.Removable Then
Label2.Text = "U盘已经插入!盘符为:" + drive.Name.ToString()
End If
Next
Case DBT_CONFIGCHANGECANCELED
Case DBT_CONFIGCHANGED
Case DBT_CUSTOMEVENT
Case DBT_DEVICEQUERYREMOVE
Case DBT_DEVICEQUERYREMOVEFAILED
Case DBT_DEVICEREMOVECOMPLETE 'U盘卸载
Label2.Text = "U盘已经拔出!"
Case DBT_DEVICEREMOVEPENDING
Case DBT_DEVICETYPESPECIFIC
Case DBT_DEVNODES_CHANGED
Case DBT_QUERYCHANGECONFIG
Case DBT_USERDEFINED
End Select
End If
MyBase.WndProc(m)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Text = "请操作U盘!"
Label2.Text = ""
End Sub
End Class
vb.net编程接受U盘准备卸载用的windows消息 DBT_DEVICEQUERYREMOVE总是没反应,据说是因为默认注册的消息里
在我的XP+VB2010环境下,测试U盘插入拔出,没有问题:
Private WM_DEVICECHANGE As Integer = H219
Public Enum WM_DEVICECHANGE_WPPARAMS As Integer
DBT_CONFIGCHANGECANCELED = H19
DBT_CONFIGCHANGED = H18
DBT_CUSTOMEVENT = H8006
DBT_DEVICEARRIVAL = H8000
DBT_DEVICEQUERYREMOVE = H8001
DBT_DEVICEQUERYREMOVEFAILED = H8002
DBT_DEVICEREMOVECOMPLETE = H8004
DBT_DEVICEREMOVEPENDING = H8003
DBT_DEVICETYPESPECIFIC = H8005
DBT_DEVNODES_CHANGED = H7
DBT_QUERYCHANGECONFIG = H17
DBT_USERDEFINED = HFFFF
End Enum
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_DEVICECHANGE Then
Select Case m.WParam
Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEARRIVAL
MsgBox("USB device is just plugged in!")
Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEREMOVECOMPLETE
MsgBox("USB device is just taken out")
End Select
End If
MyBase.WndProc(m)
End Sub
vb.net 做的通信程序,设备掉电后出错:无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接
看下这个异常的类型 在捕捉异常的时候处理为关闭并重新打开端口监听(这个看你自己需求) 然后在socketException下面再catch其它exception 进行弹出错误提示之类的操作 就可以了
本文标题:关于vb.netusb插拔的信息
文章路径:http://azwzsj.com/article/dosodgs.html