This module provides interrupt driven RS232 buffering.
Start buffering incoming data.
Stop buffering incoming data.
Function DataAvailable() As Boolean
Checks to see if there is any data in the input buffer. Returns true if data present, false otherwise.
Function ReadByte() As Byte
Read a single byte from the input buffer. A call to DataAvailable() should be made before making this call to ensure that data is present in the input buffer.
Function ReadString(ByRef text As String) As Byte
- text - String variable to receive the data.
Read a string from the buffer. The function returns the number of bytes read. The routine expects the string to have a null terminator.
Reset the module. A call to Halt() should be made before making a call to this routine.
Event OnData(ByRef data As Byte, ByRef accept As Boolean)
- data - Input byte that is about to be placed into the buffer.
- accept - This flag should be set to false to indicate that the data byte should not be added to the buffer. By default it is true.
An event which enables incoming data to be changed or to prevent incoming data from being added to the buffer. See the program at the bottom of the page for a working example. This event is fired from the main interrupt handling routine. It is advised that the handler returns as soon as possible and that no calls are made to any other function or subroutine when the handler is executing.
An event which is fired when the input buffer becomes full. This event is fired from the main interrupt handling routine. It is advised that the handler returns as soon as possible and that no calls are made to any other function or subroutine when the handler is executing.
' imports... imports UartBuffer imports Uart ' this event handler is triggered when data is received - it gives ' the program the opportunity to accept or reject the incoming byte ' or modify the data in some way - this example changes all space ' characters to underscore... Sub OnData(ByRef Data As Byte, ByRef Accept As Boolean) Handles RX.OnData Dim DataIn As Byte = Data If DataIn = CByte(" ") Then Data = "_" End If End Sub ' this event is fired if the RX buffer overruns... Sub OnOverrun () Handles RX.OnOverrun High(PORTB.15) End Sub ' main program... Sub Main() UART.SetBaudrate(UART.Baudrate.Is38400) ' set baudrate RX.Start() ' start buffering data ' loop forever to prevent program ' from terminating... While True If RX.DataAvailable() Then ' if data is available Console.Write(RX.ReadByte()) ' then echo back End If End While End Sub