using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace SerialPortExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
foreach (string s in System.IO.Ports.SerialPort.GetPortNames())
{
listBox1.Items.Add(s);
serialPort1.Open();
}
}
private void button1_Click(object sender, EventArgs e)
{
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
try
{
textBox1.Text = serialPort1.ReadExisting();
textBox1.Text = serialPort1.ReadLine().ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
No comments:
Post a Comment