C# 串口

来源:互联网 发布:新东方雅思词汇知乎 编辑:程序博客网 时间:2024/06/05 17:17
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");        }    }}
0 0
原创粉丝点击