Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

data received event - no data returned

Posted on 2014-03-14
2
Medium Priority
?
391 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

886 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