Click here to Skip to main content
14,327,358 members
Rate this:
Please Sign up or sign in to vote.
See more:
i want a code which implements receiving of hex data from the hardware through serial port here is a code which i have writen
Dim strData As String
       Try
           strData = serialport.ReadTo(Chr(&HA))
           If (strData.Length > 0) Then
               MsgBox("Drive returned data before initial LF:" & _
                   vbNewLine & strData) 'This should be empty. always.
           End If
       Catch ex As Exception
           MsgBox("Coud not read to initial LF: " & vbNewLine & ex.Message)
       End Try

       ' Now read and trim the CR LF from the remaining data.
       strData = serialport.ReadExisting()
       If (strData.Length > 0) Then
           Try
               strData = strData.Substring(0, strData.Length - 2)
           Catch ex As Exception
               MsgBox("Serial data out of sync." & vbNewLine & vbNewLine _
                   & strData)
           End Try
       End If

       Return strData


as soon as readline() or read() is being debuged the whole program is getng hanged and am terminating it directly.
plz help whats the problem in code.if this is to be changed what shud i implement to receive data from hardware
Posted
Updated 9-May-12 18:08pm
v2
Comments
   
Please stop re-posting. This is the question #3 on the same topic. As this one is more detailed, I'll remove the first one.

Look here, everyone:
http://www.codeproject.com/Questions/381776/very-urgent-need-sample-code-in-visual-basic

What is that? Same person? Same school? It's a shame.

--SA
Member 8953399 10-May-12 1:11am
   
mind k
Sergey Alexandrovich Kryukov 10-May-12 19:11pm
   
Huh?
--SA

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

What are you doing? MessageBox is a blocking call, how can you mix it with communications? Generally, the communication APIs are also based on some blocking calls, so in a real-life code they can be executed in a separate thread. To start development, start with a simple console application.

The second thing is: nothing really hangs. Your read operation is a blocking call. When you finish your ReadTo depends on what happens on the opposite end of your RS-232 cable. Who knows what do you have there?

—SA
   
Comments
Member 8953399 9-May-12 23:57pm
   
....
this is code that i used to sent hex data & i have no problems in that.if u can help then give a sample code that i can get idea how do i write code to receive data

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100