找传奇、传世资源到传世资源站!

C#串口通讯实例

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

C#串口通讯实例
from clipboard
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;using System.IO.Ports; namespace ComDemo{    public partial class ComSet : Form    {        public ComSet()        {            InitializeComponent();        }         private void ComSet_Load(object sender, EventArgs e)        {            //串口            string[] ports = SerialPort.GetPortNames();            foreach (string port in ports)            {                cmbPort.Items.Add(port);            }            cmbPort.SelectedIndex = 0;             //波特率            cmbBaudRate.Items.Add("110");            cmbBaudRate.Items.Add("300");            cmbBaudRate.Items.Add("1200");            cmbBaudRate.Items.Add("2400");            cmbBaudRate.Items.Add("4800");            cmbBaudRate.Items.Add("9600");            cmbBaudRate.Items.Add("19200");            cmbBaudRate.Items.Add("38400");            cmbBaudRate.Items.Add("57600");            cmbBaudRate.Items.Add("115200");            cmbBaudRate.Items.Add("230400");            cmbBaudRate.Items.Add("460800");            cmbBaudRate.Items.Add("921600");            cmbBaudRate.SelectedIndex = 5;             //数据位            cmbDataBits.Items.Add("5");            cmbDataBits.Items.Add("6");            cmbDataBits.Items.Add("7");            cmbDataBits.Items.Add("8");            cmbDataBits.SelectedIndex = 3;             //停止位            cmbStopBit.Items.Add("1");            cmbStopBit.SelectedIndex = 0;             //佼验位            cmbParity.Items.Add("无");            cmbParity.SelectedIndex = 0;        }         private void bntOK_Click(object sender, EventArgs e)        {            //以下4个参数都是从窗体MainForm传入的            MainForm.strProtName = cmbPort.Text;            MainForm.strBaudRate = cmbBaudRate.Text;            MainForm.strDataBits = cmbDataBits.Text;            MainForm.strStopBits = cmbStopBit.Text;            DialogResult = DialogResult.OK;        }         private void bntCancel_Click(object sender, EventArgs e)        {            DialogResult = DialogResult.Cancel;        }    }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复