void serial_DataReceived(object sender, SerialDataReceivedEventArgs e) //Serial 받는 부분 { int intRecSize = serial.BytesToRead; if (intRecSize != 0) { try { for (int i = 0; i < serial.BytesToRead; i++) { RecvDataList.Add((Byte)serial.ReadByte()); } } catch { } } }
public void process_Soft() { for (;;) { if (RecvDataList.Count < 10) { continue; } int bufferlen = RecvDataList.Count; byte[] BtData = new byte[bufferlen]; RecvDataList.CopyTo(0, BtData, 0, bufferlen); // size 가 500mb 보다 클시 if (flag_save == true) { string ff = Save_Path + name + ".txt"; var info = new FileInfo(ff); if (info.Length >= 500000) // 변경할것 { file.Close(); name2 = Regex.Replace(name, @"[\d-]", string.Empty); file_num++; // file numbering name = name2 + Convert.ToString(file_num); file = new System.IO.StreamWriter(Save_Path + name + ".txt", append: true); // 저장 경로 } } if (flag_save == true) { for (int i = 0; i < bufferlen; i++) { file.WriteLine("{0}", BtData[i]); } } RecvDataList.RemoveRange(0, bufferlen); } }
public void processMain() { for (;;) { if (RecvDataList.Count < 70) { continue; } if (!(RecvDataList[0] == 0xFF && RecvDataList[1] == 0xFF)) //FF, FF 확인 { RecvDataList.RemoveRange(0, 1); //FF, FF전 데이터삭제 continue; } else if (RecvDataList[0] == 0xFF && RecvDataList[1] == 0xFF) { if (RecvDataList[bufferlength - 2] == 0xFF && RecvDataList[bufferlength - 1] == 0xFE) //FF, FE 확인 { RecvDataList.CopyTo(0, Rec_Check, 0, bufferlength); byte[] crc_cal = new byte[bufferlength - 6]; Array.Copy(Rec_Check, 2, crc_cal, 0, bufferlength - 6); Crc = crc.ComputeHash(crc_cal); if (Crc[Crc.Length - 2] != Rec_Check[66] || Crc[Crc.Length - 1] != Rec_Check[67]) { RecvDataList.RemoveRange(0, bufferlength - 1); continue; } //data parse : for (int i = 0; i < 11; i++) { int k = 2 * i; Tempo_FSR[i] = (Rec_Check[2 + k] << 8) + Rec_Check[3 + k]; // TMR + FSR if (flag_save == true) { try { file.Write("{0}", Tempo_FSR[i]); file.Write(","); } catch {} } } //uwb hex to short // uwb 1 : range , power + uwb 2 : range , power for (int i = 0; i < 12; i++) { int k = 2 * i; Tempo_UWB[i] = (short)((Rec_Check[24 + k] << 8) + Rec_Check[25 + k]); // UWB if (flag_save == true) { try { file.Write("{0}", Tempo_UWB[i]); file.Write(","); } catch { } } } //Imu data int // uwb 1 : range , power + uwb 2 : range , power for (int i = 0; i < 9; i++) { int k = 2 * i; Tempo_IMU[i] = (Rec_Check[48 + k] << 8) + Rec_Check[49 + k]; // IMU if (flag_save == true) { try { file.Write("{0}", Tempo_IMU[i]); if (i == 8) { //file.Write(";"); file.Write("\n"); } else { file.Write(","); } } catch { } } } try { RecvDataList.RemoveRange(0, bufferlength - 1); } catch { } } else { RecvDataList.RemoveRange(0, bufferlength - 1); // 데이터 모두삭제 continue; } } } }