8 Replies - 4126 Views - Last Post: 03 November 2011 - 05:57 AM Rate Topic: -----

#1 iceb0x  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-November 11

read from serial port and parse received data on event serialdata.eof

Posted 02 November 2011 - 11:58 PM

Hi everyone!

I'm having trouble with parsing an XML data from serial port.
Actually I need to parse it automatically after all data is received from serial port.

I can display all the data in a richtextbox control and all data is received perfectly but my problem is
it seems that serialdata.eof function seems like it's not firing.
any advice will be much appreciated!

here's some of my code:


    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'set serial port properties
        With COMPort
            .BaudRate = 19200
            .Parity = Ports.Parity.None
            .DataBits = 8
            .StopBits = Ports.StopBits.One
            .PortName = COM1
        End With

        txtMonitor.BackColor = Color.Black
        txtMonitor.ForeColor = Color.White
        txtMonitor.Text = ""

        AddHandler COMPort.DataReceived, AddressOf Receiver
    End Sub

    Private Sub Receiver(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)

        Dim Incoming As String
        Dim sp As SerialPort = CType(sender, SerialPort)
        counter = COMPort.BytesToRead
        Select Case e.EventType
            Case SerialData.Chars
                Incoming = sp.ReadLine()
                returnStr &= Incoming
                Me.Invoke(New MethodInvoker(AddressOf Display))
            Case SerialData.Eof
                Me.Invoke(New MethodInvoker(AddressOf parseXML))
        End Select

    End Sub

    Private Sub Display()
        txtMonitor.Text = returnStr
    End Sub
    
    Private Sub parseXML()

        Dim sr As New StringReader(returnStr)
        Dim doc As New XmlDocument
        Dim m_nodelist As XmlNodeList
        Dim m_node As XmlNode

        doc.Load(sr)
     
        '...and so on....
     End Sub




what i need to know is how can i automatically parse the XML data from serial port after all data is received.

Is This A Good Question/Topic? 0
  • +

Replies To: read from serial port and parse received data on event serialdata.eof

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: read from serial port and parse received data on event serialdata.eof

Posted 03 November 2011 - 12:15 AM

What about this link:
http://bytes.com/top...l-string-vb-net
http://bytes.com/top...ml-using-vb-net

J-Bo
Was This Post Helpful? 0
  • +
  • -

#3 iceb0x  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-November 11

Re: read from serial port and parse received data on event serialdata.eof

Posted 03 November 2011 - 01:27 AM

by the way, just wanna make it clear.
I already know how to do the parsing, i just need to automate it after all data has been received.
thanks!
Was This Post Helpful? 0
  • +
  • -

#4 iceb0x  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-November 11

Re: read from serial port and parse received data on event serialdata.eof

Posted 03 November 2011 - 01:38 AM

thanks for those jimmyBo but those were not i am looking for.. :sweatdrop: :bigsmile: it was my statement that wasn't clear..

again for those who want to give a hand and help me figure this problem out, i just need to call the sub/function that will parse the serial data after all data from serial port was received.. thanks in advance.
Was This Post Helpful? 0
  • +
  • -

#5 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: read from serial port and parse received data on event serialdata.eof

Posted 03 November 2011 - 01:53 AM

Add a timer to your form. Then in the Receiver Sub add this:
timer1.stop
timer1.interval = 500
Timer1.Start


The timer is for checking the delay between received data. If it elapses 500 milliseconds then it will assume there is no more data coming
add this to your Timer_Tick event:
'run sub to parse xml


That's all I can think of ATM.
Was This Post Helpful? 0
  • +
  • -

#6 iceb0x  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-November 11

Re: read from serial port and parse received data on event serialdata.eof

Posted 03 November 2011 - 01:59 AM

@jimmyBo ill try that one later.. thanks a lot. i'll leave a comment if it will work for me..

i just don't understand why event serialdata.eof is not working..
Was This Post Helpful? 0
  • +
  • -

#7 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: read from serial port and parse received data on event serialdata.eof

Posted 03 November 2011 - 02:05 AM

Cool.
What errors are you having with the event?

Oh hang on, I see! Move your AddHandler statement to inside the With...End With you have.
also are you using the event signatures right?
Is eof A Boolean? Try putting = False or = True after Case Eof.
J-Bo
Was This Post Helpful? 0
  • +
  • -

#8 dbasnett  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 608
  • Joined: 01-October 08

Re: read from serial port and parse received data on event serialdata.eof

Posted 03 November 2011 - 05:48 AM

View Posticeb0x, on 03 November 2011 - 03:59 AM, said:

@jimmyBo ill try that one later.. thanks a lot. i'll leave a comment if it will work for me..

i just don't understand why event serialdata.eof is not working..


It was deprecated some time ago I believe. You will need to check the incoming data for the end manually.
Was This Post Helpful? 0
  • +
  • -

#9 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1525
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: read from serial port and parse received data on event serialdata.eof

Posted 03 November 2011 - 05:57 AM

Is it possible to set the end of transmission character for the serial device? Sometimes you can set the character that the device will send at the end of the transmission. If you can get it to do that, then you simply check for that character.

When you read all of the data, check to see what the end character is. Maybe it's already something unique(that wouldn't come in normal data).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1