Author Topic: I try to program some kind of UART-terminal in a class. But the Uart0Receive-event doesn't work in a  (Read 636 times)

rudydevolder

  • Newbie
  • *
  • Posts: 26
  • Belgian guy married Phillipina
  • Location: Philippines
    • View Profile
This is my sub-class:
Code: [Select]
Class UART_Debug
    Shared ser As Uart
    Shared Buffer As ListOfByte
   
    Public Sub New()
        //Lplan.SetMidPowerMode(2000)
        ser = Uart.Create(9600, Pin.Pin1, Pin.Pin0) // Pin 1 to Rxd and pin 0 to TxD; Dev-Board default jumper config
        ser.Write("DEBUG-TERMINAL started") ser.Write(13) ser.Write(10)
        Buffer = New ListOfByte
    End Sub
   
    //Shared Event Uart0Receive() Doesn't work in a class so I try to call this in the main-program but it doesn't work either.
    Public Sub UartReceive()
        Dim chr As Integer = ser.Read
        While chr >= 0
            If chr = 13 Then ' CR echo as CR/LF
                ser.Write(10)
                ParseBuffer()
            Else
                Buffer.AddByte(chr.ToByte)
            End If
            ser.Write(chr.ToByte)
            chr = ser.Read()
        End While
    End Sub
   
    Public Sub print(S As String)
        ser.Write(S)
    End Sub
   
    Public Sub println(S As String)
        ser.Write(S)
        ser.Write(13) ser.Write(10)
    End Sub
   
    Private Sub ParseBuffer()
        Dim S As String
        S = Buffer.ToString
        If S = "help" Then
            ser.Write("Wait I'm going to help you\n\r")
        End If
        Buffer.Clear
    End Sub
End Class

And this is my main-program:
Code: [Select]
Class UART_Terminal_v2
    Shared Terminal As UART_Debug
   
    Shared Event Boot()
        Lplan.SetMidPowerMode(2000)
        //Data = New ListOfObject()
        Terminal = New UART_Debug
    End Event
   
    Shared Event Uart0Receive()
        Terminal.UartReceive()
    End Event
   
    Shared Event Every15Seconds() RaiseEvent Every 15000 milliSeconds
       
        Terminal.println("Every 15 seconds")
       
    End Event
   
End Class

The message is printed every 15 seconds. But the Uart0Receive() Event isn't doing anything.  ???

Share on Facebook Share on Twitter


mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
You have define is as an event and not as an Sub

Shared Event Uart0Receive

End Event

rudydevolder

  • Newbie
  • *
  • Posts: 26
  • Belgian guy married Phillipina
  • Location: Philippines
    • View Profile
I did this at first, you can still see the original definition but I commented because it didn't work. If I put the whole routine in the main class it works. When I move it to the subclass it doesn't work any more, I wanted to make the source cleaner and making some kind of subclass so I can use this more,  so I thought to trick it by putting a event call in the main program and redirect it to the subclass, but even that doesn't do the job.

mc-John

  • Global Moderator
  • Full Member
  • *****
  • Posts: 212
    • View Profile
When you set a breakpoint at the line "Terminal.UartReceive()" does it get there?