Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO.Ports;
- namespace serialPort
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- string[] comPorts = SerialPort.GetPortNames();
- foreach(string port in comPorts)
- {
- comboBox1.Items.Add(port);
- }
- }
- private void connect_Click(object sender, EventArgs e)
- {
- try {
- serialPort1.PortName = comboBox1.SelectedItem.ToString();
- serialPort1.Open();
- }
- catch(Exception hata)
- {
- MessageBox.Show(hata.Message);
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- try
- {
- serialPort1.Close();
- }
- catch(Exception hata)
- {
- MessageBox.Show(hata.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement