界面的布局:
需要注意的是在波特率的下来框中要设置选择的参数列表,可以通过下面截图的方式添加:
实现的源代码如下,注意;:控件的名字编号,要根据自己的界面布局做出修改。这里主要是实现串口控件的使用和基本的逻辑思路。
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.Runtime.InteropServices;//DllImport是System.Runtime.InteropServices命名空间下的一个属性类,其功能是提供从非托管DLL导出的函数的必要调用信息。
namespace comport1
{
public partial class Form1 : Form
{
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filepath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filepath);
string FileN