Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine($"Start scan {DateTime.Now:HH:mm:ss,fff}");

            Console.WriteLine("########################## First test ################################");

            var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());

            XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

            var detection = new UdpDeviceDetection();
            var packages  = detection.GetDeviceInfoPackagesAsync(5555, new byte[] { 0x43, 0x30, 0x32 }, timeout: 1000).GetAwaiter().GetResult();

            foreach (var package in packages)
            {
                Console.WriteLine($"{package.DiscoveredNetwork.IPAddress} {package.DeviceIpAddress} {BitConverter.ToString(package.ReceivedData)}");
            }

            Console.WriteLine("########################## Second test ###############################");

            detection.DeviceResponseReceived += Detection_DeviceResponseReceived;
            detection.ScanAsync(5555, new byte[] { 0x43, 0x30, 0x32 }, timeout: 1000).GetAwaiter().GetResult();
            detection.DeviceResponseReceived -= Detection_DeviceResponseReceived;

            Console.WriteLine($"Scan done {DateTime.Now:HH:mm:ss,fff}");
            Console.ReadLine();
        }
Пример #2
0
        private async Task DiscoverDevicesAsync()
        {
            var detection = new UdpDeviceDetection();

            var packagesAlturos = await detection.GetDeviceInfoPackagesAsync(5555, new byte[] { 0x43, 0x30, 0x32 }, timeout : 1000);

            var packagesEneo = await detection.GetDeviceInfoPackagesAsync(4800, new byte[] { 0x01, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }, timeout : 1000);

            var discoveredDevices = new List <DiscoveredDevice>
            {
                new DiscoveredDevice {
                    Manufacturer = "Choose a device"
                }
            };

            discoveredDevices.AddRange(packagesAlturos.Select(o => new DiscoveredDevice {
                Manufacturer = "Alturos", IpAddress = o.DeviceIpAddress
            }));
            discoveredDevices.AddRange(packagesEneo.GroupBy(o => o.DeviceIpAddress).Select(o => new DiscoveredDevice {
                Manufacturer = "Eneo", IpAddress = o.First().DeviceIpAddress
            }));

            this.comboBoxDiscoverd.Invoke(o => o.DataSource = discoveredDevices);
        }