重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

vb.net读取usb,vbnet读取文件内容

VB如何获取USB口条码枪的扫描数据?

这么跟你说吧,条码扫描器就相当于自动打字的键盘一样,会把扫描到的条码自动转换为数字然后发送到电脑中。你打开记事本,然后扫描一些条码试试就知道了。

成都创新互联公司是一家集网站建设,大丰企业网站建设,大丰品牌网站建设,网站定制,大丰网站建设报价,网络营销,网络优化,大丰网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

你的条码扫描器的说明书应该还有各种设置方法的说明的,可以给扫描器增添各种功能,比如在条码数字的后面增加一个回车键,这在编程中比较有用。

vb.net中,读取和写入文件

写入:Dim sr As New IO.StreamWriter(Application.StartupPath "/写入的文本.txt")

sr.WriteLine("写入的内容") sr.Close()读取:If (File.Exists(Application.StartupPath "/msg.txt")) Then

Dim fm As New IO.FileStream(Application.StartupPath "/读取的文本.txt", FileMode.Open)

Dim sr As IO.StreamReader = New IO.StreamReader(fm)

Do While sr.Peek() = 0

TextBox1.Text = sr.ReadLine() (读取文本到文本框)

Loop end if

VB.NET检测插入U盘时执行某段代码,并能获取U盘盘符

以下内容为网络提供,但我自己验证可行,供你参考.

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盘插入

ComboBox1.Items.Clear()

Dim s() As DriveInfo = DriveInfo.GetDrives

For Each drive As DriveInfo In s

If drive.DriveType = DriveType.Removable Then

ListBox1.Items.Add("U盘已插入!盘符为:" + drive.Name.ToString())

ComboBox1.Items.Add(drive.Name)

End If

Next

BtnWrite.Enabled = True

BtnRead.Enabled = True

Case DBT_CONFIGCHANGECANCELED

Case DBT_CONFIGCHANGED

Case DBT_CUSTOMEVENT

Case DBT_DEVICEQUERYREMOVE

Case DBT_DEVICEQUERYREMOVEFAILED

Case DBT_DEVICEREMOVECOMPLETE 'U盘卸载

ListBox1.Items.Add("U盘卸载!")

BtnWrite.Enabled = False

BtnRead.Enabled = False

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

ListBox1.Items.Add("请您现在插入U盘至USB接口!")

End Sub

Private Sub BtnWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnWrite.Click

If ComboBox1.Text = "" Then

MsgBox("请选择U盘盘符!", MsgBoxStyle.Exclamation, "Warn")

Else

Dim Writer As StreamWriter = Nothing

Try

Dim fileName As String = ComboBox1.Text + "Test.txt"

Writer = New StreamWriter(fileName)

Writer.WriteLine(InputBox("老四,请输入要保存的字符串", "输入信息", "Input then Test String! hehe!"))

MsgBox("Write to " + fileName + " Success!")

Catch ex As Exception

MsgBox(ex.Message, MsgBoxStyle.Critical, "Write 失败")

Finally

If Writer IsNot Nothing Then Writer.Close()

End Try

End If

End Sub

Private Sub BtnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRead.Click

If ComboBox1.Text = "" Then

MsgBox("请选择U盘盘符!", MsgBoxStyle.Exclamation, "Warn")

Else

Dim Reader As StreamReader = Nothing

Try

Dim fileName As String = ComboBox1.Text + "Test.txt"

Reader = New StreamReader(fileName)

MsgBox("Read from " + fileName + vbCrLf + Reader.ReadToEnd, MsgBoxStyle.Information, "Info")

Catch ex As Exception

MsgBox(ex.Message, MsgBoxStyle.Critical, "Read 失败")

Finally

If Reader IsNot Nothing Then Reader.Close()

End Try

End If

End Sub

End Class

关于VB和USB

如果是USB转串口,那么还用mscomm控件,如果不是,那就问生产厂家要通讯协议。

VB.NET怎样把USB摄像头在显示器上输出的实时画面(像素信息),引入到数据库.

用directshow获取帧缓存,转换为标准图像格式(比如jpg,png这些),存储到数据库的image字段里就行了.

vb.net 读取扫描枪USB接口数据的实例

USB比较难抓数据,建议是USB模拟串口,或者直接就是串口,这样数据比较好抓。

USB上传模式是鼠标光标在哪数据就上传在哪,所以你抓USB的数据的很难!

X猫-思刊办公专营店


网站名称:vb.net读取usb,vbnet读取文件内容
浏览地址:http://cqcxhl.com/article/hohhdp.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP