Serial port, continuously receiving data

milosh

Active member
Joined
May 11, 2011
Messages
33
Programming Experience
1-3
Hi all!

I have serial port object which continuously receiving data from weighing device, which sends data in 0001450= format (8 Bytes). I read about datareceived event, and implement that, but i must use Thred.Sleep to get all data and read with serial.ReadExisting. Does the ReadBytesTreshold=8 raised DataReceived event after 8 bytes of data???

Is there any way to cancel, abort, stop DataReceived event?

Thanks and sorry for bad English :)
 
Stop how, what is meant by this? Do you have code you just wish to not run until the data is completely finished receiving something like this may work:

    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        If e.EventType = IO.Ports.SerialData.Eof Then
            'this is the end of the serial data
        ElseIf e.EventType = IO.Ports.SerialData.Chars Then

        End If
    End Sub
 
Last edited:
Thanks for reply.
I tried this code but didn't help me. Because port continously receiving data from display, sometimes happend when I tried to close main form which create thread for serial port (dataReceived event), the whole application freezes. And I must to go to task manager to kill process...I think that form try to close but serial port thread can't because there is data in processing (receiving).
So, I think if there some way to kill thread of serial port when closing main form.
 
Thanks for help...I found solution.
Use BeginInvoke instead Invoke and DiscardInBuffer before close statement.

Best regards
 
Back
Top