Experts,
I'm new to VB and I'm trying developing a VBA application to send and receive data to an RFID reader and put the result into Microsoft Access.
Project has:
Mscomm
command1 (command button)
Text boxes (Text1, Text2)

At this stage i have developed the following code.

Private Sub Command1_Click()
With MSComm1
'make sure the serial port is open
If .PortOpen = False Then .PortOpen = True
'send the data (including a tailing carriage return as often needed)
.Output = ChrW(&HAA) & ChrW(&H0) & ChrW(&H4) & ChrW(&H10) & ChrW(&H6) & ChrW(&H0) & ChrW(&H0) & ChrW(&H12) & ChrW(&HBB) & vbCr
End With 'MSComm1
With Text2
'place the focus back to the textbox
.SetFocus
'select the current text to be overwritten
.SelStart = 0
.SelLength = Len(.Text)
End With 'Text1
End Sub

Private Sub Form_Load()
With MSComm1
'make sure the serial port is not open (by this program)
If .PortOpen Then .PortOpen = False
'set the active serial port
.CommPort = 2
'set the badurate,parity,databits,stopbits for the connection
.Settings = "9600,N,8,1"
'set the DRT and RTS flags
.DTREnable = True
.RTSEnable = True
'enable the oncomm event for every reveived character
.RThreshold = 1
'disable the oncomm event for send characters
.SThreshold = 0
'open the serial port
.PortOpen = True
End With 'MSComm1
With Text1
'set the properties for the displaying textbox
.BackColor = vbCyan
.Locked = True
.Text = ""
End With 'Text1
With Text2
'set the properties for the 'send' textbox
.TabIndex = 0
.Text = ""
End With 'Text2
With Command1
'set the properties for the 'send' command button
.Caption = "&Send"
.Default = True
.TabIndex = 1
End With 'Command1

End Sub
Private Sub Form_Resize()
Dim sngWidth As Single, sngHeight As Single
Dim sngDisplayHeight As Single
Dim sngTxtWidth As Single
Dim sngCmdWidth As Single, sngCmdHeight As Single
'calculate the inner size of the form
sngWidth = ScaleWidth
sngHeight = ScaleHeight
With Command1
'resize and reposition the command button
sngCmdHeight = .Height
sngCmdWidth = .Width
sngDisplayHeight = sngHeight - sngCmdHeight
sngTxtWidth = sngWidth - sngCmdWidth
.Move sngTxtWidth, sngDisplayHeight, sngCmdWidth, sngCmdHeight
End With 'Command1
'resize and reposition the label
Text1.Move 0, 0, sngWidth, sngDisplayHeight
'resize and reposition the textbox
Text2.Move 0, sngDisplayHeight, sngTxtWidth, sngCmdHeight
End Sub

Private Sub MSComm1_OnComm()

Dim strInput As String
Dim Dec_Value
With MSComm1
'test for incoming event
Select Case .CommEvent
Case comEvReceive
'display incoming event data to displaying textbox
strInput = .Input

Text1.SelText = strInput
End Select
End With 'MSComm1

End Sub

This works well and delivers the Hex command to the reader. (Reader led turns orange)
The reader returns the data (verified by portmon) but my text box shows jibberish. The returned result is in the form of Hex "## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##".
I think i need to do 2 things read the correct data type back, and put the individual parts into an array, then sort from there, issue is i don't know how to do this, can anyone point me in the correct direction.

Much appreciate any help.

Try the following -

Private Sub Form_Load()
MSComm1.CommPort = 1            '  Use COM1
MSComm1.Settings = " 9600,N,8,1" ' 9600 Baud, no parity, 8 data
MSComm1.InputLen = 0            ' Read entire buffer when Input is used
MSComm1.PortOpen = True         ' Open port

End Sub

Private Sub MSComm1_OnComm()
Dim strinput As String
strinput = MSComm1.Input

strinput = Mid(strinput, 6, Len(strinput))
Text1.Text = Text1.Text & strinput
Timer1.Interval = 65000
Do Until Timer1.Interval = 0
Timer1.Interval = Timer1.Interval - 1
Loop
Combo1.AddItem strinput

End Sub
Private Sub Timer1_Timer()
Do Until Timer1.Interval = 0
Timer1.Interval = Timer1.Interval - 1
Loop
End Sub

I want DETAILED INFO REGARDING DIS, AS I M WORKING ON RFID PROJECT!!!

PLZ TELL ME HOW TO INTERFACE RFID AND GET DETAILS IN DB

and... I WANT MORE MONEY. WE ALL WANT STUFF WE CAN'T HAVE> READ OUR POSTING RULES, YOU HAVE HIJACKED SOMEONE ELSE'S THREAD!

We do not give DETAILED info here unless you show some effort, so open your OWN thread and post a clear question there please.

@Above, sir actually i dint hijacked any 1 thread all...i found it usefull and implemented this on my own project, but i found some problem..

Pls help me if u can

thanx

Unfortunately you did hijacked this, it belongs to wam cclintock. Have a look at the first post, it is his thread.:)

You can open a new thread by clicking on THIS link. You also need to tell me what exactly you need help on, and I will gladly help.:)

hi....I wanna know if there are any vb codes that will help me connect RFID to vb 6 if the connector (serial to USB connector), the comm port is 51. I usually read some codes for comm1 and comm2 but I think that ain't help me. Is there any solution that will help me connect to vb?

Please help me....thanks....

hi....I wanna know if there are any vb codes that will help me connect RFID to vb 6 if the connector (serial to USB connector), the comm port is 51. I usually read some codes for comm1 and comm2 but I think that ain't help me. Is there any solution that will help me connect to vb?

Please help me....thanks....

try this:

Install PL-2303 USB to Serial (Prolific Tech inc.)

sample 1

Private Sub Form_Load()
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputLen = 0
MSComm1.RThreshold = 1
MSComm1.CommPort = 1
MSComm1.PortOpen = True


End Sub

Private Sub MSComm1_OnComm()
Dim strInput, rfidString As String
Dim intI As Integer
  
  With MSComm1
    
    'test for incoming event
    Select Case .CommEvent
      Case comEvReceive
      MsgBox ""
      Text1.Text = ""
    
        'display incoming event data to displaying textbox
        strInput = .Input
        For intI = 1 To Len(strInput)
            rfidString = rfidString & Hex(Asc(Mid$(strInput, intI, 1))) & " "
             
             Text1.Text = rfidString
            
            Next intI
        rfidString = ""
     End Select
  End With
  
  
End Sub

Sample 2

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

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

' 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)
    

     'sample output
     ItemDatabase.txtID = strnumber
  
    

End If
End Sub

Edited 5 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

This article has been dead for over six months. Start a new discussion instead.