Monday 9 July 2012

Programming with RFID Reader


Im back again this time i will show how to use RFID Reader in VB6 Currently im developing Loadable E-Pass System for a confidential client and i want to share some of of codes regarding RFID and VB6. These is pretty straight forward i used MSCOMM (serial library in .NET) component in order to read /write buffer connected to PC's serial/usb port. This is done by using the oncomm() event in order to read all the buffers send by the RFID interface without using the timer control.



Private Sub Form_Load()
On Error Resume Next

' Fire Rx Event Every Two Bytes
MSComm1.RThreshold = 2

' When Inputting Data, Input 2 Bytes at a time
MSComm1.InputLen = 2

' 2400 Baud, No Parity, 8 Data Bits, 1 Stop Bit
MSComm1.Settings = "2400,N,8,1"

' Make sure DTR line is low to prevent Stamp reset
MSComm1.DTREnable = False

' Open COM1
MSComm1.CommPort = 1
MSComm1.PortOpen = True

If MSComm1.PortOpen = False Then
MsgBox "RFID not Connected!! system will shutdown!!"
End

End If



End Sub

Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If

End Sub



Private Sub MSComm1_OnComm()
Dim sData As String
Dim lHighByte As Long
Dim lLowByte As Long
Dim lByte As Long

' If Rx Event then get data and process
If MSComm1.CommEvent = comEvReceive Then
    sData = MSComm1.Input ' Get data
    lHighByte = Asc(Mid$(sData, 1, 1)) ' get 1st byte
    lLowByte = Asc(Mid$(sData, 2, 1))  ' Get 2nd byte
    lByte = JoinHighLow(lHighByte, lLowByte)
    
    strnumber = CStr(lByte)
    
    
    ItemDatabase.txtID = strnumber
 
      

End If
End Sub

Private Function JoinHighLow(lHigh As Long, lLow As Long) As Long
JoinHighLow = (lHigh * &H100) Or lLow
End Function

Updates:
USB to RS232 converter compatible:
Download and install prolific drivers.
For more info please download the sample project Happy coding for Design projects, custom web and windows application, please visit

Facebook Fan Page
comments

No comments:

Post a Comment