Guest User

Untitled

a guest
Feb 19th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using System.IO.Ports;
  4. using System.Text;
  5. using Microsoft.SPOT;
  6. using Microsoft.SPOT.Hardware;
  7. using GHIElectronics.NETMF.Hardware;
  8.  
  9.  
  10. namespace MFConsoleApplication1
  11. {
  12.    
  13.     public class Program
  14.     {
  15.         private static byte[] rx_byte = new byte[1000];
  16.         public static void Main()
  17.         {
  18.            
  19.  
  20.             SerialPort UART = new SerialPort("COM2");
  21.             UART.BaudRate = 115200;
  22.             UART.Parity = Parity.None;
  23.             UART.StopBits = StopBits.One;
  24.             UART.DataBits = 8;
  25.             UART.Handshake = Handshake.None;
  26.  
  27.            
  28.             UART.Open();
  29.                
  30.                 UART.DataReceived += new SerialDataReceivedEventHandler(DataReceviedHandler);
  31.  
  32.  
  33.              while (true)
  34.             {
  35.              Thread.Sleep(10);
  36.             }
  37.         }
  38.  
  39.         private static void DataReceviedHandler(object sender, SerialDataReceivedEventArgs e)
  40.         {
  41.            
  42.             SerialPort UART = (SerialPort)sender;
  43.  
  44.      
  45.            UART.Read(rx_byte, 0, rx_byte.Length);
  46.    
  47.            Debug.Print(rx_byte[0].ToString());
  48.  
  49.            
  50.         }
  51.        
  52.  
  53.  
  54.     }
  55. }
Add Comment
Please, Sign In to add comment