[C#] SerialPort 1 ~ 超精簡版
1. 先拉版面CharConvert.rar
2. 從 ToolBox 拉 SerialPort 放到Form , 設定 BaudRate 57600
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;
namespace SerialPort1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string input;
private void btnOpen_Click(object sender, EventArgs e)
{
serialPort1.Open(); //開啟Com 1
if (serialPort1.IsOpen) //判斷Com 1 是否有開啟成功
{
tbxRecv.Text += serialPort1.PortName + "Open Success!\n"; //成功開啟訊息
}
}
private void btnRecv_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen) //判斷Com 1 是否有開啟成功
{
input = serialPort1.ReadExisting(); //從Com 1 讀出資料, 傳到 input 裡
tbxRecv.Text += input + "\n"; //印出 資料, 並換行
}
}
}
}