RobotStudio event

GetDirectory exception PC-SDK

Options
mrogerf
mrogerf
edited January 2015 in Developer Tools
Hello.

I develop this small program  to create a backup and copy it to PC, but I get the following exception when calling GetDirectory : Operation is not valid due the current state of the object.

The code is bellow:

Thanks for any help
=======================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ABB.Robotics;
using ABB.Robotics.Controllers;
using ABB.Robotics.Controllers.Discovery;
using ABB.Robotics.Controllers.RapidDomain;
using ABB.Robotics.Controllers.FileSystemDomain;

namespace abbirc5
{
    class Program
    {
        static void Main(string[] args)
        {   if (args.Length > 0) {
                bool bControllerFound = false;

                System.Console.WriteLine("IP requested: " + args[0]);
                NetworkScanner netscanner = new NetworkScanner();
                NetworkScanner.AddRemoteController(args[0]);

                netscanner.Scan();
                System.Threading.Thread.Sleep(4000);
                netscanner.Scan(); 
                ControllerInfoCollection controllers = netscanner.Controllers;
                
                foreach (ControllerInfo controllerInfo in controllers) {
                    if (controllerInfo.IPAddress.ToString() == args[0]) {
                        bControllerFound = true;
                        System.Console.WriteLine("System found: " + controllerInfo.Id + " :: " + controllerInfo.IPAddress.ToString());

                        if (controllerInfo.Availability == Availability.Available) {
                            Controller controller = ControllerFactory.CreateFrom(controllerInfo);
                            controller.Logon(UserInfo.DefaultUser);
                            
                            System.Console.WriteLine("Controller logged");
                            
                            //do backup
                            controller.BackupCompleted += new EventHandler<BackupEventArgs>(controller_BackupCompleted);
                            controller.Backup("/hd0a/temp/backup");
                            
                            do {
                                System.Console.Write(".");
                                System.Threading.Thread.Sleep(1000);
                            } while (controller.BackupInProgress);

                            controller.FileSystem.RemoteDirectory = "/hd0a/temp";
                            controller.FileSystem.LocalDirectory = ".";
                            controller.FileSystem.GetDirectory("backup");
                            System.Console.WriteLine("1:Transfer succeced:"+controllerInfo.Id);
                            
                            //finish connection
                            controller.Logoff();
                            controller.Dispose();
                        }
                        else
                            System.Console.WriteLine("0:Controller found but it is not avaiable");

                    }
                }

                if (!bControllerFound)
                    System.Console.WriteLine("0:Controller not found");

            }
            else
                System.Console.WriteLine("0:Lacks argument");
        }

        static void controller_BackupCompleted(object sender, BackupEventArgs e)
        {   if (e.Succeeded)
                System.Console.WriteLine("1:Backup done");
            else
                System.Console.WriteLine("0:Backup error");
        }
    }
}


Tagged:

Comments

  • Armandb
    Options
                                controller.FileSystem.GetDirectory("backup");
    Are you sure it's backup folder ?