TinyCLR Documentation Web Example

Just stumbled on this trying to find something else, but it sort of stood out as a Whha copy & paste buffer over-run typo?

[https://docs.ghielectronics.com/software/tinyclr/tutorials/uart.html](http://UART Tutoral from Documentation site)

I think I have a fork of the doco’s already, I’ll do a PR if I have, just for fun!

using System.Diagnostics;
using System.Text;
using System.Threading;
using GHIElectronics.TinyCLR.Devices.Uart;
using GHIElectronics.TinyCLR.Pins;

class Program {
    private static void Main() {
        var txBuffer = new byte[] { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 };    //A, B, C, D, E, F
>       var rxBuffer = new byte[txBuffer.Length];

        var myUart = UartController.FromName(FEZ.UartPort.Usart1);

        myUart.SetActiveSettings(9600, 8, UartParity.None, UartStopBitCount.One, UartHandshake.None);
        myUart.Enable();
        myUart.Write(txBuffer, 0, txBuffer.Length);

        while (true) {
            if (myUart.BytesToRead > 0) {
>               var bytesReceived = myUart.Read(rxBuffer, 0, myUart.BytesToRead);
                Debug.WriteLine(Encoding.UTF8.GetString(rxBuffer, 0, bytesReceived));
            }
            Thread.Sleep(20);
        }
    }
}

Ahh OK sorry!! My mistake!

(See I dont read doco’s!) I just looked at the code only!

It does say this if for a Loop-Back test. So bytes TX’d will be received.
But… I don’t know, for a newbie…, I think this has some code smells to it?

1 Like