166 lines
5.7 KiB
Plaintext
166 lines
5.7 KiB
Plaintext
![]() |
private void DisplayYD()
|
|||
|
{
|
|||
|
int ipindex = 4;
|
|||
|
byte[] namestr8 = new byte[8];
|
|||
|
byte[] ipstr16 = new byte[16];
|
|||
|
byte[] macstr20 = new byte[20];
|
|||
|
byte[] recvBuff = new byte[MaxFrameLength];
|
|||
|
int IpIndex = 0;
|
|||
|
while (udpRecv_YD.isEmpty() == false)
|
|||
|
{
|
|||
|
int n = udpRecv_YD.PopOneRecv(ref recvBuff, ref IpIndex);
|
|||
|
|
|||
|
for (int i = 0; i < 8; i++)
|
|||
|
{
|
|||
|
namestr8[i] = 0;
|
|||
|
}
|
|||
|
for (int i = 0; i < 16; i++)
|
|||
|
{
|
|||
|
ipstr16[i] = 0;
|
|||
|
}
|
|||
|
for (int i = 0; i < 20; i++)
|
|||
|
{
|
|||
|
macstr20[i] = 0;
|
|||
|
}
|
|||
|
if (n == 0)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
if ((recvBuff[0] == 0xeb) && (recvBuff[1] == 0x90) && (recvBuff[2] == 0x06))
|
|||
|
{
|
|||
|
ipindex = 4;
|
|||
|
for (int i = 0; i < 8; i++)
|
|||
|
{
|
|||
|
namestr8[i] = recvBuff[ipindex++];
|
|||
|
}
|
|||
|
|
|||
|
string namestr1 = System.Text.Encoding.Default.GetString(namestr8);
|
|||
|
DataGridViewRow row1 = new DataGridViewRow();
|
|||
|
row1.CreateCells(this.dataGridView2);
|
|||
|
row1.Cells[0].Value = (bool)false;
|
|||
|
row1.Cells[1].Value = namestr1; //
|
|||
|
|
|||
|
for (int i = 0; i < 8; i++)
|
|||
|
{
|
|||
|
namestr8[i] = recvBuff[ipindex++];
|
|||
|
}
|
|||
|
string namestr2 = System.Text.Encoding.Default.GetString(namestr8);
|
|||
|
row1.Cells[2].Value = namestr2; //
|
|||
|
|
|||
|
for (int i = 0; i < 16; i++)
|
|||
|
{
|
|||
|
ipstr16[i] = recvBuff[ipindex++];
|
|||
|
}
|
|||
|
string namestr3 = System.Text.Encoding.Default.GetString(ipstr16);
|
|||
|
row1.Cells[3].Value = namestr3; //
|
|||
|
|
|||
|
|
|||
|
for (int i = 0; i < 20; i++)
|
|||
|
{
|
|||
|
macstr20[i] = recvBuff[ipindex++];
|
|||
|
}
|
|||
|
string namestr4 = System.Text.Encoding.Default.GetString(macstr20);
|
|||
|
row1.Cells[4].Value = namestr4; //
|
|||
|
|
|||
|
|
|||
|
for (int i = 0; i < 16; i++)
|
|||
|
{
|
|||
|
ipstr16[i] = recvBuff[ipindex++];
|
|||
|
}
|
|||
|
string namestr5 = System.Text.Encoding.Default.GetString(ipstr16);
|
|||
|
row1.Cells[5].Value = namestr5; //
|
|||
|
|
|||
|
for (int i = 0; i < 20; i++)
|
|||
|
{
|
|||
|
macstr20[i] = recvBuff[ipindex++];
|
|||
|
}
|
|||
|
string namestr6 = System.Text.Encoding.Default.GetString(macstr20);
|
|||
|
row1.Cells[6].Value = namestr6; //
|
|||
|
|
|||
|
|
|||
|
row1.Cells[7].Value = "root"; //
|
|||
|
row1.Cells[8].Value = "jdyd2013"; //
|
|||
|
|
|||
|
if (dataGridView2.Rows.Count == 0)
|
|||
|
{
|
|||
|
dataGridView2.Rows.Add(row1);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
int sameCol = 0;
|
|||
|
bool sameYD = false;
|
|||
|
for (int m = 0; m < dataGridView2.Rows.Count; m++)
|
|||
|
{
|
|||
|
sameCol = 0;
|
|||
|
for (int k = 1; k < 7; k++)
|
|||
|
{
|
|||
|
if (dataGridView2.Rows[m].Cells[k].Value.ToString() == row1.Cells[k].Value.ToString())
|
|||
|
{
|
|||
|
sameCol++;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
if (sameCol == 6)
|
|||
|
{
|
|||
|
sameYD = true;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
if (sameYD == false)
|
|||
|
{
|
|||
|
dataGridView2.Rows.Add(row1);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void InitUDPSocket_YD()
|
|||
|
{
|
|||
|
|
|||
|
InitIPAddress();
|
|||
|
|
|||
|
if (udpclients_YD == null)
|
|||
|
{
|
|||
|
//8004<30>ǶԷ<C7B6><D4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>
|
|||
|
udpclients_YD = new UDPClients("255.255.255.255", "8004", "ASYN");//ָ<><D6B8><EFBFBD>Է<EFBFBD><D4B7>Ľ<EFBFBD><C4BD>ն˿<D5B6>
|
|||
|
udpclients_YD.InitUdpSocket(LocalIPAddress[0], 7004);//
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
if (Udpserver_YD == null)
|
|||
|
{
|
|||
|
Udpserver_YD = new UDPService("7004", "ASYN");
|
|||
|
Udpserver_YD.InitUdpSocket();
|
|||
|
Udpserver_YD.EV_ReceiveData += new NetEvent(this.UDPRecvData_YD);
|
|||
|
|
|||
|
Udpserver_YD.StartReceive();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
if ((udpclients_YD != null) && (Udpserver_YD != null))
|
|||
|
{
|
|||
|
timer3.Start();
|
|||
|
|
|||
|
byte len = 11;
|
|||
|
byte[] data = new byte[len];
|
|||
|
data[0] = 0xeb;
|
|||
|
data[1] = 0x90;
|
|||
|
data[2] = 0x05;
|
|||
|
|
|||
|
data[3] = 0x08;
|
|||
|
|
|||
|
data[4] = 0;
|
|||
|
data[5] = (byte)(DateTime.Now.Second);
|
|||
|
data[6] = (byte)DateTime.Now.Minute;
|
|||
|
data[7] = (byte)DateTime.Now.Hour;
|
|||
|
data[8] = (byte)DateTime.Now.Day;
|
|||
|
data[9] = (byte)DateTime.Now.Month;
|
|||
|
data[10] = (byte)DateTime.Now.Year;
|
|||
|
|
|||
|
udpclients_YD.Send2(data);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|