problem with retrieving data from serial port
Hi;
I try to retrieve 8 byte data from com 3 however it is not working properly. I dont know what is wrong with my program! The code is below!
Thanks in advance!
VB Code:
Dim coming As String
MSComm1.PortOpen = True
MSComm1.InputLen = 0
MSComm1.Output = "AT" + Chr$(13)
If MSComm1.InBufferCount Then
MSComm1.InBufferCount = 0
End If
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 8
coming = MSComm1.Input
txtpassword.Text = coming
Re: problem with retrieving data from serial port
http://www.vbforums.com/attachment.p...id=47243&stc=1 Welcome to the forums. :wave:
When you run your program what happens? What does "not working properly" mean?
Re: problem with retrieving data from serial port
Tnks for ur hospitality and fast answer;
Actually compiling does not give any error, however according to coming data, program should send a "y" stand for yes or "n" stand for no. Although I enter the correct data and expect "y", it sends "n" generally, even sometimes strangely "A" and "T" which is irrelevant to program. As far as I understand there is a data loss caused by visual basic. Because when I try hyperterminal, it works fine. Plus, after a few try, it is locking up and program freeze and doesnt give any response.
In the previous message I posted just the part regarding to retrieving data. Now, the complete code is below!
Best Wishes!
VB Code:
Private Sub Form_Load()
Do While 1
Dim coming As String
MSComm1.PortOpen = True
MSComm1.InputLen = 0
MSComm1.Output = "AT" + Chr$(13)
If MSComm1.InBufferCount Then
MSComm1.InBufferCount = 0
End If
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 8
coming = MSComm1.Input
txtpassword.Text = coming
Dim number As String
UserInfo.Refresh
number = txtpassword.Text
Do Until UserInfo.Recordset.EOF
If UserInfo.Recordset.Fields("passwords").Value = number Then
MSComm1.Output = "y" & vbCr
Exit Sub
Else
UserInfo.Recordset.MoveNext
End If
Loop
MSComm1.Output = "n" & vbCr
MSComm1.PortOpen = False
Loop
End Sub
Re: problem with retrieving data from serial port
I realized that i should remove "MSComm1.Output = "AT" + Chr$(13)" part since it causes problem. Still it is locking up. no response after a few try!
Re: problem with retrieving data from serial port
1) How is "y" 8 bytes? I only count 1 byte.
2) You receive data from MSComm in Private Sub MSComm_OnComm (). Don't do any of this in Form_Load. If you want to set the port up immediately, do it in Form_Activate. In MSComm_OnComm, when you get the data from the port, send the next output if the device needs to be told to send you the next byte.
3) You're not defining or instantiating your recordset, you're not connecting your recordset to a connection and you're not loading your recordset.
Quote:
Originally Posted by muratti
I realized that i should remove "MSComm1.Output = "AT" + Chr$(13)" part since it causes problem.
What causes the device to send you data? Not the "AT" command?