daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Mar 25th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 testBuild
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         string dataOUT;
  17.  
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void Form1_Load(object sender, EventArgs e)
  24.         {
  25.             string[] ports = SerialPort.GetPortNames();
  26.             cBoxCOMPORT.Items.AddRange(ports);
  27.         }
  28.  
  29.         private void btnOpen_Click(object sender, EventArgs e)
  30.         {
  31.             try
  32.             {
  33.                 serialPort1.PortName = cBoxCOMPORT.Text;
  34.                 serialPort1.BaudRate = Convert.ToInt32(CBoxBaudRate.Text);
  35.                 serialPort1.DataBits = Convert.ToInt32(cBoxDataBits.Text);
  36.                 serialPort1.StopBits = (StopBits)Enum.Parse(typeof(StopBits), cBoxStopBits.Text);
  37.                 serialPort1.Parity = (Parity)Enum.Parse(typeof(Parity), cBoxParityBits.Text);
  38.  
  39.                 serialPort1.Open();
  40.                 progressBar1.Value = 100;
  41.             }
  42.  
  43.             catch (Exception err)
  44.             {
  45.                 MessageBox.Show(err.Message,"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  46.             }
  47.         }
  48.  
  49.         private void btnClose_Click(object sender, EventArgs e)
  50.         {
  51.             if(serialPort1.IsOpen)
  52.             {
  53.                 serialPort1.Close();
  54.                 progressBar1.Value = 0;
  55.             }
  56.         }
  57.  
  58.         private void btnSendData_Click(object sender, EventArgs e)
  59.         {
  60.             if(serialPort1.IsOpen)
  61.             {
  62.                 dataOUT = tBoxDataOut.Text;
  63.                 serialPort1.Write(dataOUT);
  64.             }
  65.         }
  66.     }
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top