private void tcpAsyncServer_ReceiveServerEvent(object sender, ReceiveServerEventArgs e) { this.Invoke((EventHandler)(delegate { NetPacket np = (NetPacket)e.netPacket; switch (np.PacketHead.PType) { case NetPacket.NetPacketType.STRING: textBox1.AppendText("收到字符串" + np.Data.ToString() + "\r\n"); tcpAsyncServer.Send(e.Client, NetPacket.MakeStringPacket("服务器收到数据" + np.Data.ToString())); break; case NetPacket.NetPacketType.BINARY: NetFile nf = (NetFile)np.Data; textBox1.AppendText("收到文件" + nf.FileName + ",正在后台生成.....\r\n"); string file = System.Windows.Forms.Application.StartupPath + "\\收到的文件\\" + nf.FileName; FileInfo f = new FileInfo(file); if (!Directory.Exists(f.DirectoryName)) { Directory.CreateDirectory(f.DirectoryName); } FileStream fs = null; fs = new FileStream(file, FileMode.Create); fs.BeginWrite(nf.Content, 0, nf.Content.Length, NetFileWriteOK, fs); break; case NetPacket.NetPacketType.COMPLEX: NetObject no = (NetObject)np.Data; textBox1.AppendText("收到序列对象" + no.TypeName + ",正在后台生成.....\r\n"); break; } })); }
private void tcpAsyncServer_ReceiveServerEvent(object sender, ReceiveServerEventArgs e) { CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; IPEndPoint ip = (IPEndPoint)e.Client.ClientSocket.RemoteEndPoint; this.Invoke((EventHandler)(delegate { textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ") + "\r\n"); if (rx.Header.Command == 0x50)//握手电源控制器状态上报 { double f; byte[] fb = new byte[4]; int indexLi = -1; for (int i = 0; i < listView1.Items.Count; i++) { if (listView1.Items[i].Text == ip.Address.ToString()) { indexLi = i; break; } } if (indexLi == -1) { NetLog(DateTime.Now.ToLongTimeString() + ":"); NetLog("未处理ip数据:" + e.Client.ClientSocket.RemoteEndPoint.ToString()); NetLog("\r\n"); return; } string strLog = e.Client.ClientSocket.RemoteEndPoint.ToString() + ":"; //MS8607 if (rx.Data[12] > 10) { listView1.Items[indexLi].SubItems[2].Text = "xxx.x"; listView1.Items[indexLi].SubItems[3].Text = "xxx.x"; listView1.Items[indexLi].SubItems[4].Text = "xxx.x"; } else { f = BitConverter.ToSingle(rx.Data, 0); listView1.Items[indexLi].SubItems[2].Text = f.ToString("F2"); strLog += f.ToString("F2") + ","; f = BitConverter.ToSingle(rx.Data, 4); //f = f; listView1.Items[indexLi].SubItems[3].Text = f.ToString("F2"); strLog += f.ToString("F2") + ","; f = BitConverter.ToSingle(rx.Data, 8); listView1.Items[indexLi].SubItems[4].Text = f.ToString("F2"); strLog += f.ToString("F2") + ","; } if (rx.Data[13] == 0) { listView1.Items[indexLi].SubItems[5].Text = "漏水"; } else { listView1.Items[indexLi].SubItems[5].Text = "正常"; } strLog += listView1.Items[indexLi].SubItems[5].Text + ","; if (rx.Data[14] == 0) { listView1.Items[indexLi].SubItems[6].Text = "漏水"; } else { listView1.Items[indexLi].SubItems[6].Text = "正常"; } strLog += listView1.Items[indexLi].SubItems[5].Text + ","; if (rx.Data[15] == 0) { listView1.Items[indexLi].SubItems[7].Text = "断电"; } else { listView1.Items[indexLi].SubItems[7].Text = "供电"; } strLog += listView1.Items[indexLi].SubItems[5].Text; NetLog(DateTime.Now.ToLongTimeString() + ":"); NetLog(strLog); NetLog("\r\n"); } else { NetLog(DateTime.Now.ToLongTimeString() + ":"); NetLog("未知指令数据:" + e.Client.ClientSocket.RemoteEndPoint.ToString()); NetLog("\r\n"); NetLog(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); NetLog("\r\n"); } })); }
private void tcpAsyncServer_ReceiveServerEvent(object sender, ReceiveServerEventArgs e) { this.Invoke((EventHandler)(delegate { string strRx = (string)e.netPacket; string[] rxList = strRx.Split(','); string key = e.Client.ClientSocket.RemoteEndPoint.ToString(); //if(rxList.Length==2) { int index = int.Parse(rxList[0]); if (index == 1)//学号等信息 { textBox1.AppendText(strRx + "\r\n"); CurveData cd = new CurveData(); string[] infoList = rxList[1].Split('|'); if (infoList.Length == 4) { cd.ZuoWeiHao = infoList[0]; cd.BanJi = infoList[1]; cd.XueHao = infoList[2]; cd.exWorkTepy = byte.Parse(infoList[3]); CurveDataTable[key] = cd; WFGlobal.WaitMS(1000); textBox1.AppendText("学号信息\r\n"); tcpAsyncServer.Send(e.Client, easyStringPacket.MakePacket("01,OK")); } } else if (index <= 7 && index >= 2) { CurveData cd = (CurveData)CurveDataTable[key]; if (cd != null) { int nCount = int.Parse(rxList[1]); string[] infoList = rxList[2].Split('|'); if (infoList.Length == nCount) { cd.VADataCount[index - 2] = nCount; for (int i = 0; i < nCount; i++) { cd.VAData[index - 2, i] = (float)(float.Parse(infoList[i]) * 0.000763); } cd.bVAExist[index - 2] = true; CurveDataTable[key] = cd; WFGlobal.WaitMS(1000); textBox1.AppendText("实验数据\r\n"); tcpAsyncServer.Send(e.Client, easyStringPacket.MakePacket(index.ToString("d2") + ",OK")); // if (index == 7) // { // ReportPrint(cd); // } } } } else if (index <= 11 && index >= 8) { CurveData cd = (CurveData)CurveDataTable[key]; int gqIndex = index - 8; if (cd != null) { int nCount = int.Parse(rxList[1]); string[] infoList = rxList[2].Split('|'); if (infoList.Length == nCount) { cd.GQDataCount[gqIndex] = nCount; for (int i = 0; i < nCount; i++) { cd.GQData[gqIndex, i] = (float)(float.Parse(infoList[i]) * 0.000763); } cd.bGQExist[gqIndex] = true; CurveDataTable[key] = cd; WFGlobal.WaitMS(1000); textBox1.AppendText("实验数据\r\n"); tcpAsyncServer.Send(e.Client, easyStringPacket.MakePacket(index.ToString("d2") + ",OK")); // if (index == 7) // { // ReportPrint(cd); // } } } } else if (index == 12) { CurveData cd = (CurveData)CurveDataTable[key]; if (cd != null) { string[] infoList = rxList[1].Split('|'); if (infoList.Length == 9) { for (int i = 0; i < 9; i++) { cd.PLKData[i] = float.Parse(infoList[i]); } cd.bPLKExist = true; CurveDataTable[key] = cd; WFGlobal.WaitMS(1000); textBox1.AppendText("实验数据\r\n"); tcpAsyncServer.Send(e.Client, easyStringPacket.MakePacket(index.ToString("d2") + ",OK")); // if (index == 7) // { // ReportPrint(cd); // } } } } else if (index == 99)//请求打印帧 { CurveData cd = (CurveData)CurveDataTable[key]; if (cd != null) { WFGlobal.WaitMS(1000); textBox1.AppendText("开始打印\r\n"); tcpAsyncServer.Send(e.Client, easyStringPacket.MakePacket(index.ToString("d2") + ",OK")); ReportPrint(cd); } } } //textBox1.AppendText(strRx + "\r\n"); // NetPacket np = (NetPacket)e.netPacket; // switch (np.PacketHead.PType) // { // case NetPacket.NetPacketType.STRING: // textBox1.AppendText("收到字符串" + np.Data.ToString() + "\r\n"); // tcpAsyncServer.Send(e.Client, NetPacket.MakeStringPacket("服务器收到数据" + np.Data.ToString())); // break; // case NetPacket.NetPacketType.BINARY: // NetFile nf = (NetFile)np.Data; // textBox1.AppendText("收到文件" + nf.FileName + ",正在后台生成.....\r\n"); // string file = System.Windows.Forms.Application.StartupPath + "\\收到的文件\\" + nf.FileName; // FileInfo f = new FileInfo(file); // if (!Directory.Exists(f.DirectoryName)) // Directory.CreateDirectory(f.DirectoryName); // FileStream fs = null; // fs = new FileStream(file, FileMode.Create); // fs.BeginWrite(nf.Content, 0, nf.Content.Length, NetFileWriteOK, fs); // break; // case NetPacket.NetPacketType.COMPLEX: // NetObject no = (NetObject)np.Data; // textBox1.AppendText("收到序列对象" + no.TypeName + ",正在后台生成.....\r\n"); // break; // } })); }
private void tcpAsyncServer_ReceiveServerEvent(object sender, ReceiveServerEventArgs e) { IPEndPoint ip = (IPEndPoint)e.Client.ClientSocket.RemoteEndPoint; //if (ip.Address.Equals(Form1.mcuSocketIP.Address)) if (Form1.mcuClientContext != null && e.Client == Form1.mcuClientContext) { this.Invoke((EventHandler)(delegate { CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; if (rx.Header.Command == 0x02) //读取网络参数 { tabControl1.Enabled = true; timer1.Enabled = false; textBox6.Text = StringsFunction.byteToHexStr(rx.Data, 0, 8, " "); byte[] bIP = new byte[4]; for (int i = 0; i < 4; i++) { bIP[i] = rx.Data[8 + i]; } IPAddress mcuIP = new IPAddress(bIP); textBox2.Text = mcuIP.ToString(); for (int i = 0; i < 4; i++) { bIP[i] = rx.Data[12 + i]; } mcuIP = new IPAddress(bIP); textBox3.Text = mcuIP.ToString(); for (int i = 0; i < 4; i++) { bIP[i] = rx.Data[16 + i]; } mcuIP = new IPAddress(bIP); textBox4.Text = mcuIP.ToString(); for (int i = 0; i < 4; i++) { bIP[i] = rx.Data[24 + i]; } mcuIP = new IPAddress(bIP); textBox5.Text = mcuIP.ToString(); numericUpDown2.Value = BytesOP.MakeShort(rx.Data[0x1d], rx.Data[0x1c]); numericUpDown1.Value = BytesOP.MakeShort(rx.Data[0x21], rx.Data[0x20]); } else if (rx.Header.Command == 0x03) //设定网络参数 { tabControl1.Enabled = true; timer1.Enabled = false; MessageBox.Show("设定网络参数成功"); } else if (rx.Header.Command == 0x04) //设定光源 { tabControl1.Enabled = true; timer1.Enabled = false; if (rx.Data[0] != 0) { MessageBox.Show("设定光源电流成功"); } else { MessageBox.Show("设定光源电流失败"); } } else if (rx.Header.Command == 0x05) //设定备用IO成功 { tabControl1.Enabled = true; timer1.Enabled = false; MessageBox.Show("设定备用IO成功"); } else if (rx.Header.Command == 0x06) //设定备用IO成功 { tabControl1.Enabled = true; timer1.Enabled = false; MessageBox.Show("设定重启成功"); } else if (rx.Header.Command == 0x07) //设定备用IO成功 { tabControl1.Enabled = true; timer1.Enabled = false; MessageBox.Show("电源设定成功"); } // if (bSave) // { // NetLog(DateTime.Now.ToLongTimeString() + " : "); // NetLog("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); // NetLog(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); // NetLog("\r\n"); // } // else if (rx.Header.Command != 0x01) { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); textBox1.AppendText("\r\n"); } })); } else { this.Invoke((EventHandler)(delegate { NetLog(DateTime.Now.ToLongTimeString() + " : "); NetLog("收到未知IP数据" + e.Client.clientEndPoint.ToString() + ":"); NetLog("\r\n"); })); } }
private void tcpAsyncServer_ReceiveServerEvent(object sender, ReceiveServerEventArgs e) { IPEndPoint ip = (IPEndPoint)e.Client.ClientSocket.RemoteEndPoint; //if (ip.Address.Equals(Form1.mcuSocketIP.Address)) if (ip.Address.ToString() == strIP) { this.Invoke((EventHandler)(delegate { CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; if (rx.Header.Command == 0x02)//读取网络参数 { tabControl1.Enabled = true; timer1.Enabled = false; textBox6.Text = WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, 0, 6, " "); byte[] bIP = new byte[4]; for (int i = 0; i < 4; i++) { bIP[i] = rx.Data[8 + i]; } IPAddress mcuIP = new IPAddress(bIP); textBox2.Text = mcuIP.ToString(); for (int i = 0; i < 4; i++) { bIP[i] = rx.Data[12 + i]; } mcuIP = new IPAddress(bIP); textBox3.Text = mcuIP.ToString(); for (int i = 0; i < 4; i++) { bIP[i] = rx.Data[16 + i]; } mcuIP = new IPAddress(bIP); textBox4.Text = mcuIP.ToString(); for (int i = 0; i < 4; i++) { bIP[i] = rx.Data[24 + i]; } mcuIP = new IPAddress(bIP); textBox5.Text = mcuIP.ToString(); numericUpDown2.Value = BytesOP.MakeShort(rx.Data[0x1d], rx.Data[0x1c]); numericUpDown1.Value = BytesOP.MakeShort(rx.Data[0x21], rx.Data[0x20]); } else if (rx.Header.Command == 0x03)//设定网络参数 { tabControl1.Enabled = true; timer1.Enabled = false; MessageBox.Show("设定网络参数成功,请重启设备后生效"); } else if (rx.Header.Command == 0x05)//设定备用IO成功 { tabControl1.Enabled = true; timer1.Enabled = false; MessageBox.Show("设定IO状态成功"); } else if (rx.Header.Command == 0x06)//设定备用IO成功 { tabControl1.Enabled = true; timer1.Enabled = false; MessageBox.Show("设定重启成功,将重新连入服务器,确定后将退出系统设定界面!"); this.Close(); } else if (rx.Header.Command != 0x50) { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("控制板数据为:" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); textBox1.AppendText("\r\n"); } })); } else { this.Invoke((EventHandler)(delegate { NetLog(DateTime.Now.ToLongTimeString() + " : "); NetLog("收到未知IP数据" + e.Client.clientEndPoint.ToString() + ":"); NetLog("\r\n"); })); } }
private void tcpAsyncServer_ReceiveServerEvent(object sender, ReceiveServerEventArgs e) { IPEndPoint ip = (IPEndPoint)e.Client.ClientSocket.RemoteEndPoint; //if (ip.Address.Equals(mcuSocketIP.Address)) if (mcuClientContext != null && e.Client == mcuClientContext) { this.Invoke((EventHandler)(delegate { CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; if (rx.Header.Command == 0x01) { double f; byte[] fb = new byte[4]; int fbIndex; string str; bool bSave = false; DateTime dt = DateTime.Now; //温度 f = BytesOP.MakeShort(rx.Data[0], rx.Data[1]); f = f / 100; listView1.Items[0].SubItems[1].Text = f.ToString("F2"); string filePT; filePT = System.Windows.Forms.Application.StartupPath + "\\TextLog\\PT" + String.Format("{0:D4}{1:D2}{2:D2}", dt.Year, dt.Month, dt.Day) + ".txt"; TextLog.AddTextLog(dt.ToString() + " " + listView1.Items[0].SubItems[1].Text, filePT, false); //电子罗盘 fbIndex = 2; for (int i = 0; i < 4; i++) { fb[i] = rx.Data[fbIndex + 3 - i]; } f = BitConverter.ToSingle(fb, 0); listView1.Items[1].SubItems[1].Text = f.ToString("F2"); fbIndex = 6; for (int i = 0; i < 4; i++) { fb[i] = rx.Data[fbIndex + 3 - i]; } f = BitConverter.ToSingle(fb, 0); listView1.Items[2].SubItems[1].Text = f.ToString("F2"); fbIndex = 10; for (int i = 0; i < 4; i++) { fb[i] = rx.Data[fbIndex + 3 - i]; } f = BitConverter.ToSingle(fb, 0); listView1.Items[3].SubItems[1].Text = f.ToString("F2"); string fileTC; fileTC = System.Windows.Forms.Application.StartupPath + "\\TextLog\\TC" + String.Format("{0:D4}{1:D2}{2:D2}", dt.Year, dt.Month, dt.Day) + ".txt"; TextLog.AddTextLog(dt.ToString() + " " + listView1.Items[1].SubItems[1].Text + " " + listView1.Items[2].SubItems[1].Text + " " + listView1.Items[3].SubItems[1].Text, fileTC, false); //授时 str = Encoding.UTF8.GetString(rx.Data, 14, 10); listView1.Items[4].SubItems[1].Text = str; str = Encoding.UTF8.GetString(rx.Data, 24, 6); listView1.Items[5].SubItems[1].Text = str; //MS8607 f = BitConverter.ToSingle(rx.Data, 30); listView1.Items[6].SubItems[1].Text = f.ToString("F2"); f = BitConverter.ToSingle(rx.Data, 34); listView1.Items[7].SubItems[1].Text = f.ToString("F2"); f = BitConverter.ToSingle(rx.Data, 38); listView1.Items[8].SubItems[1].Text = f.ToString("F2"); string fileMS; fileMS = System.Windows.Forms.Application.StartupPath + "\\TextLog\\MS" + String.Format("{0:D4}{1:D2}{2:D2}", dt.Year, dt.Month, dt.Day) + ".txt"; TextLog.AddTextLog(dt.ToString() + " " + listView1.Items[6].SubItems[1].Text + " " + listView1.Items[7].SubItems[1].Text + " " + listView1.Items[8].SubItems[1].Text, fileMS, false); //光源 f = BytesOP.MakeShort(rx.Data[44], rx.Data[45]); f = f / 10; rioCur = f; listView1.Items[14].SubItems[1].Text = f.ToString("F1"); ushort rioStatus = BytesOP.MakeShort(rx.Data[42], rx.Data[43]); listView1.Items[15].SubItems[1].Text = rioStatus.ToString("X04"); if (BytesOP.GetBit(rioStatus, 0)) { listView1.Items[16].SubItems[1].Text = "是"; listView1.Items[16].BackColor = Color.Lime; } else { listView1.Items[16].SubItems[1].Text = "否"; listView1.Items[16].BackColor = Color.Red; } if (BytesOP.GetBit(rioStatus, 6)) { listView1.Items[17].SubItems[1].Text = "是"; listView1.Items[17].BackColor = Color.Red; } else { listView1.Items[17].SubItems[1].Text = "否"; listView1.Items[17].BackColor = Color.Lime; } if (BytesOP.GetBit(rioStatus, 7)) { listView1.Items[18].SubItems[1].Text = "是"; listView1.Items[18].BackColor = Color.Red; } else { listView1.Items[18].SubItems[1].Text = "否"; listView1.Items[18].BackColor = Color.Lime; } if (BytesOP.GetBit(rioStatus, 11))//当前为新数据,需要存储 { string fileLA; fileLA = System.Windows.Forms.Application.StartupPath + "\\TextLog\\LA" + String.Format("{0:D4}{1:D2}{2:D2}", dt.Year, dt.Month, dt.Day) + ".txt"; TextLog.AddTextLog(dt.ToString() + " " + listView1.Items[14].SubItems[1].Text + " " + listView1.Items[15].SubItems[1].Text, fileLA, false); } //通信错误帧统计 listView1.Items[9].SubItems[1].Text = rx.Data[46].ToString(); if (rx.Data[46] > 5) { bSave = true; listView1.Items[9].BackColor = Color.Red; } else { listView1.Items[9].BackColor = SystemColors.Window; } listView1.Items[10].SubItems[1].Text = rx.Data[47].ToString(); if (rx.Data[47] > 5) { bSave = true; listView1.Items[10].BackColor = Color.Red; } else { listView1.Items[10].BackColor = SystemColors.Window; } listView1.Items[11].SubItems[1].Text = rx.Data[48].ToString(); if (rx.Data[48] > 5) { bSave = true; listView1.Items[11].BackColor = Color.Red; } else { listView1.Items[11].BackColor = SystemColors.Window; } listView1.Items[12].SubItems[1].Text = rx.Data[49].ToString(); if (rx.Data[49] > 5) { bSave = true; listView1.Items[12].BackColor = Color.Red; } else { listView1.Items[12].BackColor = SystemColors.Window; } listView1.Items[13].SubItems[1].Text = rx.Data[50].ToString(); if (rx.Data[50] > 5) { bSave = true; listView1.Items[13].BackColor = Color.Red; } else { listView1.Items[13].BackColor = SystemColors.Window; } listView1.Items[19].SubItems[1].Text = rx.Data[51].ToString(); //漏水1 listView1.Items[20].SubItems[1].Text = rx.Data[52].ToString(); //漏水2 listView1.Items[21].SubItems[1].Text = rx.Data[53].ToString(); //备用IO1 listView1.Items[22].SubItems[1].Text = rx.Data[54].ToString(); //备用IO1 listView1.Items[23].SubItems[1].Text = rx.Data[55].ToString(); //备用IO1 listView1.Items[24].SubItems[1].Text = rx.Data[56].ToString(); //备用IO1 listView1.Items[25].SubItems[1].Text = rx.Data[57].ToString(); //备用IO1 listView1.Items[26].SubItems[1].Text = rx.Data[58].ToString(); //备用IO1 for (int i = 0; i < 6; i++) { bIO[i] = rx.Data[53 + i]; } if (rx.Data[59] == 0) { listView1.Items[27].SubItems[1].Text = "打开"; bPower1 = true; } else { listView1.Items[27].SubItems[1].Text = "关闭"; bPower1 = false; } if (rx.Data[60] == 0) { listView1.Items[28].SubItems[1].Text = "打开"; bPower2 = true; } else { listView1.Items[28].SubItems[1].Text = "关闭"; bPower2 = false; } if (bSave) { NetLog(DateTime.Now.ToLongTimeString() + " : "); NetLog("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); NetLog(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); NetLog("\r\n"); } else { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); textBox1.AppendText("\r\n"); } } else if (rx.Header.Command == 0x08)//读取光源状态 { timer2.Enabled = false; toolStrip1.Enabled = true; timer1.Enabled = true; textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到手动读取光源数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); textBox1.AppendText("\r\n"); if (rx.Header.Len == 0)//读取失败 { MessageBox.Show("读取光源状态失败,请稍后重试!!"); } else { //光源 double f; f = BytesOP.MakeShort(rx.Data[2], rx.Data[3]); f = f / 10; rioCur = f; listView1.Items[14].SubItems[1].Text = f.ToString("F1"); ushort rioStatus = BytesOP.MakeShort(rx.Data[0], rx.Data[1]); listView1.Items[15].SubItems[1].Text = rioStatus.ToString("X04"); if (BytesOP.GetBit(rioStatus, 0)) { listView1.Items[16].SubItems[1].Text = "是"; listView1.Items[16].BackColor = Color.Lime; } else { listView1.Items[16].SubItems[1].Text = "否"; listView1.Items[16].BackColor = Color.Red; } if (BytesOP.GetBit(rioStatus, 6)) { listView1.Items[17].SubItems[1].Text = "是"; listView1.Items[17].BackColor = Color.Red; } else { listView1.Items[17].SubItems[1].Text = "否"; listView1.Items[17].BackColor = Color.Lime; } if (BytesOP.GetBit(rioStatus, 7)) { listView1.Items[18].SubItems[1].Text = "是"; listView1.Items[18].BackColor = Color.Red; } else { listView1.Items[18].SubItems[1].Text = "否"; listView1.Items[18].BackColor = Color.Lime; } DateTime dt = DateTime.Now; string fileLA; fileLA = System.Windows.Forms.Application.StartupPath + "\\TextLog\\LA" + String.Format("{0:D4}{1:D2}{2:D2}", dt.Year, dt.Month, dt.Day) + ".txt"; TextLog.AddTextLog(dt.ToString() + " " + listView1.Items[14].SubItems[1].Text + " " + listView1.Items[15].SubItems[1].Text, fileLA, false); } } else { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); textBox1.AppendText("\r\n"); } })); } else { this.Invoke((EventHandler)(delegate { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到未知IP数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText("\r\n"); CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; if (rx.Header.Command == 0xf0) { if (rx.Data[0] == 0x01) //传感器采集板接入 { toolStripButton2.Enabled = true; toolStripButton3.Enabled = true; mcuClientContext = e.Client; //mcuSocketIP.Port = ip.Port; this.Invoke((EventHandler)(delegate { NetLog(DateTime.Now.ToLongTimeString() + " : "); NetLog("单片机采集板接入"); NetLog("\r\n"); })); } } })); } }
private void tcpAsyncServer_ReceiveServerEvent(object sender, ReceiveServerEventArgs e) { IPEndPoint ip = (IPEndPoint)e.Client.ClientSocket.RemoteEndPoint; //if (ip.Address.Equals(mcuSocketIP.Address)) if (mcuClientContext != null && e.Client == mcuClientContext) { this.Invoke((EventHandler)(delegate { CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; if (rx.Header.Command == 0x01) { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到水听器采集板数据" + e.Client.clientEndPoint.ToString()); textBox1.AppendText("\r\n"); int max = 102400; if (chart1.Series[0].Points.Count > max) { chart1.Series[0].Points.Clear(); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < (rx.Data.Length - 2); i += 2) { ushort ad = BytesOP.MakeShort(rx.Data[i], rx.Data[i + 1]); double v = (double)ad; v = v * 0.000078125; v = v - 2.56; //chart1.Series[0].Points.Clear(); chart1.Series[0].Points.AddY(v); sb.AppendLine(v.ToString("F6")); // int max = 1024000; // if (chart1.Series[0].Points.Count > max) // { // while (chart1.Series[0].Points.Count > (max - 1024)) // { // chart1.Series[0].Points.RemoveAt(0); // } // } } TextLog.AddTextLog(sb.ToString(), fileHY, false); } })); } else { this.Invoke((EventHandler)(delegate { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到未知IP数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText("\r\n"); CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; if (rx.Header.Command == 0xf0) { if (rx.Data[0] == 0x02) //矢量水听器采集板接入 { mcuClientContext = e.Client; //mcuSocketIP.Port = ip.Port; this.Invoke((EventHandler)(delegate { NetLog(DateTime.Now.ToLongTimeString() + " : "); NetLog("水听器采集板接入"); NetLog("\r\n"); })); } } })); } }
private void tcpAsyncServer_ReceiveServerEvent(object sender, ReceiveServerEventArgs e) { IPEndPoint ip = (IPEndPoint)e.Client.ClientSocket.RemoteEndPoint; //if (ip.Address.Equals(mcuSocketIP.Address)) if (mcuClientContext != null && e.Client == mcuClientContext) { this.Invoke((EventHandler)(delegate { CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; if (rx.Header.Command == 0x01) { double f; byte[] fb = new byte[4]; int fbIndex; string str; bool bSave = false; //温度 f = BytesOP.MakeShort(rx.Data[0], rx.Data[1]); f = f / 100; listView1.Items[0].SubItems[1].Text = f.ToString("F2"); //电子罗盘 fbIndex = 2; for (int i = 0; i < 4; i++) { fb[i] = rx.Data[fbIndex + 3 - i]; } f = BitConverter.ToSingle(fb, 0); listView1.Items[1].SubItems[1].Text = f.ToString("F2"); fbIndex = 6; for (int i = 0; i < 4; i++) { fb[i] = rx.Data[fbIndex + 3 - i]; } f = BitConverter.ToSingle(fb, 0); listView1.Items[2].SubItems[1].Text = f.ToString("F2"); fbIndex = 10; for (int i = 0; i < 4; i++) { fb[i] = rx.Data[fbIndex + 3 - i]; } f = BitConverter.ToSingle(fb, 0); listView1.Items[3].SubItems[1].Text = f.ToString("F2"); //授时 str = Encoding.UTF8.GetString(rx.Data, 14, 10); listView1.Items[4].SubItems[1].Text = str; str = Encoding.UTF8.GetString(rx.Data, 24, 6); listView1.Items[5].SubItems[1].Text = str; //MS8607 f = BitConverter.ToSingle(rx.Data, 30); listView1.Items[6].SubItems[1].Text = f.ToString("F2"); f = BitConverter.ToSingle(rx.Data, 34); listView1.Items[7].SubItems[1].Text = f.ToString("F2"); f = BitConverter.ToSingle(rx.Data, 38); listView1.Items[8].SubItems[1].Text = f.ToString("F2"); //光源 f = BytesOP.MakeShort(rx.Data[44], rx.Data[45]); f = f / 10; rioCur = f; listView1.Items[14].SubItems[1].Text = f.ToString("F1"); ushort rioStatus = BytesOP.MakeShort(rx.Data[42], rx.Data[43]); listView1.Items[15].SubItems[1].Text = rioStatus.ToString("X04"); if (BytesOP.GetBit(rioStatus, 0)) { listView1.Items[16].SubItems[1].Text = "是"; listView1.Items[16].BackColor = Color.Lime; } else { listView1.Items[16].SubItems[1].Text = "否"; listView1.Items[16].BackColor = Color.Red; } if (BytesOP.GetBit(rioStatus, 6)) { listView1.Items[17].SubItems[1].Text = "是"; listView1.Items[17].BackColor = Color.Red; } else { listView1.Items[17].SubItems[1].Text = "否"; listView1.Items[17].BackColor = Color.Lime; } if (BytesOP.GetBit(rioStatus, 7)) { listView1.Items[18].SubItems[1].Text = "是"; listView1.Items[18].BackColor = Color.Red; } else { listView1.Items[18].SubItems[1].Text = "否"; listView1.Items[18].BackColor = Color.Lime; } //通信错误帧统计 listView1.Items[9].SubItems[1].Text = rx.Data[46].ToString(); if (rx.Data[46] > 5) { bSave = true; listView1.Items[9].BackColor = Color.Red; } else { listView1.Items[9].BackColor = SystemColors.Window; } listView1.Items[10].SubItems[1].Text = rx.Data[47].ToString(); if (rx.Data[47] > 5) { bSave = true; listView1.Items[10].BackColor = Color.Red; } else { listView1.Items[10].BackColor = SystemColors.Window; } listView1.Items[11].SubItems[1].Text = rx.Data[48].ToString(); if (rx.Data[48] > 5) { bSave = true; listView1.Items[11].BackColor = Color.Red; } else { listView1.Items[11].BackColor = SystemColors.Window; } listView1.Items[12].SubItems[1].Text = rx.Data[49].ToString(); if (rx.Data[49] > 5) { bSave = true; listView1.Items[12].BackColor = Color.Red; } else { listView1.Items[12].BackColor = SystemColors.Window; } listView1.Items[13].SubItems[1].Text = rx.Data[50].ToString(); if (rx.Data[50] > 5) { bSave = true; listView1.Items[13].BackColor = Color.Red; } else { listView1.Items[13].BackColor = SystemColors.Window; } listView1.Items[19].SubItems[1].Text = rx.Data[51].ToString(); //漏水1 listView1.Items[20].SubItems[1].Text = rx.Data[52].ToString(); //漏水2 listView1.Items[21].SubItems[1].Text = rx.Data[53].ToString(); //备用IO1 listView1.Items[22].SubItems[1].Text = rx.Data[54].ToString(); //备用IO1 listView1.Items[23].SubItems[1].Text = rx.Data[55].ToString(); //备用IO1 listView1.Items[24].SubItems[1].Text = rx.Data[56].ToString(); //备用IO1 listView1.Items[25].SubItems[1].Text = rx.Data[57].ToString(); //备用IO1 listView1.Items[26].SubItems[1].Text = rx.Data[58].ToString(); //备用IO1 for (int i = 0; i < 6; i++) { bIO[i] = rx.Data[53 + i]; } if (rx.Data[59] == 0) { listView1.Items[27].SubItems[1].Text = "打开"; bPower1 = true; } else { listView1.Items[27].SubItems[1].Text = "关闭"; bPower1 = false; } if (rx.Data[60] == 0) { listView1.Items[28].SubItems[1].Text = "打开"; bPower2 = true; } else { listView1.Items[28].SubItems[1].Text = "关闭"; bPower2 = false; } if (bSave) { NetLog(DateTime.Now.ToLongTimeString() + " : "); NetLog("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); NetLog(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); NetLog("\r\n"); } else { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); textBox1.AppendText("\r\n"); } } else { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到单片机采集板数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx.Data, " ")); textBox1.AppendText("\r\n"); } })); } else { this.Invoke((EventHandler)(delegate { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("收到未知IP数据" + e.Client.clientEndPoint.ToString() + ":"); textBox1.AppendText("\r\n"); CP1616_NoAddr_Packet rx = (CP1616_NoAddr_Packet)e.netPacket; if (rx.Header.Command == 0xf0) { if (rx.Data[0] == 0x01) //传感器采集板接入 { mcuClientContext = e.Client; //mcuSocketIP.Port = ip.Port; this.Invoke((EventHandler)(delegate { NetLog(DateTime.Now.ToLongTimeString() + " : "); NetLog("单片机采集板接入"); NetLog("\r\n"); })); } } })); } }