[RESOLVED] Read Data From COM Port
Hi everyone...
I have problem here on how to read data from COM Port. Recently i'm working a project on read data from RFID. This device were attached to COM Port. The 1'st i've done is connect to COM port using this code:
Code:
Private Sub MSComm1_OnComm()
Dim strInput As String
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
However the output is "||||||". Could someone help me on this? If i'm not mistaken the data from COM Port is in HEX format. Is it true? If true...what should i do to convert to text or string. Really need help here.
Thanks in advances.
Re: Read Data From COM Port
Welcome to the Forums.
Thread Mmoved
Re: Read Data From COM Port
Well, it looks as if your device is sending non-printable characters. To find out you could use something like this:
Code:
Private Sub MSComm1_OnComm()
Dim strInput As String
Dim intI As Integer
With MSComm1
'test for incoming event
Select Case .CommEvent
Case comEvReceive
'display incoming event data to displaying textbox
strInput = .Input
For intI = 1 To Len(strInput)
Text1.Text = Text1.Text & Hex(Asc(Mid$(strInput, intI, 1))) & " "
Next intI
End Select
End With 'MSComm1
The above should display the data received in Hex in Text1
Re: Read Data From COM Port
Thanks a lot Doogle. Its really help me. I got this output = 8A 84 84 84 4 0 0 0 F0 0 0 0 0 0 0 0 0 0 10 0 0 0 30 0 F0.
It seems like HEX file. Isn't it? Well then...how can i convert this to string? I mean i want in Text1.Text displat the string.
Thanks again Doogle for quick reply.
Re: Read Data From COM Port
Well, that data does not represent any printable characters so can't be directly converted into anything 'human readable'. Do you have any idea what the data is meant to represent?
Re: Read Data From COM Port
Well..its like this. My project is Inventory System Using RFID. A simple one. So i need to read id tag that read by rfid reader (MF700). This device is attach to COM port/serial. Thats why i need to read those HEX n convert it to readable data. Mostly its id tag such as for example XA024D1S.
P.S : I'm using MF700 Mifare Card Issuer (come with the device) to write some data to mifare card. The ascii string is 00000001 and the HEX code is "30 30 30 30 30 30 30 31".
Re: Read Data From COM Port
I can only guess that the data is encoded in some way. Is there any documentation with the device that indicates the format of the data sent ?
Re: Read Data From COM Port
I'm afraid there is no document or SDK. Only installation for those program i've mention above. It only have some diagram for wiring the device.
I've testing MF700-30 Utility (reader Application) comes with the device. Here is the screenshot.
http://farm4.static.flickr.com/3016/...1fab44d7_m.jpg
Re: Read Data From COM Port
Latest trial....i've change MSComm property it its inputmode. I've changed it to 1-inputComModeBinary. Then i get this kind of output = 3C 3F 3F 3F. So...what should i do? The right output should be 00000001. Can someone here help me on this?
Thanks in advances.
Re: Read Data From COM Port
Have you checked the MSComm Settings ? They must match those expected by the RFID device. The Hex 3F (a ?) is the default character that MSCOmm will insert into the stream if a Parity error happens. Check / change the Parity setting.
eg
Code:
'
' No Parity
'
MSComm1.Settings = "9600,N,8,1"
'
' Even Parity
'
MSComm1.Settings = "9600,E,8,1"
'
' Odd Parity
'
MSComm1.Settings = "9600,O,8,1"
One of the above might work.
Also, those settings assume 9600 bits per second transfer rate, again, it might have to operate at a slower speed. Finally, it's just possible that it only transfers 7 data bits, and / or sends 2 stop bits. There's a huge number of combinations you could try but if you have no manual or other information it's going to be trial and error. I'd look at the Parity settings first.
Re: Read Data From COM Port
This what i've got:
Code:
With MSComm1.Settings = "9600,N,8,1"
Output is 8 30 30 30 30 30 30 30 31
MSComm1.Settings = "9600,E,8,1"
Output is 3F 3F 3F 3F 3F 3F 3F 3F 3F 3F
With MSComm1.Settings = "9600,O,8,1"
Output is 3F 3F 3F 3F 3F 3F 3F 3F
I've count with MSComm1.Settings = "9600,O,8,1" exactly 8. But with MSComm1.Settings = "9600,O,8,1" I've got 10. I'll guest I'm going to stick with MSComm1.Settings = "9600,O,8,1".
My question here...what format the output represent? Is it HEX or Binary or mayb ASCII? Got confuse here. However...thanks for ur tips Doogle.
:D
Re: Read Data From COM Port
I've changed the parity to MSComm1.Settings = "19200,N,8,1". The new RFID tag value is A001B001 using the program comes with the device. When I tried to read the data/value using my own application...the output i get is "41 30 30 31 42 30 30 31". This is HEX files. What should i do to convert it to ASCII?
Re: Read Data From COM Port
This will display the RFID in the textbox:
Code:
Private Sub MSComm1_OnComm()
Dim strInput As String
Dim intI As Integer
With MSComm1
'test for incoming event
Select Case .CommEvent
Case comEvReceive
'display incoming event data to displaying textbox
strInput = .Input
Text1.Text = Text1.Text & strInput
End Select
End With
Re: Read Data From COM Port
Thanks a lot Doogle. U really help me on this. Now I can carry on to my main project. The problem is solve now. Million thanks to u. :thumb: