Guest User

Untitled

a guest
Feb 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. using GHIElectronics.TinyCLR.Devices.Can;
  2. using GHIElectronics.TinyCLR.Devices.SerialCommunication;
  3. using GHIElectronics.TinyCLR.Pins;
  4. using GHIElectronics.TinyCLR.Storage.Streams;
  5. using System.Reflection;
  6.  
  7. namespace TinyCLRApplication1 {
  8. public class Size {
  9. private static object[] empty = new object[0];
  10. private readonly object provider;
  11. private readonly MethodInfo getReadBufferSize;
  12. private readonly MethodInfo setReadBufferSize;
  13. private readonly MethodInfo getWriteBufferSize;
  14. private readonly MethodInfo setWriteBufferSize;
  15.  
  16. public Size(object controller, string fieldName) {
  17. this.provider = controller.GetType().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance).GetValue(controller);
  18.  
  19. var type = this.provider.GetType();
  20.  
  21. this.getReadBufferSize = type.GetMethod("get_ReadBufferSize", BindingFlags.Public | BindingFlags.Instance);
  22. this.setReadBufferSize = type.GetMethod("set_ReadBufferSize", BindingFlags.Public | BindingFlags.Instance);
  23. this.getWriteBufferSize = type.GetMethod("get_WriteBufferSize", BindingFlags.Public | BindingFlags.Instance);
  24. this.setWriteBufferSize = type.GetMethod("set_WriteBufferSize", BindingFlags.Public | BindingFlags.Instance);
  25. }
  26.  
  27. public uint ReadBufferSize {
  28. get => (uint)this.getReadBufferSize.Invoke(this.provider, Size.empty);
  29. set => this.setReadBufferSize.Invoke(this.provider, new object[] { value });
  30. }
  31.  
  32. public uint WriteBufferSize {
  33. get => (uint)this.getWriteBufferSize.Invoke(this.provider, Size.empty);
  34. set => this.setWriteBufferSize.Invoke(this.provider, new object[] { value });
  35. }
  36. }
  37.  
  38. public class Program {
  39. static void Main() {
  40. var can = CanController.FromId(G80.CanBus.Can1);
  41. var canSize = new Size(can, "provider");
  42. can.SetBitTiming(new CanBitTiming(1, 1, 1, 1, 1, false));
  43. var ser = SerialDevice.FromId(G80.UartPort.Usart1);
  44. var serSize = new Size(ser, "stream");
  45. ser.OutputStream.Write(new Buffer(1));
  46.  
  47. canSize.ReadBufferSize = 256;
  48. serSize.ReadBufferSize = 4096;
  49. }
  50. }
  51. }
Add Comment
Please, Sign In to add comment