public SerialCommunicationViewModel(SerialMessageProcessor prcessor) { MessageProcessor = prcessor; // for debugging _selectedPortName = PortList.FirstOrDefault(); }
//判断文件是否存在,以及坐标偏移 private void FileExsits(string path, int offert, string Block, int RBFlag) { string tmpStr = string.Empty; string FilePath = string.Empty; PathAndOffert temp = new PathAndOffert(null, null, null, null, offert, 1, 0); string[] FileName = path.Split(','); //FileName[0]必定是文件夹的名字 string[] Blocks = Block.Split(','); if (!Directory.Exists(FileName[0])) //判断文件夹是否存在,没有则新建 { Directory.CreateDirectory(FileName[0]); } if (Blocks.Count() != FileName.Count() - 1)//OutPath中的逗号数目比Block中的多1个 { throw new Exception("ReadPage 中Block和plane数应该和数据路径对应!!!"); } if (FileName.Count() == 2)//单plane { tmpStr = FileName[0] + @"/" + FileName[1]; temp.FilePath[0] = tmpStr; temp.PlaneNum = 1; } else if (FileName.Count() == 3)//两个Plane { tmpStr = FileName[0] + @"/" + FileName[1]; temp.FilePath[0] = tmpStr; tmpStr = FileName[0] + @"/" + FileName[2]; temp.FilePath[1] = tmpStr; temp.PlaneNum = 2; } else if (FileName.Count() == 5)//4个Plane { tmpStr = FileName[0] + @"/" + FileName[1]; temp.FilePath[0] = tmpStr; tmpStr = FileName[0] + @"/" + FileName[2]; temp.FilePath[1] = tmpStr; tmpStr = FileName[0] + @"/" + FileName[3]; temp.FilePath[2] = tmpStr; tmpStr = FileName[0] + @"/" + FileName[4]; temp.FilePath[3] = tmpStr; temp.PlaneNum = 4; } else { throw new Exception("ReadPage 路径格式错误!!!"); } if (RBFlag == 1)//如果统计R/B#拉低时间,则新建一个csv文件 { try { FileStream stream = new FileStream(FileName[0] + @"/" + @"R/B_Falling_Duration.csv", FileMode.Create, FileAccess.Write); stream.Close(); } catch { throw new Exception("R/B统计表格创建失败!"); } } if (PortList.Keys.Count == 1) { string name = PortList.FirstOrDefault().Key; if (!ComDataPath.Keys.Contains(name)) { List <PathAndOffert> tmpList = new List <PathAndOffert>(); ComDataPath.Add(name, tmpList); } for (int i = 0; i < temp.PlaneNum; i++) { try { //temp.FilePath[i] += ".bin"; if (!File.Exists(temp.FilePath[i])) { //File.Create(temp.FilePath[i]).Dispose(); FileStream stream = new FileStream(temp.FilePath[i], FileMode.Create, FileAccess.Write); stream.Close(); } } catch { throw new Exception("文件路径不正确!!!"); } } ComDataPath[name].Add(temp); } else { foreach (string name in PortList.Keys) { PathAndOffert Privious = temp; temp = Privious; if (!ComDataPath.Keys.Contains(name)) { List <PathAndOffert> tmpList = new List <PathAndOffert>(); ComDataPath.Add(name, tmpList); } for (int i = 0; i < Privious.PlaneNum; i++) { temp.FilePath[i] += name; if (!File.Exists(temp.FilePath[i])) { //File.Create(temp.FilePath[i]).Dispose(); FileStream stream = new FileStream(temp.FilePath[i], FileMode.Create, FileAccess.Write); stream.Close(); } } ComDataPath[name].Add(temp); } } }