public ActionResult <BreakerSetupObject> Put(int id, [FromBody] BreakerSetupObject newConfiguration)
        {
            id = id - 1;

            SmartDASService service;

            try {
                service = new SmartDASService();
                service.Connect();
            } catch (Exception e) {
                return(StatusCode(500, e));
            }

            try {
                if (id >= 0 && id < 9)
                {
                    var breakers = service.getBreakerConfigurations();

                    breakers[id] = newConfiguration;

                    breakers = service.setBreakerConfigurations(breakers);
                    service.Disconnect();
                    return(breakers[id]);
                }
                else
                {
                    service.Disconnect();
                    return(NotFound());
                }
            } catch (Exception e) {
                service.Disconnect();
                return(StatusCode(500, e));
            }
        }
        public ActionResult <dasCommandsStructure> Put([FromBody] dasCommandsStructure newConfig)
        {
            SmartDASService service;

            try {
                service = new SmartDASService();
                service.Connect();
            } catch (Exception e) {
                return(StatusCode(500, e));
            }

            try {
                service.setDASCommands(newConfig);
            } catch (Exception e) {
                service.Disconnect();
                return(StatusCode(500, e));
            }

            try {
                service.setDASCommands(newConfig);
                var dasCommands = service.getDASCommands();
                service.Disconnect();
                return(dasCommands);
            } catch (Exception e) {
                service.Disconnect();
                return(StatusCode(500, e));
            }
        }
        public ActionResult <BreakerSetupObject> Get(int id)
        {
            id = id - 1;

            SmartDASService service;

            try {
                service = new SmartDASService();
                service.Connect();
            } catch (Exception e) {
                return(StatusCode(500, e));
            }

            if (id >= 0 && id < 9)
            {
                try {
                    var breakers = service.getBreakerConfigurations();
                    service.Disconnect();
                    return(breakers[id]);
                } catch (Exception e) {
                    service.Disconnect();
                    return(StatusCode(500, e));
                }
            }
            else
            {
                service.Disconnect();
                return(NotFound());
            }
        }
        public ActionResult <BreakerSetupObject[]> Get()
        {
            var service = new SmartDASService();

            service.Connect();
            try {
                var breakerConfig = service.getBreakerConfigurations();
                service.Disconnect();
                return(breakerConfig);
            } catch (Exception e) {
                service.Disconnect();
                return(StatusCode(500, e));
            }
        }
        public ActionResult <comAlarmStatusStructure> Get()
        {
            var service = new SmartDASService();

            service.Connect();
            try {
                var commAlarms = service.getCommAlarms();
                service.Disconnect();
                return(commAlarms);
            } catch (Exception e) {
                service.Disconnect();
                return(StatusCode(500, e));
            }
        }
Пример #6
0
        public ActionResult <dasStatusStructure> Get()
        {
            var service = new SmartDASService();

            service.Connect();
            try {
                var dasStatus = service.getDASStatus();
                service.Disconnect();
                return(dasStatus);
            } catch (Exception e) {
                return(StatusCode(500, e));
            }
        }
        public ActionResult <siteSetupStructure> Get()
        {
            var service = new SmartDASService();

            service.Connect();
            try {
                var structure = service.getConfigData();
                service.Disconnect();
                return(structure);
            } catch (Exception e) {
                return(StatusCode(500, e));
            }
        }
Пример #8
0
        public ActionResult <plcNetworkConfig> Get()
        {
            var service = new SmartDASService();

            service.Connect();
            try {
                var networkConfig = service.getPLCNetwork();

                service.Disconnect();
                return(networkConfig);
            } catch (Exception e) {
                return(StatusCode(500, e));
            }
        }
Пример #9
0
        public ActionResult <ConnectionStatus> Get()
        {
            var service = new SmartDASService();

            service.Connect();

            if (SmartDASService.DemoMode == true)
            {
                return(new ConnectionStatus()
                {
                    code = 0,
                    message = "OK",
                    attempts = 0,
                });
            }

            var connectionStatus = service.getConnectionStatus();

            service.Disconnect();

            return(connectionStatus);
        }
        public ActionResult <dasCommandsStructure> Get()
        {
            SmartDASService service;

            try {
                service = new SmartDASService();
                service.Connect();
            } catch (Exception e) {
                return(StatusCode(500, e));
            }

            var dasCommands = new dasCommandsStructure();

            try {
                dasCommands = service.getDASCommands();
            } catch (Exception e) {
                return(StatusCode(500, e));
            }

            service.Disconnect();
            return(dasCommands);
        }
Пример #11
0
        /// <summary>
        /// Attempts to set the PLC network configuration
        /// </summary>
        /// <param name="newConfig"></param>
        /// <param name="attempts"></param>
        /// <returns></returns>
        private plcNetworkConfig setPLCNetworkRecursively(plcNetworkConfig newConfig, int attempts = 0)
        {
            int maxAttempts = 10;

            if (attempts >= maxAttempts)
            {
                throw new Exception("Could not set new plc network config. Exceeded Max Write Attempts");
            }

            string newIP = $"{newConfig.newIP1}.{newConfig.newIP2}.{newConfig.newIP3}.{newConfig.newIP4}";

            Console.WriteLine($"Attempt number {attempts} at setting the PLC to {newIP}");

            // create a new service with a connection to the PLC
            var service = new SmartDASService();

            service.Connect();

            plcNetworkConfig oldConfig = service.getPLCNetwork();

            // Attempt to set the PLC network configuration
            service.setPLCNetwork(newConfig);

            // Disconnect the currently active connection with the PLC
            service.Disconnect();

            // Check that the current configuration is in the same network group as
            // the old configuration. e.g. if the old config is 192.168.1.5 and the new config is 192.168.122.7
            // then do not recursively check if it can access the plc, because the user has to enter the new
            // ip address in their network configuration. if the old config is 192.168.1.5 and the new config
            // is 192.168.1.124, then recursively validate the ip adddress on the plc is correct.

            if (
                oldConfig.newIP1 != newConfig.newIP1 ||
                oldConfig.newIP2 != newConfig.newIP2 ||
                oldConfig.newIP3 != newConfig.newIP3
                )
            {
                return(newConfig);
            }

            // Set the service ip address to the new PLC ip address
            service.IP = newIP;

            // Check the configuration read back from the controller matches the new configuration attempting to be stored

            // Attempt to reconnect to the PLC
            int connectResult = service.Connect();

            // Disconnect the currently active connection with the PLC
            service.Disconnect();

            // Check that the connection returned a non-zero error code
            if (connectResult == 0)
            {
                return(newConfig);
            }
            else
            {
                // Try to set the PLC network again
                return(this.setPLCNetworkRecursively(newConfig, attempts += 1));
            }
        }