/// <summary>
        /// Sends program to manipulator
        /// </summary>
        /// <param name="program"></param>
        public async void UploadProgram(Program program)
        {
            if (!manipulator.Connected)
            {
                return;
            }
            try
            {
                manipulator.Number(program.Name);
                await Task.Delay(1000);

                manipulator.New();
                await Task.Delay(1000);

                var lines = program.GetLines();

                for (var i = 0; i < lines.Count; i++)
                {
                    await Task.Delay(500);

                    manipulator.SendCustom(lines[i]);
                    StepUpdate?.Invoke(this, new NotificationEventArgs("Uploading program", i + 1,
                                                                       lines.Count, EventType.LINE_UPLOADED));
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
        /// <summary>
        /// Receives all programs downloaded from manipulator
        /// </summary>
        /// <returns></returns>
        public async Task <List <Program> > DownloadPrograms(List <RemoteProgram> remotePrograms)
        {
            var programs = new List <Program>();

            for (var i = 0; i < remotePrograms.Count; i++)
            {
                programs.Add(await DownloadProgram(remotePrograms[i]));
                StepUpdate?.Invoke(this, new NotificationEventArgs("Downloading programs", i + 1,
                                                                   remotePrograms.Count, EventType.PROGRAM_DOWNLOADED));
            }
            return(programs);
        }
        /// <summary>
        /// Sends program to manipulator
        /// </summary>
        /// <param name="program"></param>
        public async void UploadProgram()
        {
            var dialog = new OpenFileDialog
            {
                DefaultExt = ".txt",
                Filter     = "txt files (.txt)|*.txt"
            };

            // Default file name
            // Default file extension
            // Filter files by extension

            if (dialog.ShowDialog() == false)
            {
                return;
            }

            var path  = dialog.FileName;
            var name  = Path.GetFileNameWithoutExtension(path);
            var lines = File.ReadAllLines($"{dialog.FileName}");

            if (!manipulator.Connected)
            {
                return;
            }
            try
            {
                manipulator.Number(name);
                await Task.Delay(1000);

                manipulator.New();
                await Task.Delay(1000);

                for (var i = 0; i < lines.Length; i++)
                {
                    await Task.Delay(500);

                    //var prefix = $"{Convert.ToString(i + 1)} ";
                    manipulator.SendCustom(lines[i]);
                    StepUpdate?.Invoke(this, new NotificationEventArgs("Uploading program", i + 1, lines.Length, EventType.LINE_UPLOADED));
                    Debug.WriteLine($"{i + 1}/{lines.Length}, {lines[i]}");
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
                Debug.WriteLine(ex.Message);
            }
        }
예제 #4
0
        /// <summary>
        /// Receives all programs downloaded from manipulator
        /// </summary>
        /// <returns></returns>
        public async Task <List <Program> > DownloadPrograms(List <RemoteProgram> remotePrograms, CancellationToken cancellationToken)
        {
            var programs = new List <Program>();

            for (var i = 0; i < remotePrograms.Count; i++)
            {
                try
                {
                    cancellationToken.ThrowIfCancellationRequested();
                }
                catch (OperationCanceledException)
                {
                    break;
                }

                programs.Add(await DownloadProgram(remotePrograms[i], cancellationToken));
                StepUpdate?.Invoke(this, new NotificationEventArgs("Downloading programs", i + 1,
                                                                   remotePrograms.Count, EventType.PROGRAM_DOWNLOADED));
            }
            return(programs);
        }
예제 #5
0
        /// <summary>
        /// Sends program to manipulator
        /// </summary>
        /// <param name="program">Program to be uploaded to manipulator</param>
        /// <param name="cancellationToken">Defines task cancellation operation</param>
        public async Task UploadProgram(Program program, CancellationToken cancellationToken)
        {
            if (!manipulator.Connected)
            {
                return;
            }
            try
            {
                manipulator.Number(program.Name);
                await Task.Delay(1000, cancellationToken);

                manipulator.New();
                await Task.Delay(1000, cancellationToken);

                var lines = program.GetLines();

                for (var i = 0; i < lines.Count; i++)
                {
                    await Task.Delay(500, cancellationToken);

                    cancellationToken.ThrowIfCancellationRequested();

                    manipulator.SendCustom(lines[i]);
                    StepUpdate?.Invoke(this, new NotificationEventArgs("Uploading program", i + 1,
                                                                       lines.Count, EventType.LINE_UPLOADED));
                }
            }
            catch (OperationCanceledException)
            {
                // Cancellation does not require handling as method returns immediately after catch clause
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }