Results 1 to 5 of 5

Thread: problem with retrieving data from serial port

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    3

    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:
    1. Dim coming As String
    2. MSComm1.PortOpen = True
    3. MSComm1.InputLen = 0
    4. MSComm1.Output = "AT" + Chr$(13)
    5. If MSComm1.InBufferCount Then
    6. MSComm1.InBufferCount = 0
    7. End If
    8. Do
    9. DoEvents
    10. Loop Until MSComm1.InBufferCount >= 8
    11. coming = MSComm1.Input
    12. txtpassword.Text = coming

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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?

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    3

    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:
    1. Private Sub Form_Load()
    2. Do While 1
    3. Dim coming As String
    4. MSComm1.PortOpen = True
    5. MSComm1.InputLen = 0
    6. MSComm1.Output = "AT" + Chr$(13)
    7. If MSComm1.InBufferCount Then
    8. MSComm1.InBufferCount = 0
    9. End If
    10. Do
    11. DoEvents
    12. Loop Until MSComm1.InBufferCount >= 8
    13. coming = MSComm1.Input
    14. txtpassword.Text = coming
    15. Dim number As String
    16. UserInfo.Refresh
    17. number = txtpassword.Text
    18. Do Until UserInfo.Recordset.EOF
    19. If UserInfo.Recordset.Fields("passwords").Value = number Then
    20. MSComm1.Output = "y" & vbCr
    21. Exit Sub
    22.  
    23. Else
    24. UserInfo.Recordset.MoveNext
    25. End If
    26.  
    27. Loop
    28.  
    29. MSComm1.Output = "n" & vbCr
    30.  
    31. MSComm1.PortOpen = False
    32.  
    33. Loop
    34.  
    35. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    3

    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!

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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?
    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
  •  



Click Here to Expand Forum to Full Width