public static void Intconfig() { config_Path = FunComm.GetStartupPath() + "数据文件\\"; config_file_name = "config.txt"; if (!Directory.Exists(config_Path)) //不存在文件夹则创建 { Directory.CreateDirectory(config_Path); FileStream configfile = new FileStream(config_Path + config_file_name, FileMode.Create); configfile.Close(); //初始化config信息 string config_str = "串口号" + "," + "波特率" + "," + "数据位" + "," + "校验位" + "," + "停止位" + "," + "窗口号" + "," + "文件路径" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str); string config_str1 = "COM1" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str1); string config_str2 = "COM2" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str2); string config_str3 = "COM3" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str3); string config_str4 = "COM4" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str4); string config_str5 = "COM5" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str5); string config_str6 = "COM6" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str6); string config_str7 = "COM7" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str7); string config_str8 = "COM8" + "," + "B9600" + "," + "BIT_8" + "," + "None" + "," + "Stop_1" + "," + "0" + "," + "" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str8); string config_str9 = "10.126.1.192" + "," + "9000" + "," + "qdsb422" + "," + "qdsb422" + "," + "127.0.0.1" + "," + "0x84" + "," + "0x64" + "\r\n"; File.AppendAllText(config_Path + config_file_name, config_str9); } }
//读取初始化信息 public static void IntCOM() { config_Path = FunComm.GetStartupPath() + "数据文件\\"; config_file_name = "config.txt"; if (Directory.Exists(config_Path)) //存在文件夹则初始化串口 { string[] config = File.ReadAllLines(FunComm.config_Path + FunComm.config_file_name); for (int i = 1; i < config.Length - 1; i++) { string[] config_i = config[i].Split(','); if (config_i.Length > 0)//有内容 { Readconfig(config_i, i); } //if (config_i.Length ==1)//有内容 //{ // Readcom(config_i,i); //} } string[] config_tcp = config[config.Length - 1].Split(','); Readtcp(config_tcp, config.Length - 1); } }