//int SavaLeng = 0; public bool SaveTxt(string sFileName, byte[] sContent, Int32 slength, int cc) { try { if (!System.IO.File.Exists(sFileName))//如果不存在则创建文件 { FileStream fs; fs = File.Create(sFileName); fs.Close(); } FileStream fsTxtWrite = new FileStream(sFileName, FileMode.Append); fsTxtWrite.Write(sContent, 0, slength); //SavaLeng+=slength; fsTxtWrite.Close(); //MessageBox.Show(slength.ToString() +":s-2:" +sContent[slength - 2].ToString() +" s-1:" +sContent[slength - 1].ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); } if (sContent[slength - 4] == 0x0d && sContent[slength - 3] == 0x0a) { MessageBox.Show("一个文件接收完成." + ccflag); ccflag = 0; FileStream rs = File.Open(sFileName, FileMode.Open); ushort nso_num = (ushort)(rs.Length / 4); byte[] readtmp = new byte[nso_num * 4]; rs.Read(readtmp, 0, nso_num * 4); rs.Close(); UInt16 a = CRC16.Get_Crc16(readtmp, nso_num * 4 - 4); // MessageBox.Show(Convert.ToString(nso_num * 4)); if (a == (sContent[slength - 2] << 8 | sContent[slength - 1])) { FlagConverter[cc] = true; //转换成sgy if (SGY_Change.Change(sFileName, SGYDataFolder + "\\" + SaveTime[cc] + ".sgy"))//保存的sgy格式数据//取原始数据 { MessageBox.Show("通道" + cc + "转换完成."); } else { MessageBox.Show("通道" + cc + "转换失败."); } MessageBox.Show("完成CRC验证——无错."); } else { FlagConverter[cc] = false; MessageBox.Show("完成CRC验证——出错."); } return(true); } else { return(false); } }
private void button1_Click(object sender, EventArgs e) { foreach (int conn in dictsocket.Keys) { if (SGY_Change.Change(OriginalDataFolder + "\\" + SaveTime[conn] + "." + conn, //取原始数据 SGYDataFolder + "\\" + SaveTime[conn] + ".sgy")) //保存的sgy格式数据 { MessageBox.Show("通道" + conn + "转换完成."); } else { MessageBox.Show("通道" + conn + "转换失败."); } } }