您的位置:首页 > 编程语言 > C#

C# 串口

2016-05-25 13:43 381 查看
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# 串口