Esempio n. 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();
            }
        }
Esempio n. 2
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();
            }
        }