VB中一个简单的串口通信问题,求求各位大神帮帮忙
先看这段代码Private Sub Timer1_Timer()
Dim SQL, mytime, name, department, description As String
Dim i As Integer
Dim inbuf$ '用来存放收到的数据
mytime = Now
card_numb(1) = "3c 73 42 27 fd 03"
card_numb(2) = "4c 25 48 71 fp 03"
card_numb(3) = "5c 34 38 87 fl 03"
card_numb(4) = "6c 40 31 43 fe 03"
card_numb(5) = "2c 89 32 45 fa 03"
inbuf = "3c 73 42 27 fd 03"
For i = 1 To 5
If card_numb(i) = inbuf Then
SQL = "select *from worker_Infor where 卡号= '" & i & "'"
ExecuteSQL (SQL)
name = rname.Fields(1)
department = rname.Fields(2)
description = rname.Fields(3)
SQL = "select *from Infor_record"
ExecuteSQL (SQL)
rname.AddNew
rname.Fields(0) = i
rname.Fields(1) = name
rname.Fields(2) = department
rname.Fields(3) = mytime
rname.Fields(4) = description
Text1.Text = rname.Fields(0)
Text2.Text = rname.Fields(2)
Text3.Text = rname.Fields(1)
Text4.Text = rname.Fields(3)
Text5.Text = rname.Fields(4)
rname.Update
rname.Close
End If
Next i
End Sub
这段代码的功能是实现读取卡号信息并输出卡号对应的员工信息吧,里面的inbuf是一个给定的值‘3c 73 42 27 fd 03’,无论刷的卡号是怎样的数,输出地结果都是‘3c 73 42 27 fd 03’所对应的信息。我想知道要是想实现这样的功能:把读卡器读取到卡号存储到inbuf里面再与员工卡号匹配,并输出相应的员工信息。这段代码该做怎样的修改,还需要用到MScomm里面的哪些函数?
--------------------编程问答-------------------- 个人认为不需要使用到Timer控件
MSComm1.RThreshold = 1 当有信息从读卡器上时产生Comm事件
然后从Comm事件里读取当前读取到的卡号至inbuf,
然后再用SQl查询就行了
补充:VB , 控件