这个小工具是小弟两年前写的,代码可能有点稚嫩,但是原理以及机制依旧不变 ,原文发布在其他博客中.....
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.Collections;
namespace one
{
/// <summary>
/// 一个串口的例子
/// </summary>
public partial class Form1 : Form
{
Form from = new Form();
private string str = string.Empty;
private byte[] by;
public Form1()
{
InitializeComponent();
}
#region 加载本电脑上的串口
private void Form1_Load(object sender, EventArgs e)
{
button3.Enabled = true;
button4.Enabled = false;
comboBox2.Text = "9600";
string[] portList = System.IO.Ports.SerialPort.GetPortNames();
for (int i = 0; i < portList.Length; i++)
{
comboBox3.Items.Add(portList[i]);
comboBox1.Items.Add(portList[i]);
comboBox4_shou.Items.Add(portList[i]);
}
}
#endregion
/// <summary>
/// 将信息发送到该Com口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
byte[] b = new byte[10];
b = GEt();
write();
//MessageBox.Show(ByteArrayToHexString(Data).ToString());
}
#region 写入数据
public void write()
{
try
{
// serialPort1.PortNa