Example #1
0
        /// <summary>
        /// Load the preset position file of the specified logical motion controller by the file name
        /// </summary>
        /// <param name="LogicalMotionController"></param>
        /// <param name="FileName"></param>
        public MassMoveArgs LoadProfile(LogicalMotionComponent MotionComponent, string FileName)
        {
            // the full file path where we should find the preset profiles
            var fullFilePath = PRESET_FOLDER + "\\" + MotionComponent.GetHashString() + "\\" + FileName + ".json";

            if (File.Exists(fullFilePath) == true)
            {
                var json = File.ReadAllText(fullFilePath, new UTF8Encoding());

                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.Converters.Add(new MassMoveArgsConverter());
                var args = JsonConvert.DeserializeObject <MassMoveArgs>(json, new MassMoveArgsConverter());

                if (args.LogicalMotionComponent != MotionComponent.GetHashString())
                {
                    throw new FormatException("it does not match with the selected motion component.");
                }
                else if (args.HashString != args.GetHashString())
                {
                    throw new FormatException("it might be modified unexpectedly.");
                }
                else
                {
                    return(args);
                }
            }
            else
            {
                // the folder does not exist
                throw new FileNotFoundException($"{fullFilePath} does not exist.");
            }
        }
Example #2
0
        private bool CheckProfileExistance(LogicalMotionComponent MotionComponent, string FileName)
        {
            // the full file path where we should find the preset profiles
            var fullFilePath = PRESET_FOLDER + "\\" + MotionComponent.GetHashString() + "\\" + FileName + ".json";

            return(File.Exists(fullFilePath));
        }
Example #3
0
        /// <summary>
        /// Save the preset position profile
        /// </summary>
        /// <param name="Args"></param>
        /// <param name="FileName"></param>
        private void SaveProfile(LogicalMotionComponent MotionComponent, MassMoveArgs Args, string FileName)
        {
            if (MotionComponent == null)
            {
                throw new InvalidDataException("the logical motion controller is empty.");
            }

            if (FileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                throw new InvalidDataException("the name of profile contains invalid chars.");
            }

            // if the directory does not exist, create it.
            var dir = PRESET_FOLDER + "\\" + MotionComponent.GetHashString();

            if (Directory.Exists(dir) == false)
            {
                Directory.CreateDirectory(dir);
            }

            // the full file path where we should find the preset profiles
            var fullFilePath = PRESET_FOLDER + "\\" + MotionComponent.GetHashString() + "\\" + FileName + ".json";

            // calculate the hash string which is used to check whether the profile is modified
            Args.HashString = Args.GetHashString();

            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.Converters.Add(new MassMoveArgsConverter());
            var json = JsonConvert.SerializeObject(Args, settings);

            File.WriteAllText(fullFilePath, json, new UTF8Encoding());

            // reload the position preset profile list
            LoadProfilesList(MotionComponent);
        }
Example #4
0
        /// <summary>
        /// load the current positions of the specified logical motion component
        /// </summary>
        /// <param name="MotionComponent"></param>
        /// <returns></returns>
        private MassMoveArgs LoadCurrentPositions(LogicalMotionComponent MotionComponent)
        {
            // generate the move args list to bind to the window
            MassMoveArgs arg = new MassMoveArgs()
            {
            };

            foreach (var laxis in MotionComponent)
            {
                var a = laxis.MoveArgs.Clone() as AxisMoveArgs;
                a.Distance   = laxis.PhysicalAxisInst.UnitHelper.RelPosition;
                a.IsMoveable = true;
                a.MoveOrder  = 1;
                arg.Add(a);
            }

            arg.LogicalMotionComponent = MotionComponent.GetHashString();

            return(arg);
        }
Example #5
0
        /// <summary>
        /// Load the profiles which belong to the selected logical motion component
        /// </summary>
        /// <returns></returns>
        private void LoadProfilesList(LogicalMotionComponent MotionComponent)
        {
            var dir = PRESET_FOLDER + "\\" + MotionComponent.GetHashString();

            if (Directory.Exists(dir))
            {
                List <string> profiles = new List <string>();

                DirectoryInfo info = new DirectoryInfo(dir);
                foreach (var file in info.GetFiles())
                {
                    if (file.Extension == ".json")
                    {
                        profiles.Add(Path.GetFileNameWithoutExtension(file.FullName));
                    }
                }

                ProfileList = profiles.ToArray();
            }
            else
            {
                ProfileList = null;
            }
        }