private void button6_Click(object sender, EventArgs e) { tabControl1.Enabled = false; timer1.Enabled = true; byte[] tx = new byte[2]; if (rbp1on.Checked) { tx[0] = 0x01; } else { tx[0] = 0x00; } if (rbp2on.Checked) { tx[1] = 0x01; } else { tx[1] = 0x00; } byte[] tx03 = CP1616_NoAddr_Packet.MakeCP1616_NoAddr_Packet(0x07, tx); tcpAsyncServer.Send(Form1.mcuClientContext, tx03); this.Invoke((EventHandler)(delegate { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("发送到" + Form1.mcuClientContext.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(tx03, " ")); textBox1.AppendText("\r\n"); })); }
private void timer1_Tick(object sender, EventArgs e) { if (mcuClientContext != null) { byte[] tx = CP1616_NoAddr_Packet.MakeCP1616_NoAddr_Packet(0x01); this.Invoke((EventHandler)(delegate { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("发送到" + mcuClientContext.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(tx, " ")); textBox1.AppendText("\r\n"); })); tcpAsyncServer.Send(mcuClientContext, tx); } //看看是否有未知的板子接入 ClientContext[] clientList = tcpAsyncServer.ClientContextList; foreach (ClientContext client in clientList) { if (mcuClientContext != null) { if (client == mcuClientContext) { continue; } } byte[] tx = CP1616_NoAddr_Packet.MakeCP1616_NoAddr_Packet(0xf0); tcpAsyncServer.Send(client, tx); } //if (bPic) //{ //} }
private void tcpAsyncServer_AcceptServer(object sender, AcceptServerEventArgs e) { this.Invoke((EventHandler)(delegate { NetLog(DateTime.Now.ToLongTimeString() + ":"); NetLog("Accept:" + e.Client.ClientSocket.RemoteEndPoint.ToString()); NetLog("\r\n"); })); byte[] tx = CP1616_NoAddr_Packet.MakeCP1616_NoAddr_Packet(0xf0); tcpAsyncServer.Send(e.Client, tx); }
private void button5_Click(object sender, EventArgs e) { tabControl1.Enabled = false; timer1.Enabled = true; byte[] tx06 = CP1616_NoAddr_Packet.MakeCP1616_NoAddr_Packet(0x06); tcpAsyncServer.Send(clientContext, tx06); this.Invoke((EventHandler)(delegate { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("发送到" + clientContext.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(tx06, " ")); textBox1.AppendText("\r\n"); })); }
private void button3_Click(object sender, EventArgs e) { tabControl1.Enabled = false; timer1.Enabled = true; byte[] tx = new byte[2]; tx[0] = BytesOP.GetHighByte((ushort)(numericUpDown3.Value * 10)); tx[1] = BytesOP.GetLowByte((ushort)(numericUpDown3.Value * 10)); byte[] tx03 = CP1616_NoAddr_Packet.MakeCP1616_NoAddr_Packet(0x04, tx); tcpAsyncServer.Send(Form1.mcuClientContext, tx03); this.Invoke((EventHandler)(delegate { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("发送到" + Form1.mcuClientContext.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(tx03, " ")); textBox1.AppendText("\r\n"); })); }
private void timer1_Tick(object sender, EventArgs e) { //看看是否有未知的板子接入 ClientContext[] clientList = tcpAsyncServer.ClientContextList; foreach (ClientContext client in clientList) { if (mcuClientContext != null) { if (client == mcuClientContext) { continue; } } byte[] tx = CP1616_NoAddr_Packet.MakeCP1616_NoAddr_Packet(0xf0); tcpAsyncServer.Send(client, tx); } }
private void button1_Click(object sender, EventArgs e) { if (Form1.mcuClientContext != null) { tabControl1.Enabled = false; timer1.Enabled = true; byte[] tx = CP1616_NoAddr_Packet.MakeCP1616_NoAddr_Packet(0x02); tcpAsyncServer.Send(Form1.mcuClientContext, tx); this.Invoke((EventHandler)(delegate { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("发送到" + Form1.mcuClientContext.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(tx, " ")); textBox1.AppendText("\r\n"); })); } else { MessageBox.Show("单片机采集板尚未接入,请稍后重试!!"); } }
private void button2_Click(object sender, EventArgs e) { if (Form1.mcuClientContext == null) { MessageBox.Show("单片机采集板尚未接入,请稍后重试!!"); return; } IPAddress mcuIP = CheckIPInput(textBox2.Text); if (mcuIP == null) { MessageBox.Show("单片机板ip输入有误"); return; } IPAddress mcuSN = CheckIPInput(textBox3.Text); if (mcuSN == null) { MessageBox.Show("单片机板子网掩码输入有误"); return; } IPAddress mcuGW = CheckIPInput(textBox4.Text); if (mcuGW == null) { MessageBox.Show("单片机板默认网关输入有误"); return; } IPAddress pcIP = CheckIPInput(textBox5.Text); if (pcIP == null) { MessageBox.Show("服务器端ip输入有误"); return; } byte[] mac = StringsFunction.strToHexByte(textBox6.Text, " "); if (mac.Length != 8) { MessageBox.Show("MAC输入有误"); return; } tabControl1.Enabled = false; timer1.Enabled = true; byte[] tx = new byte[36]; for (int i = 0; i < 8; i++) { tx[i] = mac[i]; } for (int i = 0; i < 4; i++) { tx[8 + i] = mcuIP.GetAddressBytes()[i]; tx[8 + 4 + i] = mcuSN.GetAddressBytes()[i]; tx[8 + 8 + i] = mcuGW.GetAddressBytes()[i]; tx[8 + 16 + i] = pcIP.GetAddressBytes()[i]; } tx[28] = BytesOP.GetLowByte((ushort)numericUpDown2.Value); tx[29] = BytesOP.GetHighByte((ushort)numericUpDown2.Value); tx[30] = 0; tx[31] = 0; tx[32] = BytesOP.GetLowByte((ushort)numericUpDown1.Value); tx[33] = BytesOP.GetHighByte((ushort)numericUpDown1.Value); tx[34] = 0; tx[35] = 0; byte[] tx03 = CP1616_NoAddr_Packet.MakeCP1616_NoAddr_Packet(0x03, tx); tcpAsyncServer.Send(Form1.mcuClientContext, tx03); this.Invoke((EventHandler)(delegate { textBox1.AppendText(DateTime.Now.ToLongTimeString() + " : "); textBox1.AppendText("发送到" + Form1.mcuClientContext.clientEndPoint.ToString() + ":"); textBox1.AppendText(WFNetLib.StringFunc.StringsFunction.byteToHexStr(tx03, " ")); textBox1.AppendText("\r\n"); })); }