예제 #1
0
        public Task <SaveResult> SendSignalRequest(ICaptureDevice adapter, string macAddress)
        {
            var disposables = new CompositeDisposable();
            var transport   = new ProfinetEthernetTransport(adapter);

            transport.Open();
            transport.AddDisposableTo(disposables);


            try
            {
                System.Net.NetworkInformation.PhysicalAddress deviceAddress = System.Net.NetworkInformation.PhysicalAddress.Parse(macAddress);
                DCP.BlockErrors err = transport.SendSetSignalRequest(deviceAddress, timeoutInMilliseconds, retries);
                if (err != DCP.BlockErrors.NoError)
                {
                    return(Task.FromResult(new SaveResult(false, err.ToString())));
                }

                return(Task.FromResult(new SaveResult(true, err.ToString())));
            }
            catch (Exception e)
            {
                return(Task.FromResult(new SaveResult(false, e.Message)));
            }
            finally
            {
                disposables.Dispose();
            }
        }
예제 #2
0
        public async Task <List <Device> > GetDevices(ICaptureDevice adapter, TimeSpan timeout)
        {
            var disposables = new CompositeDisposable();
            var transport   = new ProfinetEthernetTransport(adapter);

            transport.Open();
            transport.AddDisposableTo(disposables);

            var devices = new List <Device>();

            Observable.FromEventPattern <ProfinetEthernetTransport.OnDcpMessageHandler, ConnectionInfoEthernet, DcpMessageArgs>(h => transport.OnDcpMessage += h, h => transport.OnDcpMessage -= h)
            .Select(x => ConvertEventToDevice(x.Sender, x.EventArgs))
            .Where(device => devices != null)
            .Do(device => devices.Add(device))
            .Subscribe()
            .AddDisposableTo(disposables)
            ;

            transport.SendIdentifyBroadcast();

            await Task.Delay(timeout);

            disposables.Dispose();

            return(devices);
        }
예제 #3
0
        public Task <SaveResult> SendSettings(ICaptureDevice adapter, string macAddress, Device newSettings, bool permanent)
        {
            var disposables = new CompositeDisposable();
            var transport   = new ProfinetEthernetTransport(adapter);

            transport.Open();
            transport.AddDisposableTo(disposables);


            try
            {
                System.Net.NetworkInformation.PhysicalAddress deviceAddress = System.Net.NetworkInformation.PhysicalAddress.Parse(macAddress);

                DCP.BlockErrors err = transport.SendSetNameRequest(deviceAddress, timeoutInMilliseconds, retries, newSettings.Name, permanent);
                if (err != DCP.BlockErrors.NoError)
                {
                    return(Task.FromResult(new SaveResult(false, err.ToString())));
                }

                System.Net.IPAddress ip      = System.Net.IPAddress.Parse(newSettings.IP);
                System.Net.IPAddress subnet  = System.Net.IPAddress.Parse(newSettings.SubnetMask);
                System.Net.IPAddress gateway = System.Net.IPAddress.Parse(newSettings.Gateway);
                err = transport.SendSetIpRequest(deviceAddress, timeoutInMilliseconds, retries, ip, subnet, gateway, permanent);
                if (err != DCP.BlockErrors.NoError)
                {
                    return(Task.FromResult(new SaveResult(false, err.ToString())));
                }

                return(Task.FromResult(new SaveResult(true, err.ToString())));
            }
            catch (Exception e)
            {
                return(Task.FromResult(new SaveResult(false, e.Message)));
            }
            finally
            {
                disposables.Dispose();
            }
        }