|
-
Sep 5th, 2006, 08:16 AM
#1
Thread Starter
New Member
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
-
Sep 5th, 2006, 08:35 AM
#2
Re: problem with retrieving data from serial port
Welcome to the forums. 
When you run your program what happens? What does "not working properly" mean?
-
Sep 5th, 2006, 09:07 AM
#3
Thread Starter
New Member
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
-
Sep 5th, 2006, 09:14 AM
#4
Thread Starter
New Member
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!
-
Sep 5th, 2006, 12:02 PM
#5
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.
 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?
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|