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;
using System.Threading;
using Microsoft.Win32;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
static string[] portName = SerialPort.GetPortNames();
static int baudRate = 115200;
static Parity parity = Parity.None;
static int dataBits = 8;
static StopBits stopBits = StopBits.One;
static SerialPort _serialPort = new SerialPort(portName[1], baudRate, parity, dataBits, stopBits);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (!(_serialPort.IsOpen))
{
MessageBox.Show("_serialPort.Open();");
_serialPort.Open();
}
_serialPort.WriteLine("Ryantest01");
}
}
}
C# 串口
最新推荐文章于 2025-06-14 14:19:05 发布