通过串口和单片机通讯的ic卡读卡程序VB源码.rar
(55.17 KB, 售价: 1 E币)
- Attribute VB_Name = "IC卡管理自动记录系统"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Public inData As String '串口中断时读入的字符串
- Dim TEXT_OK As Boolean
- Dim text1_temp As String
- Dim t7 As String
- Private Sub Command2_Click()
- data1.Recordset.MovePrevious
- If data1.Recordset.BOF Then data1.Recordset.MoveFirst
- Text1.Text = data1.Recordset("卡号")
- Text2.Text = data1.Recordset("姓名")
- Text3.Text = data1.Recordset("班级")
- Text4.Text = data1.Recordset("余额")
- Text5.Text = data1.Recordset("日期")
- Text6.Text = data1.Recordset("时间")
- Text9.Text = Format(CStr(CStr((CSng(Text4.Text) * 100) \ 60)), "#00") & "小时" & Format(CStr(CStr((CSng(Text4.Text) * 100) Mod 60)), "#00") & " 分钟"
- data1.UpdateRecord
- End Sub
- Private Sub Command3_Click()
- If data1.Recordset.EOF = False Then data1.Recordset.MoveNext
- If data1.Recordset.EOF Then data1.Recordset.MoveLast
- Text1.Text = data1.Recordset("卡号")
- Text2.Text = data1.Recordset("姓名")
- Text3.Text = data1.Recordset("班级")
- Text4.Text = data1.Recordset("余额")
- Text5.Text = data1.Recordset("日期")
- Text6.Text = data1.Recordset("时间")
- data1.UpdateRecord
- Text9.Text = Format(CStr(CStr((CSng(Text4.Text) * 100) \ 60)), "#00") & "小时" & Format(CStr(CStr((CSng(Text4.Text) * 100) Mod 60)), "#00") & " 分钟"
- End Sub
- Sub 找卡号()
- Dim n, m As Integer
- data1.Refresh
- data1.Recordset.MoveLast
- m = data1.Recordset.RecordCount
- data1.Refresh
- data1.Recordset.MoveFirst
- For n = 1 To m Step 1
- If Text1.Text = data1.Recordset("卡号") Then
- Text1.Text = data1.Recordset("卡号")
- 'Text2.Text = data1.Recordset("姓名")
- 'Text3.Text = data1.Recordset("班级")
- End If
- data1.Recordset.MoveNext
- Next n
- End Sub
- Private Sub Command6_Click()
- Timer2.Enabled = True
- Command9.Enabled = True
- Command6.Enabled = False
- End Sub
- Private Sub Command7_Click()
- Text1.Text = ""
- Text2.Text = ""
- Text3.Text = ""
- Text4.Text = ""
- MSComm1.Output = "rr12345678" '把查询命令发出到串口
- End Sub
- Private Sub Command8_Click()
- Dim NUM, n, m As Integer
- Call CACK_TEXT
- If TEXT_OK = True Then
- NUM = Val(Text4.Text)
- n = NUM \ 256
- m = NUM - n * 256
- 'Call 写入单片机
-
- Call 写入数据库
- text1_temp = Text1.Text
- Text1.Text = ""
- Else
- n = MsgBox("请正确输入", 5 + vbExclamation, "错误")
- End If
- End Sub
- Sub 写入单片机()
- Dim adsafdds As String
- Dim yuer1, yuer2 As String
- yuer1 = Format(CStr(CStr((CSng(Text4.Text) * 100) \ 60)), "#00")
- yuer2 = Format(CStr(CStr((CSng(Text4.Text) * 100) Mod 60)), "#00")
- adsafdds = "ss" & Text1.Text & yuer1 & yuer2
- MSComm1.Output = adsafdds
- End Sub
- Private Sub Command9_Click()
- Timer2.Enabled = False
- Command6.Enabled = True
- Command9.Enabled = False
- End Sub
- Private Sub Form_Load()
- MSComm1.PortOpen = True
- MSComm1.RThreshold = 1
- Command8.Enabled = False
- Command6.Enabled = True
- Command9.Enabled = False
- End Sub
- Sub CACK_TEXT()
- TEXT_OK = False
- If (Len(Text1.Text) = 4 And Len(Text4.Text) < 6) Then TEXT_OK = True
- End Sub
- Sub 写入数据库()
- data1.Refresh
- data1.Recordset.MoveLast
- data1.Recordset.AddNew
- data1.Recordset("卡号") = Text1.Text
- 'data1.Recordset("姓名") = Text2.Text
- 'data1.Recordset("班级") = Text3.Text
- data1.Recordset("余额") = Text4.Text
- data1.Recordset("日期") = Date
- data1.Recordset("时间") = Time()
- data1.UpdateRecord
- End Sub
- Private Sub MSComm1_OnComm() '串口中断
- 'On Error Resume Next
- Static bFlag As Boolean
- Static Xbyte As Long
- Select Case MSComm1.CommEvent '选择事件
- Case comEvReceive '接收到字符
- Dim I As Integer
- Dim InByte() As Byte '定义一个二进制指针放接收到的数据
- InByte = MSComm1.Input '数据转移到指针
- Dim j As Long
- For j = 0 To UBound(InByte) '循环到指针上标
-
- inData = inData & Chr(InByte(j)) '取出一个字节换为16进制显示用
-
- Next j
- DoEvents
- Text1.SelText = inData '将刚收到的字符串显示出来
- inData = ""
- Text1.SelStart = Len(Text1.Text) '光标置后
- If Len(Text1.Text) = 10 Then
- Call 计算
- 'Call 找卡号
- End If
- Case comEventRxOver '接收缓冲区满的处理
- MsgBox "接收缓冲区满了!" '发出警告
- End Select
- End Sub
- Sub 计算()
- Dim temp As String
- Dim 标志 As String
- Dim k As Integer
- Dim yuer1 As String
- Dim 余额 As Integer
- temp = Text1.Text
- 标志 = Left(temp, 1)
- temp = Right(temp, Len(temp) - 2)
- Select Case 标志
- Case "s"
- Text1.Text = Left(temp, 4)
-
- Case "r"
- Text1.Text = ""
- MsgBox "写卡成功!!!!!"
- GoTo 计算end
- Case Else
- Text1.Text = ""
- MsgBox "通讯有误??????"
- GoTo 计算end
- End Select
- temp = Right(temp, 4)
- Text9.Text = Left(temp, 2) & "小时" & Right(temp, 2) & "分钟"
- Text4.Text = Format(CStr((CSng(Left(temp, 2) * 60 + CSng(Right(temp, 2)))) / 100), "#00.00")
- 计算end:
-
- End Sub
- ……………………
- …………限于本文篇幅 余下代码请下载附件…………
复制代码
【必读】版权免责声明
1、本主题所有言论和内容纯属会员个人意见,与本论坛立场无关。2、本站对所发内容真实性、客观性、可用性不做任何保证也不负任何责任,网友之间仅出于学习目的进行交流。3、对提供的数字内容不拥有任何权利,其版权归原著者拥有。请勿将该数字内容进行商业交易、转载等行为,该内容只为学习所提供,使用后发生的一切问题与本站无关。 4、本网站不保证本站提供的下载资源的准确性、安全性和完整性;同时本网站也不承担用户因使用这些下载资源对自己和他人造成任何形式的损失或伤害。 5、本网站所有软件和资料均为网友推荐收集整理而来,仅供学习用途使用,请务必下载后两小时内删除,禁止商用。6、如有侵犯你版权的,请及时联系我们(电子邮箱1370723259@qq.com)指出,本站将立即改正。
|