By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,808 Members | 1,612 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,808 IT Pros & Developers. It's quick & easy.

Extracting RFID Tag's CRC Hex value using VB 6.0

P: 3
Hello. I'm new to this forum. Hope that I don't make mistakes in here but if I do, please correct me if there is. Thanks.

I also wanted to ask you guys regarding about the following following source codes I'm going to post it here as I did a search here and did not find any question related to mine.

I'm doing an automatic inventory control system using RFID project and I'm instructed to extract the RFID transponder's ID and CRC and display it onto the form I've created using Visual Basic 6.0 before I touch up on the database portion which I need not need to worry much about. I managed to get the program to extract the transponder's ID and display it onto the textbox but I'm having problems extracting the CRC Hex value I'm not sure which part of the code I'm suppose to addon (See below).

Expand|Select|Wrap|Line Numbers
  1. Public Sub Display_Msg(sMsg As String)
  2.  
  3.    frmMain.txtDisplay.Text = frmMain.txtDisplay.Text + sMsg
  4.  
  5. End Sub
  6.  
  7. Public Function Hex2Str(Hex_String As String) As String
  8.     Dim iPos As Integer
  9.     Dim iTemp As Integer
  10.     Dim sMsg As String
  11.     Dim b As String
  12.     Dim gPos As Integer
  13.     Dim g As String
  14.  
  15.  
  16.    For iPos = 8 To Len(Hex_String) - 2
  17.         iTemp = Asc(Mid$(Hex_String, iPos, 2))
  18.  
  19.         If iTemp < 17 Then sMsg = sMsg + "0"
  20.             g = iTemp
  21.             b = b & Chr$(g)
  22.             sMsg = sMsg + Hex(iTemp) + " "
  23.  
  24.    Next iPos
  25.  
  26.  
  27.         frmMain.txtDisplay.Text = frmMain.txtDisplay.Text & _
  28.             "PC -> Reader: 07 FF B0 01 00 1C 56" & vbCrLf
  29.  
  30.         frmMain.txtDisplay.Text = frmMain.txtDisplay.Text & _
  31.             "PC <- Reader: " & sMsg & vbCrLf
  32.         taginput_crc = frmMain.txtDisplay.Text
  33.  
  34.         frmMain.txtDisplay.Text = taginput_crc & _
  35.             "PC <- Reader: 11 FF B0 23 01 " & sMsg & "00 01 " & vbCrLf & vbCrLf
  36.  
  37.         frmMain.MSComm1.Output = Chr$(&H11) + Chr$(&HFF) + Chr$(&HB0) & _
  38.             Chr$(&H23) + Chr$(&H1) + sMsg + Chr$(&H0) + Chr$(&H1) & _
  39.             frmMain.Text2.Text
  40.  
  41.         frmMain.txtDisplay.Text = taginput_crc & _
  42.             "PC -> Reader: 11 FF B0 23 01 " & sMsg & "00 01 " & frmMain.Text2.Text & vbCrLf & vbCrLf
  43.  
  44.  
  45.         frmShoes.txtShoeTag.Text = "11 FF B0 23 01" & sMsg + "00 01"
  46.         frmShirt.txtShirtTag.Text = "11 FF B0 23 01" & sMsg + "00 01"
  47.  
  48.  
  49.         sbuffer = Chr$(&H11) + Chr$(&HFF) + Chr$(&HB0) + Chr$(&H23) + Chr$(&H1) + b + Chr$(&H0) + Chr$(&H1)
  50.  
  51.         crc_output = CalcCRC16CheckSum(sbuffer, Len(sbuffer))
  52.  
  53.         buflen = Len(sbuffer)
  54.         frmMain.Text1.Text = Len(sbuffer)
  55.  
  56. End Function
And also for example, if my CRC value is "D1B8" which isn't correct as the program calculates D1 as MSB and B8 as LSB, what must be edited to obtain the CRC value "B8D1" as this is actually the correct value (see below)?

Expand|Select|Wrap|Line Numbers
  1. Public Function CalcCRC16CheckSum(sbuffer As String, buflen As Byte) As Integer
  2.  
  3.     Dim i, j As Byte
  4.     Dim wCrc As Integer
  5.     Initialise_mPower
  6.     wCrc = CRC16_PRESET
  7.  
  8.     For i = 1 To buflen
  9.  
  10.         wCrc = wCrc Xor Asc(Mid$(sbuffer, i, 1))
  11.         For j = 1 To 8
  12.             If (wCrc And &H1) Then
  13.                 wCrc = LShift(wCrc, 1) Xor POLYNOM
  14.             Else
  15.                 wCrc = LShift(wCrc, 1)
  16.             End If
  17.         Next j
  18.     Next i
  19.  
  20.     crc_output = wCrc
  21.  
  22.     frmMain.crcdisplay.Text = crc_output
  23.     a = Hex(crc_output)
  24.     frmMain.Text2.Text = a
  25.  
  26. End Function
  27.  
  28. Public Function LShift(ivalue As Integer, iBits As Integer) As Integer
  29.  
  30.     If (ivalue And mPower2(15)) = mPower2(15) Then
  31.         LShift = (ivalue And &H7FFF) \ mPower2(iBits) Or mPower2(15 - iBits)
  32.     Else
  33.         LShift = ivalue \ mPower2(iBits)
  34.     End If
  35.  
  36. End Function
  37.  
  38. Public Function RShift(ivalue As Integer, iBits As Integer) As Integer
  39.  
  40.     If (ivalue And mPower2(15 - iBits)) = mPower2(15 - iBits) Then
  41.         RShift = (ivalue And (mPower2(15 - iBits) - 1)) * mPower2(iBits) Or mPower2(15)
  42.     Else
  43.         RShift = (ivalue And (mPower2(15 - iBits) - 1)) * mPower2(iBits)
  44.     End If
  45.  
  46. End Function
Sorry if I posted a big chunk of code in here as I'm unsure of which portion of the code I'm suppose to look into.

Thanks for the help.
Jun 8 '07 #1
Share this Question
Share on Google+
2 Replies


P: 3
I assuming that nobody could answer this? I have been waiting for a reply on this since last week. Thanks again.
Jun 11 '07 #2

P: 3
Can't anyone help? If can't please let me know. Thank you.
Jun 13 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.