Solved

data received event - no data returned

Posted on 2014-03-14
2
375 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with another query 10 54
How to call new form in VB2013? 4 35
Datagridview column resizing 8 28
Click print button programmatically on print showdialog 1 24
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

734 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