Пример #1
0
        private DevicesHeartBeat showDevInfo(string s, string Ip)
        {
            DevicesHeartBeat device = JsonConvert.DeserializeObject <DevicesHeartBeat>(s);

            showMsg2(String.Format("解析,机器码[{0}]", device.deviceMachineCode));
            showMsg2(String.Format("解析,机器编号[{0}]", device.deviceKey));
            device.ip = string.IsNullOrEmpty(device.ip) ? Ip : device.ip;
            showMsg2(String.Format("解析,Ip[{0}]", device.ip));
            showMsg2(String.Format("解析,系统时间[{0}]", device.time));
            showMsg2(String.Format("解析,人员数[{0}]", device.personCount));
            showMsg2(String.Format("解析,照片数[{0}]", device.faceCount));
            showMsg2(String.Format("解析,运行时间[{0}]", device.runtime));
            showMsg2(String.Format("解析,版本号[{0}]", device.version));
            showMsg2(String.Format("解析,App占用内存[{0}mb]-[{1:F}%]", device.memory, device.memory / device.totalMem * 100.00));
            showMsg2(String.Format("解析,系统可用内存[{0}mb]-[{1:F}%]", device.availMem, device.availMem / device.totalMem * 100.00));
            showMsg2(String.Format("解析,系统总内存[{0}mb]", device.totalMem));
            showMsg2("");


            showMsg(String.Format("找到设备,机器码[{0}]", device.deviceMachineCode));
            showMsg(String.Format("IP:[{0}]", device.ip));
            showMsg(String.Format("设备类型[{0}]", device.deviceType));

            this.Text = device.deviceMachineCode;
            ButtonListInit();
            return(device);
        }
Пример #2
0
        private void GetDevices()
        {
            byte PACKET_TYPE_FIND_DEVICE_REQ_10 = 0x10; // 搜索请求

            UdpClient  UDPsend  = new UdpClient(new IPEndPoint(IPAddress.Any, 0));
            IPEndPoint endpoint = new IPEndPoint(IPAddress.Broadcast, 9000);

            //其实 IPAddress.Broadcast 就是 255.255.255.255
            //下面代码与上面有相同的作用
            //IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 8080);
            byte[] buf = packData(PACKET_TYPE_FIND_DEVICE_REQ_10);//Encoding.Default.GetBytes("This is UDP broadcast" + DateTime.Now.ToString());
            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    UDPsend.Send(buf, buf.Length, endpoint);
                    try
                    {
                        int rspCount         = 200;
                        IPEndPoint endpointR = new IPEndPoint(IPAddress.Any, 0);
                        while (rspCount-- > 0)
                        {
                            //recePack.setData(receData);
                            byte[] receData = parsePack(UDPsend.Receive(ref endpointR));
                            if (receData != null)
                            {
                                string msg = Encoding.UTF8.GetString(receData);
                                showMsg2(String.Format("设备[{0}]:[{1}]", endpointR.Address, msg));
                                DevicesHeartBeat d = showDevInfo(msg, endpointR.Address.ToString());
                                if (d.deviceType != DeviceType)
                                {
                                    showMsg(String.Format("!!!!!!设备类型不匹配,仅支持类型[{0}]", DeviceType));
                                }
                                else
                                {
                                    DevicList.Add(d);
                                }
                            }
                        }
                    }
                    catch (SocketException ex)
                    {
                        showMsg2(ex.ToString());
                    }

                    Thread.Sleep(1000);
                }
            });
        }