Solved

data received event - no data returned

Posted on 2014-03-14
2
378 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …
Introduction to Processes

617 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