Ejemplo n.º 1
0
        public IOconfMap(string row, int lineNum) : base(row, lineNum, "Map")
        {
            format = "Map;SerialNo/COM1/USB1-1.1;BoxName;[NodeName];[baud rate]";

            var list = ToList();

            if (list[0] != "Map")
            {
                throw new Exception($"IOconfMap: wrong format: {row} {format}");
            }
            bool isWindows = RpiVersion.IsWindows();

            if (isWindows && list[1].StartsWith("COM"))
            {
                USBPort = list[1];
            }
            else if (!isWindows && list[1].StartsWith("USB"))
            {
                USBPort = "/dev/" + list[1];
            }
            else
            {
                SerialNumber = list[1];
            }

            BoxName = list[2];
            if (list.Count <= 3)
            {
                return;
            }

            string distributedNodeName = list.Count == 5 ? list[3] : default;
            var    baudrate            = 0;

            if (list.Count >= 5 && !int.TryParse(list[4], out baudrate))
            {
                CALog.LogErrorAndConsoleLn(LogID.A, $"Failed to parse the baud rate for the board: {BoxName}. Attempting with defaults.");
            }
            else if (list.Count == 4 && int.TryParse(list[3], out baudrate))
            {
                BaudRate = baudrate;
            }
            else
            {
                distributedNodeName = list[3];
            }

            BaudRate        = baudrate;
            DistributedNode = distributedNodeName != default
                ? IOconfFile.GetEntries <IOconfNode>().SingleOrDefault(n => n.Name == distributedNodeName) ?? throw new Exception($"Failed to find node in configuration for Map: {row}. Format: {format}")
                : !IOconfFile.GetEntries <IOconfNode>().Any() ? DistributedNode : throw new Exception($"The node name is not optional for distributed deployments: {row}. Format: {format}");
        }
        private static void CheckRules()
        {
            // no two rows can have the same type,name combination.
            var groups = Table.GroupBy(x => x.UniqueKey());

            foreach (var g in groups.Where(x => x.Count() > 1))
            {
                CALog.LogErrorAndConsoleLn(LogID.A, $"ERROR in {Directory.GetCurrentDirectory()}\\IO.conf:{Environment.NewLine} Name: {g.First().ToList()[1]} occure {g.Count()} times in this group: {g.First().ToList()[0]}{Environment.NewLine}");
            }

            // no heater can be in several oven areas
            var heaters = GetOven().Where(x => x.OvenArea > 0).GroupBy(x => x.HeatingElement);

            foreach (var heater in heaters.Where(x => x.Select(y => y.OvenArea).Distinct().Count() > 1))
            {
                CALog.LogErrorAndConsoleLn(LogID.A, $"ERROR in {Directory.GetCurrentDirectory()}\\IO.conf:{Environment.NewLine} Heater: {heater.Key.Name} occure in several oven areas : {string.Join(", ", heater.Select(y => y.OvenArea).Distinct())}");
            }
        }
Ejemplo n.º 3
0
 private static void ShowHumanErrorMessages(Exception ex)
 {
     if (ex.Message.StartsWith("account already exist"))
     {
         CALog.LogErrorAndConsoleLn(LogID.A, "Your password was wrong. Please exit and try again..");
         CALog.LogInfoAndConsoleLn(LogID.A, Environment.NewLine + "Press any key to exit");
     }
     else if (ex.Message.StartsWith("Could not find any devices connected to USB"))
     {
         CALog.LogErrorAndConsoleLn(LogID.A, ex.Message + " Please check USB connections and try again..");
         CALog.LogInfoAndConsoleLn(LogID.A, Environment.NewLine + "Press any key to exit");
     }
     else if (ex.InnerException != null && ex.InnerException.Message.Contains("LoopName already used before:"))
     {
         CALog.LogErrorAndConsoleLn(LogID.A, "Please change your Webchart name and try again..");
         CALog.LogInfoAndConsoleLn(LogID.A, Environment.NewLine + "Press any key to exit");
     }
     else
     {
         CALog.LogException(LogID.A, ex);
     }
 }