for (int i = 0; i <count; i++) //根据选择的串口号数量创建对应数量的线程
{
thread = new Thread(new ParameterizedThreadStart(Run));
thread.Name = Convert.ToString(i);
thread.IsBackground = true; //将线程转为后台线程
thread.Start(GetPortNames[i]); //传入串口号
}
public void Run(object serialName)
{
ConnectParams[] comm =null;
sp1 = new SerialPort();
sp1.PortName = serialName.ToString();//设置串口名
sp1.BaudRate = 19200; //波特率
sp1.DataBits = 8; //数据位
sp1.StopBits = StopBits.One;//停止位
sp1.Parity = Parity.None; //校验位
sp1.DtrEnable = true;//准备就绪
sp1.RtsEnable = true;
sp1.ReadTimeout = 1000;//设置数据读取超时为1秒
DevType = "流量计";
var cnn = new ConnectParams();
cnn.portName = sp1.PortName;
cnn.ComStarte = starte;
DataTable dt = new Dat