using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
class Comm
{
public delegate void EventHandle(byte[] readBuffer); //定义委托
public event EventHandle DataReceived;//声明委托类型的变量
public SerialPort serialPort;//定义串口全局变量
Thread threadRead;//定义串口读取数据线程
Thread threadSend;//定义串口发送数据线程
volatile bool _keepReading;//读取数据线程运行标识(0:退出运行 1:允许运行)
volatile bool _keepSending;//发送数据线程运行标识(0:退出运行 1:允许运行)
byte[] bufSend;//发送数据数组
int offSetSend;//从发送数据数组中第几个数据开始发送
int countSend;//发送数据的长度
/// <summary>
/// 串口类构造函数
/// </summary>
public Comm()
{
serialPort = new SerialPort();
threadRead = null;
_keepReading = false;//读取数据线程运行标识(0:退出运行 1:允许运行)
threadSend = null;
_keepSending = false;//发送数据线程运行标识(0:退出运行 1:允许运行)
offSetSend = 0;
countSend = 0;//发送数据的长度
}
/// <summary>
/// 串口是否打开
/// </summary>
public bool IsOpen
{