Solved

data received event - no data returned

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This article will show, step by step, how to integrate R code into a R Sweave document
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now