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.