Solved

data received event - no data returned

Posted on 2014-03-14
2
370 Views
Last Modified: 2014-03-18
Serial port data received event is not being thrown.  I can send data out but not receiving.
I can send and receive through realterm.  Trying to interface with a commercial mettler toledo scale.
0
Comment
Question by:mikeplastic
2 Comments
 
LVL 1

Accepted Solution

by:
mastiSoft earned 500 total points
ID: 39933872
  If SendNow = True Then //send command to serial port
                    ' WRITE DATA TO DEVISES-
                    z = UBound(ByteArray)
                    SerialPort1.Write(ByteArray, 0, z)

                    ResivBytes = 0 'going to control amount of bytes we read from SP
                    System.Threading.Thread.Sleep(10)
                    SendNow = False
                End If

                bRead = 0

                If SerialPort1.IsOpen = True Then
                    'answer is here
                    'SerialPort1.BytesToRead 'Number of Bytes to read
                    bRead = SerialPort1.ReadByte()

                    If bRead > 0 Then 'there is some bytes in buffer
                        Dim cData(bRead) As Byte
                        Label4.Text = Val(Label4.Text) + bRead
                        nRead = SerialPort1.Read(cData, 0, bRead)  'Reading the Data
                        '  ..................................................................
                        If chAscii.Checked = True Then
                            ascStr = ""

                            returnStr = ""
                            For Each b As Byte In cData
                                returnStr = returnStr & Chr(b)
                            Next
                            'lstReceive.Items.Add(returnStr)
                        End If
                        ' ..................................................................
                        If chAscii.Checked = False Then
                            returnStr = ""
                            ' controll if we get data in buffer
                            For Each b As Byte In cData
                                returnStr += Hex(b).PadLeft(2, "0")
                            Next

                            'lstReceive.Items.Add(returnStr)

                        End If
                    End If
                End If

Open in new window



In background one loop waiting for command and as soon as command was send SP start read the answer. Hope it helps.
0
 

Author Closing Comment

by:mikeplastic
ID: 39936788
Very helpful - this was a great answer.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about a problem I had getting the GPS LocationListener working.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question