找回密码
 注册

QQ登录

只需一步,快速开始

搜索

VB串口和单片机读IC卡上位机源程序

[复制链接]
coolice 发表于 2020-5-3 18:03:20 | 显示全部楼层 |阅读模式
通过串口和单片机通讯的ic卡读卡程序VB源码.rar (55.17 KB, 售价: 1 E币)

1.png

  1. Attribute VB_Name = "IC卡管理自动记录系统"
  2. Attribute VB_GlobalNameSpace = False
  3. Attribute VB_Creatable = False
  4. Attribute VB_PredeclaredId = True
  5. Attribute VB_Exposed = False
  6. Option Explicit
  7. Public inData As String '串口中断时读入的字符串
  8. Dim TEXT_OK As Boolean
  9. Dim text1_temp As String
  10. Dim t7 As String



  11. Private Sub Command2_Click()
  12. data1.Recordset.MovePrevious
  13. If data1.Recordset.BOF Then data1.Recordset.MoveFirst
  14. Text1.Text = data1.Recordset("卡号")
  15. Text2.Text = data1.Recordset("姓名")
  16. Text3.Text = data1.Recordset("班级")
  17. Text4.Text = data1.Recordset("余额")
  18. Text5.Text = data1.Recordset("日期")
  19. Text6.Text = data1.Recordset("时间")

  20. Text9.Text = Format(CStr(CStr((CSng(Text4.Text) * 100) \ 60)), "#00") & "小时" & Format(CStr(CStr((CSng(Text4.Text) * 100) Mod 60)), "#00") & " 分钟"
  21. data1.UpdateRecord
  22. End Sub

  23. Private Sub Command3_Click()

  24. If data1.Recordset.EOF = False Then data1.Recordset.MoveNext
  25. If data1.Recordset.EOF Then data1.Recordset.MoveLast
  26. Text1.Text = data1.Recordset("卡号")
  27. Text2.Text = data1.Recordset("姓名")
  28. Text3.Text = data1.Recordset("班级")
  29. Text4.Text = data1.Recordset("余额")
  30. Text5.Text = data1.Recordset("日期")
  31. Text6.Text = data1.Recordset("时间")
  32. data1.UpdateRecord

  33. Text9.Text = Format(CStr(CStr((CSng(Text4.Text) * 100) \ 60)), "#00") & "小时" & Format(CStr(CStr((CSng(Text4.Text) * 100) Mod 60)), "#00") & " 分钟"
  34. End Sub

  35. Sub 找卡号()
  36. Dim n, m As Integer
  37. data1.Refresh
  38. data1.Recordset.MoveLast
  39. m = data1.Recordset.RecordCount
  40. data1.Refresh
  41. data1.Recordset.MoveFirst

  42. For n = 1 To m Step 1
  43.     If Text1.Text = data1.Recordset("卡号") Then
  44.         Text1.Text = data1.Recordset("卡号")
  45.         'Text2.Text = data1.Recordset("姓名")
  46.         'Text3.Text = data1.Recordset("班级")
  47.     End If
  48.     data1.Recordset.MoveNext
  49. Next n
  50. End Sub




  51. Private Sub Command6_Click()
  52. Timer2.Enabled = True
  53. Command9.Enabled = True
  54. Command6.Enabled = False
  55. End Sub

  56. Private Sub Command7_Click()

  57. Text1.Text = ""

  58. Text2.Text = ""
  59. Text3.Text = ""
  60. Text4.Text = ""
  61. MSComm1.Output = "rr12345678" '把查询命令发出到串口
  62. End Sub
  63. Private Sub Command8_Click()
  64. Dim NUM, n, m As Integer

  65. Call CACK_TEXT
  66. If TEXT_OK = True Then
  67.     NUM = Val(Text4.Text)
  68.     n = NUM \ 256
  69.     m = NUM - n * 256
  70.     'Call 写入单片机
  71.    
  72.     Call 写入数据库
  73.     text1_temp = Text1.Text
  74.     Text1.Text = ""
  75. Else
  76.     n = MsgBox("请正确输入", 5 + vbExclamation, "错误")
  77. End If

  78. End Sub
  79. Sub 写入单片机()
  80. Dim adsafdds As String
  81. Dim yuer1, yuer2 As String
  82. yuer1 = Format(CStr(CStr((CSng(Text4.Text) * 100) \ 60)), "#00")
  83. yuer2 = Format(CStr(CStr((CSng(Text4.Text) * 100) Mod 60)), "#00")

  84. adsafdds = "ss" & Text1.Text & yuer1 & yuer2
  85. MSComm1.Output = adsafdds

  86. End Sub

  87. Private Sub Command9_Click()
  88. Timer2.Enabled = False
  89. Command6.Enabled = True
  90. Command9.Enabled = False
  91. End Sub

  92. Private Sub Form_Load()
  93. MSComm1.PortOpen = True
  94. MSComm1.RThreshold = 1
  95. Command8.Enabled = False
  96. Command6.Enabled = True
  97. Command9.Enabled = False
  98. End Sub
  99. Sub CACK_TEXT()
  100. TEXT_OK = False
  101. If (Len(Text1.Text) = 4 And Len(Text4.Text) < 6) Then TEXT_OK = True
  102. End Sub
  103. Sub 写入数据库()
  104. data1.Refresh
  105. data1.Recordset.MoveLast
  106. data1.Recordset.AddNew
  107. data1.Recordset("卡号") = Text1.Text
  108. 'data1.Recordset("姓名") = Text2.Text
  109. 'data1.Recordset("班级") = Text3.Text
  110. data1.Recordset("余额") = Text4.Text
  111. data1.Recordset("日期") = Date
  112. data1.Recordset("时间") = Time()
  113. data1.UpdateRecord

  114. End Sub


  115. Private Sub MSComm1_OnComm() '串口中断
  116. 'On Error Resume Next
  117. Static bFlag As Boolean
  118. Static Xbyte As Long
  119. Select Case MSComm1.CommEvent '选择事件
  120. Case comEvReceive '接收到字符
  121. Dim I As Integer
  122.         Dim InByte() As Byte '定义一个二进制指针放接收到的数据
  123.         InByte = MSComm1.Input '数据转移到指针
  124.         Dim j As Long
  125.         For j = 0 To UBound(InByte) '循环到指针上标
  126.             
  127.             inData = inData & Chr(InByte(j)) '取出一个字节换为16进制显示用
  128.          
  129.         Next j
  130. DoEvents
  131.     Text1.SelText = inData '将刚收到的字符串显示出来
  132.     inData = ""
  133. Text1.SelStart = Len(Text1.Text) '光标置后
  134.   If Len(Text1.Text) = 10 Then
  135.     Call 计算
  136.     'Call 找卡号
  137.   End If
  138. Case comEventRxOver '接收缓冲区满的处理
  139. MsgBox "接收缓冲区满了!" '发出警告
  140. End Select

  141. End Sub

  142. Sub 计算()
  143. Dim temp As String
  144. Dim 标志 As String
  145. Dim k As Integer
  146. Dim yuer1   As String
  147. Dim 余额    As Integer
  148. temp = Text1.Text

  149. 标志 = Left(temp, 1)
  150. temp = Right(temp, Len(temp) - 2)
  151. Select Case 标志
  152.     Case "s"
  153.         Text1.Text = Left(temp, 4)
  154.         
  155.     Case "r"
  156.         Text1.Text = ""
  157.         MsgBox "写卡成功!!!!!"

  158.         GoTo 计算end
  159.     Case Else
  160.         Text1.Text = ""
  161.         MsgBox "通讯有误??????"
  162.         GoTo 计算end
  163. End Select
  164.     temp = Right(temp, 4)
  165.     Text9.Text = Left(temp, 2) & "小时" & Right(temp, 2) & "分钟"
  166.     Text4.Text = Format(CStr((CSng(Left(temp, 2) * 60 + CSng(Right(temp, 2)))) / 100), "#00.00")
  167. 计算end:
  168.    
  169. End Sub


  170. ……………………

  171. …………限于本文篇幅 余下代码请下载附件…………
复制代码


您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-12-27 10:53

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表