Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.IO.Ports;
  16.  
  17. namespace R_SCORING
  18. {
  19. /// <summary>
  20. /// Interaction logic for MainWindow.xaml
  21. /// </summary>
  22. public partial class MainWindow : Window
  23. {
  24. struct StrukturaCzujnikow
  25. {
  26. public StrukturaCzujnikow(int czujnik1, int czujnik2, int czujnik3, int czujnik4, int czujnik5, int czujnik6, int czujnik7, int czujnik8, int czujnik9, int czujnik10)
  27. {
  28. Czujnik1 = czujnik1;
  29. Czujnik2 = czujnik2;
  30. Czujnik3 = czujnik3;
  31. Czujnik4 = czujnik4;
  32. Czujnik5 = czujnik5;
  33. Czujnik6 = czujnik6;
  34. Czujnik7 = czujnik7;
  35. Czujnik8 = czujnik8;
  36. Czujnik9 = czujnik9;
  37. Czujnik10 = czujnik10;
  38.  
  39. }
  40.  
  41. public int Czujnik1;
  42. public int Czujnik2;
  43. public int Czujnik3;
  44. public int Czujnik4;
  45. public int Czujnik5;
  46. public int Czujnik6;
  47. public int Czujnik7;
  48. public int Czujnik8;
  49. public int Czujnik9;
  50. public int Czujnik10;
  51. }
  52.  
  53. SerialPort PortUsb = new SerialPort();
  54.  
  55. public MainWindow()
  56. {
  57. InitializeComponent();
  58. InitializeComponent();
  59. PoloczenieSerialPortu();
  60. }
  61.  
  62. private void PoloczenieSerialPortu()
  63. {
  64. PortUsb.PortName = "COM10";
  65. PortUsb.BaudRate = 115200;
  66. PortUsb.Handshake = Handshake.None;
  67. PortUsb.Parity = Parity.None;
  68. PortUsb.DataBits = 8;
  69. PortUsb.StopBits = StopBits.One;
  70. PortUsb.RtsEnable = true;
  71. PortUsb.DtrEnable = true;
  72.  
  73. //PortUsb.ReadTimeout = 200;
  74. //PortUsb.WriteTimeout = 50;
  75.  
  76.  
  77. PortUsb.DataReceived += new SerialDataReceivedEventHandler(ReadByteByByte);
  78. PortUsb.Open();
  79. }
  80.  
  81. private void ReadByteByByte(object sender, SerialDataReceivedEventArgs e)
  82. {
  83. if (!PortUsb.IsOpen) return;
  84. int bytes = PortUsb.BytesToRead;
  85. byte[] buffer = new byte[bytes];
  86. PortUsb.Read(buffer, 0, bytes);
  87. HandleSerialData(buffer);
  88. PortUsb.Close();
  89. }
  90.  
  91. public void HandleSerialData(byte[] buffer)
  92. {
  93.  
  94. byte[] allBufferData = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a };
  95.  
  96.  
  97. }
  98.  
  99. private void CopyToStruct()
  100. {
  101.  
  102.  
  103.  
  104. }
  105. }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement