Guest User

Untitled

a guest
Jan 19th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Collections;
  4. using System.Text;
  5. using System.Threading;
  6. using GHIElectronics.TinyCLR.Storage.Streams;
  7. using GHIElectronics.TinyCLR.Devices.SerialCommunication;
  8. using GHIElectronics.TinyCLR.Pins;
  9.  
  10. namespace g400uart
  11. {
  12. class Program
  13. {
  14. static DataReader UartA_ReadStream;
  15. static DataWriter UartA_WriteStream;
  16.  
  17. static void Main()
  18. {
  19. byte ReadBuffer = 0;
  20. //SerialDevice UartA = SerialDevice.FromId(FEZ.UartPort.Usart1);
  21. SerialDevice UartA = SerialDevice.FromId(G400D.UartPort.Usart1);
  22. UartA.BaudRate = 115200;
  23. UartA.ReadTimeout = TimeSpan.Zero;
  24. UartA_ReadStream = new DataReader(UartA.InputStream);
  25. UartA_WriteStream = new DataWriter(UartA.OutputStream);
  26.  
  27. UartA_WriteStream.WriteString("I am UART A!");
  28. UartA_WriteStream.Store();
  29.  
  30. while (ReadBuffer != 0x5A)
  31. {
  32. if (UartA_ReadStream.Load(1) > 0)
  33. {
  34. ReadBuffer = UartA_ReadStream.ReadByte();
  35. Debug.WriteLine("Received: " + ReadBuffer);
  36. UartA_WriteStream.WriteByte(ReadBuffer);
  37. UartA_WriteStream.Store();
  38. }
  39. Thread.Sleep(10);
  40. }
  41. }
  42. }
  43. }
Add Comment
Please, Sign In to add comment