private void ReceivedDataTimerTick(object sender, EventArgs e) { string path = textBoxPath.Text + "2.txt"; if (dataReady) { string indata = string.Empty; Messages.Clear(); //StringBuilder sb = new System.Text.StringBuilder(); //string[] binaryArr1 = new string[sb.Length]; //string[] binaryArr2 = new string[sb.Length]; //string[] residueArr = new string[binaryArr1.Length]; //string[] residueArr2 = new string[binaryArr1.Length]; //string binaryStr=null; //foreach (byte b in System.Text.Encoding.UTF8.GetBytes(indata)) // for (int k = 0; k < sb.Length; k++) // { // sb.Append(Convert.ToString(b, 2).PadLeft(11, '0').PadRight(15, '0'))/*.Append(' ')*/; // binaryArr1[k] = sb.ToString(); // sb.Append(Convert.ToString(b, 2).PadLeft(11, '0'))/*.Append(' ')*/; // binaryArr2[k] = sb.ToString(); // //string binaryStr = sb.ToString(); // } //for (int i = 0; i < binaryArr1.Length; i++) //{ // int binaryInt = Convert.ToInt32(binaryArr1[i], 2); // int residue = binaryInt % 19/*10011*/; // residueArr[i] = Convert.ToString(residue, 2); // binaryArr1[i] = binaryArr2[i] + residueArr[i] + ' '; // binaryStr += binaryArr1[i]; //} //char[] separators = new char[] { ' ' }; //var wordsArray = binaryStr.Split(separators, StringSplitOptions.RemoveEmptyEntries); //string wordsStr = null; //string wordsStr2 = null; //string[] arrayCode = new string[binaryArr1.Length]; //for (int o = 0; o < wordsArray.Length; o++) //{ // int wordsInt = Convert.ToInt32(wordsArray[o], 2); // int residue = wordsInt % 19/*10011*/; // wordsStr = wordsArray[o]; // StringBuilder sb2 = new StringBuilder(wordsStr); // if (residue != 0) { if (sb2[residue - 2] == 1) { sb2[residue - 2] = '0'; } else { sb2[residue - 2] = '1'; } } // wordsStr2 = sb2.ToString(); // arrayCode[o] = wordsStr2; //} //var bytes = arrayCode.Select(s => Convert.ToByte(s, 16)); //var word = Encoding.UTF8.GetString(bytes.ToArray()); ; dataReady = false; //UpdateDataWindow(receivedData); Messages.Clear(); UpdateDataWindow("Данные приняты..."); StellsBox.Clear(); UpdateWindow(receivedData); using (FileStream file = new FileStream(path, FileMode.Append)) using (StreamWriter sw = new StreamWriter(file)) sw.WriteLine(StellsBox.Text); } }
private void UpdateWindow(string message) { StellsBox.Text += message; StellsBox.SelectionStart = StellsBox.TextLength; StellsBox.ScrollToCaret(); }