/// <summary> /// Send result point /// </summary> /// <param name="_point">result_point</param> private void Send(Point _point) { int[] Addresses = new int[chClients.CheckedItems.Count]; for (int I = 0; I < chClients.CheckedItems.Count; I++) { Addresses[I] = (chClients.CheckedItems[I] as ClientAddress).Id; } byte[] Data = new byte[2 * sizeof(int)]; Array.Copy(BitConverter.GetBytes((int)18), Data, sizeof(int)); Array.Copy(BitConverter.GetBytes(_point.X), 0, Data, sizeof(int), sizeof(int)); Array.Copy(BitConverter.GetBytes(_point.Y), 0, Data, sizeof(int), sizeof(int)); Client.SendData(Addresses, Data); DateTime dt = DateTime.Now; }
public static Ice.DispatchStatus SendData___(NMClient obj__, IceInternal.Incoming inS__, Ice.Current current__) { Ice.ObjectImpl.checkMode__(Ice.OperationMode.Normal, current__.mode); IceInternal.BasicStream is__ = inS__.startReadParams(); string strXml; strXml = is__.readString(); inS__.endReadParams(); int ret__ = obj__.SendData(strXml, current__); IceInternal.BasicStream os__ = inS__.startWriteParams__(Ice.FormatType.DefaultFormat); os__.writeInt(ret__); inS__.endWriteParams__(true); return(Ice.DispatchStatus.DispatchOK); }
private void Send_Data() { if ((chClients.CheckedItems.Count > 0) && NMClient.Running) { Frame data = new Frame(); int[] addresses = new int[chClients.CheckedItems.Count]; for (int j = 0; j < chClients.CheckedItems.Count; j++) { addresses[j] = (chClients.CheckedItems[j] as ClientAddress).Id; } // Random Rnd = new Random(); /* while (s.Connected && (N < 10078)) * { * for (I = 260; I < 1460; I++) * { * if ((N == 3000) && ((I / 2) == 130) && ((I % 2) == 1)) * { * data[I] = (byte)(I % 2); * } * else * data[I] = 0; * } * N += 20; * if (s.Connected) * ns.Write(data, 0, 1460); * }; * MessageBox.Show("Все!");*/ /* if (s.Connected) * { * SendData SD = new SendData(Send_Data); * SD.BeginInvoke(null, null); * } * /* for (int K = 0; K < 1001; K++) * { * if (K != 500) * { * tmp = BitConverter.GetBytes((short)0); * } * else * tmp = BitConverter.GetBytes((short)1); * for (int J = 0; J < 30; J++) * { * data[I + J * 40] = tmp[0]; * data[I + 1 + J * 40] = tmp[1]; * }; * I += 2; * if (I == 300) * { * I = 260; * ns.Write(data, 0, 1460); * } * }*/ string str; for (int l = 0; l < dgFiles.Rows.Count; l++) { try { StreamReader sr = new StreamReader(dgFiles.Rows[l].Cells[1].Value.ToString()); SetTime(DateTime.Now, l); string[] strs; int i = 0; while (!sr.EndOfStream) { if (i == Frame.LengthData) { i = 0; NMClient.SendData(addresses, data.GetBytes()); Thread.Sleep(4); } str = sr.ReadLine(); strs = str.Split(new char[] { ' ', (char)9, ';' }); byte f = 1; byte code = 0; for (int J = 0; J < strs[0].Length; J++) { if (strs[0][J] != '0') { code += f; } f <<= 1; } data.reserved[i] = code; for (int J = 0; J < Math.Min(strs.Length, Frame.CountChannels); J++) { data.Data[J * Frame.LengthData + i] = short.Parse(strs[J]); } i++; } sr.Close(); } catch (Exception e) { dgFiles.Rows[l].Cells[2].Value = "Ошибка '" + e.Message + "'"; } } } MessageBox.Show("Все!"); SetEnabled(btnSendFile, true); SetEnabled(btnSendSin, true); SetEnabled(chClients, true); }
private void Send_Data() { Frame data = new Frame(); int[] addresses = new int[chClients.CheckedItems.Count]; for (int j = 0; j < chClients.CheckedItems.Count; j++) { addresses[j] = (chClients.CheckedItems[j] as ClientAddress).Id; } StreamReader[] baseFiles = null; int currentIndex = 0; if (rbFile.Checked) { baseFiles = new StreamReader[dgBaseFiles.RowCount]; for (int i = 0; i < dgBaseFiles.RowCount; i++) { try { baseFiles[i] = new StreamReader(dgBaseFiles.Rows[i].Cells[1].Value.ToString()); if (baseFiles[i].EndOfStream) { throw new Exception("Файл не может быть пустым"); } } catch (Exception e) { baseFiles[i] = null; dgBaseFiles.Invoke(new Action(delegate { dgBaseFiles.Rows[i].Cells[2].Value = "Ошибка '" + e.Message + "'"; })); } } while (currentIndex < dgBaseFiles.RowCount && baseFiles[currentIndex] == null) { currentIndex++; } if (currentIndex == dgBaseFiles.RowCount) { MessageBox.Show("Ни один указанный файл не может использоваться в качестве фонового. Будет использован режим белого шума.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); rbFantom.Invoke(new Action(delegate { rbFantom.Checked = true; })); } else { dgBaseFiles.Invoke(new Action(delegate { dgBaseFiles.Rows[currentIndex].Cells[2].Value = "Отправка"; })); } } Action <Frame> getFrame = delegate(Frame frame) { if (rbFantom.Checked) { for (int i = 0; i < frame.Data.Length; i++) { frame.Data[i] = (short)(m_rnd.Next(2 * (int)nAmplitude.Value) - nAmplitude.Value); } } else { int i = 0; while (i < Frame.LengthData) { try { if (baseFiles[currentIndex].EndOfStream) { baseFiles[currentIndex].BaseStream.Position = 0; currentIndex = (currentIndex + 1) % dgBaseFiles.RowCount; dgBaseFiles.Invoke(new Action(delegate { dgBaseFiles.Rows[currentIndex].Cells[2].Value = ""; })); while (baseFiles[currentIndex] == null) { currentIndex = (currentIndex + 1) % dgBaseFiles.RowCount; } dgBaseFiles.Invoke(new Action(delegate { dgBaseFiles.Rows[currentIndex].Cells[2].Value = "Отправка"; })); } string[] strs = baseFiles[currentIndex].ReadLine().Split(new char[] { ' ', (char)9, ';' }); for (int j = 0; j < Math.Min(strs.Length, Frame.CountChannels); j++) { frame.Data[j * Frame.LengthData + i] = short.Parse(strs[j]); } i++; } catch (Exception e) { dgSignalFiles.Invoke(new Action(delegate { dgBaseFiles.Rows[currentIndex].Cells[2].Value = "Ошибка '" + e.Message + "'"; })); baseFiles[currentIndex] = null; int k = currentIndex; dgBaseFiles.Invoke(new Action(delegate { dgBaseFiles.Rows[currentIndex].Cells[2].Value = ""; })); currentIndex = (currentIndex + 1) % dgBaseFiles.RowCount; while (currentIndex != k && baseFiles[currentIndex] == null) { currentIndex = (currentIndex + 1) % dgBaseFiles.RowCount; } if (currentIndex == k) { MessageBox.Show("Ни один указанный файл не может использоваться в качестве фонового. Будет использован режим белого шума.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); rbFantom.Invoke(new Action(delegate { rbFantom.Checked = true; })); i = Frame.LengthData; } else { dgBaseFiles.Invoke(new Action(delegate { dgBaseFiles.Rows[currentIndex].Cells[2].Value = "Отправка"; })); } } } } }; while (m_NMClient.Running) { if (!Wait) { if ((chClients.CheckedItems.Count > 0) && m_NMClient.Running) { string str; for (int l = 0; l < dgSignalFiles.Rows.Count; l++) { try { StreamReader sr = new StreamReader(dgSignalFiles.Rows[l].Cells[1].Value.ToString()); dgSignalFiles.Invoke(new Action(delegate { dgSignalFiles.Rows[l].Cells[2].Value = "Отправка"; })); string[] strs; int i = 0; while (!sr.EndOfStream) { if (i == Frame.LengthData) { i = 0; m_NMClient.SendData(addresses, data.GetBytes()); Thread.Sleep(4); } str = sr.ReadLine(); strs = str.Split(new char[] { ' ', (char)9, ';' }); if (i == 0) { getFrame(data); } for (int j = 0; j < Math.Min(strs.Length, Frame.CountChannels); j++) { data.Data[j * Frame.LengthData + i] += short.Parse(strs[j]); } i++; } dgSignalFiles.Invoke(new Action(delegate { dgSignalFiles.Rows[l].Cells[2].Value = ""; })); sr.Close(); } catch (Exception e) { dgSignalFiles.Invoke(new Action(delegate { dgSignalFiles.Rows[l].Cells[2].Value = "Ошибка '" + e.Message + "'"; })); } } } Wait = true; } else { getFrame(data); m_NMClient.SendData(addresses, data.GetBytes()); Thread.Sleep(4); } } if (rbFile.Checked) { dgBaseFiles.Invoke(new Action(delegate { dgBaseFiles.Rows[currentIndex].Cells[2].Value = ""; })); } SetEnabled(btnSendFile, true); SetEnabled(chClients, true); }