Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO.Ports;
  11.  
  12. namespace RFID_Transfer_Final
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         SerialPort myport;
  17.         string data_rx;
  18.         bool start = false;
  19.         Timer t = new Timer();
  20.  
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.         }
  25.        
  26.         private void Form1_Load(object sender, EventArgs e)
  27.         {
  28.             t.Interval = 1000;
  29.             t.Tick += new EventHandler(timer1_Tick);
  30.         }
  31.  
  32.         private void timer1_Tick(object sender, EventArgs e)
  33.         {
  34.             while (start == true)
  35.             {
  36.                 myport = new SerialPort();
  37.                 myport.BaudRate = 9600;
  38.                 myport.PortName = "COM9";
  39.  
  40.  
  41.                 myport.Open();
  42.                 myport.DiscardInBuffer();
  43.                 myport.DiscardOutBuffer();
  44.  
  45.                 data_rx = myport.ReadLine();
  46.  
  47.                 myport.Close();
  48.  
  49.                 if (data_rx.Length == 9)
  50.                 {
  51.                     infoBox.Items.Add(data_rx);
  52.                 }
  53.             }
  54.         }
  55.  
  56.         private void RetrieveInfo_Click(object sender, EventArgs e)
  57.         {
  58.            
  59.             if (start == true)
  60.             {
  61.                 RetrieveInfo.Text = "Start";
  62.  
  63.                 t.Start();
  64.                 start = false;
  65.             }
  66.             else
  67.             {
  68.                 RetrieveInfo.Text = "Stop";
  69.  
  70.                 t.Stop();
  71.                 start = true;
  72.             }
  73.         }
  74.  
  75.        
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement