Ejemplo n.º 1
0
        public static string LoadModuleFromFile(string moduleFilePath)
        {
            //Get Station object
            Station station = Project.ActiveProject as Station;

            //Check for existance of Module
            if (System.IO.File.Exists(moduleFilePath))
            {
                try
                {
                    RsTask task = station.ActiveTask;
                    if (task != null)
                    {
                        RsIrc5Controller rsIrc5Controller = (RsIrc5Controller)task.Parent;
                        ABB.Robotics.Controllers.Controller controller =
                            new ABB.Robotics.Controllers.Controller(new Guid(rsIrc5Controller.SystemId.ToString()));

                        if (controller != null)
                        {
                            //Request Mastership
                            using (ABB.Robotics.Controllers.Mastership m =
                                       ABB.Robotics.Controllers.Mastership.Request(controller.Rapid))
                            {
                                if (controller.Rapid.ExecutionStatus ==
                                    ABB.Robotics.Controllers.RapidDomain.ExecutionStatus.Stopped)
                                {
                                    //Load Module if Rapid Execution State is stopped
                                    ABB.Robotics.Controllers.RapidDomain.Task vTask = controller.Rapid.GetTask(task.Name);
                                    bool loadResult = vTask.LoadModuleFromFile(moduleFilePath,
                                                                               ABB.Robotics.Controllers.RapidDomain.RapidLoadMode.Replace);
                                    Thread.Sleep(1000);
                                }
                            }
                        }
                    }
                }
                catch (ABB.Robotics.GeneralException gex)
                {
                    Logger.AddMessage(new LogMessage(gex.Message.ToString()));
                }

                catch (Exception ex)
                {
                    Logger.AddMessage(new LogMessage(ex.Message.ToString()));
                }
            }
            return("Loading module: " + moduleFilePath);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 加载控制器上的rapid程序
 /// </summary>
 void loadModule()
 {
     try
     {
         tRob1 = controller.Rapid.GetTask("T_ROB1");
         string filePath = controller.FileSystem.GetRemotePath(listBox2_fileStore.SelectedItem.ToString());
         Console.WriteLine("目录:" + filePath);
         string ProgramFileName = Path.ChangeExtension(filePath, ".mod");
         using (Mastership m = Mastership.Request(controller))
         {
             tRob1.LoadModuleFromFile(Path.GetFileName(filePath), RapidLoadMode.Replace);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "错误");
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads a module on a task from the controllers filesystem.
        /// </summary>
        /// <param name="task"></param>
        /// <param name="filename"></param>
        /// <param name="wipeout"></param>
        /// <returns></returns>
        internal bool LoadModuleFromControllerToTask(ABBTask task, string filename, bool wipeout = true)
        {
            // For the time being, we will always wipe out previous modules on load
            if (wipeout)
            {
                if (ClearAllModules(task) < 0)
                {
                    throw new Exception($"Error clearing modules on task {task.Name}");
                }
            }

            // Load the module
            bool success = false;

            try
            {
                using (Mastership.Request(controller.Rapid))
                {
                    FileSystem fs         = controller.FileSystem;
                    string     remotePath = fs.RemoteDirectory + "/" + REMOTE_BUFFER_DIR;
                    bool       dirExists  = fs.DirectoryExists(REMOTE_BUFFER_DIR);
                    if (!dirExists)
                    {
                        logger.Error($"No directory named {remotePath} found on controller");
                        return(false);
                    }

                    // Loads a Rapid module to the task in the robot controller
                    success = task.LoadModuleFromFile($"{remotePath}/{filename}", RapidLoadMode.Replace);
                }
            }
            catch (Exception ex)
            {
                logger.Debug(ex);
                throw new Exception("ERROR: Could not LoadModuleFromControllerToTask");
            }

            if (success)
            {
                logger.Debug($"Sucessfully loaded {filename} to {task.Name}");
            }

            return(success);
        }
Ejemplo n.º 4
0
        ///// <summary>
        ///// Loads a module to the ABB controller given as a string list of Rapid code lines.
        ///// </summary>
        ///// <param name="module"></param>
        ///// <param name="programName"></param>
        ///// <returns></returns>
        //public bool LoadProgramToController(List<string> module, string programName)
        //{
        //    if (!isConnected)
        //    {
        //        Console.WriteLine("Cannot load program, not connected to controller");
        //        return false;
        //    }

        //    string path = Path.Combine(Path.GetTempPath(), $"Machina_{programName}.mod");

        //    // Modules can only be uploaded to ABB controllers using a file
        //    if (!Machina.IO.SaveStringListToFile(path, module, Encoding.ASCII))  //
        //    {
        //        Console.WriteLine("Could not save module to temp file");
        //        return false;
        //    }
        //    else
        //    {
        //        Console.WriteLine($"Saved {programName} to {path}");
        //    }

        //    if (!LoadFileToDevice(path))
        //    {
        //        Console.WriteLine("Could not load module to controller");
        //        return false;
        //    }

        //    return true;
        //}

        /// <summary>
        /// Loads a module into de controller from a local file.
        /// @TODO: This is an expensive operation, should probably become threaded.
        /// </summary>
        /// <param name="fullPath"></param>
        /// <param name="wipeout"></param>
        /// <returns></returns>
        public bool LoadFileToDevice(string fullPath, bool wipeout = true)
        {
            string extension = Path.GetExtension(fullPath),     // ".mod"
                   filename  = Path.GetFileName(fullPath);      // "Machina_Server.mod"

            if (!_isConnected)
            {
                throw new Exception($"Could not load module '{fullPath}', not connected to controller");
            }

            // check for correct ABB file extension
            if (!extension.ToLower().Equals(".mod"))
            {
                throw new Exception("Wrong file type, must use .mod files for ABB robots");
            }

            // For the time being, we will always wipe out previous modules on load
            if (ClearAllModules() < 0)
            {
                throw new Exception("Error clearing modules");
            }

            // Load the module
            bool success = false;

            try
            {
                using (Mastership.Request(controller.Rapid))
                {
                    // When connecting to a real controller, the reference filesystem
                    // for Task.LoadModuleFromFile() becomes the controller's, so it is necessary
                    // to copy the file to the system first, and then load it.

                    // Create the remoteBufferDirectory if applicable
                    FileSystem fs         = controller.FileSystem;
                    string     remotePath = fs.RemoteDirectory + "/" + REMOTE_BUFFER_DIR;
                    bool       dirExists  = fs.DirectoryExists(REMOTE_BUFFER_DIR);
                    if (!dirExists)
                    {
                        Console.WriteLine("Creating {0} on remote controller", remotePath);
                        fs.CreateDirectory(REMOTE_BUFFER_DIR);
                    }

                    //@TODO: Should implement some kind of file cleanup at somepoint...

                    // Copy the file to the remote controller
                    controller.FileSystem.PutFile(fullPath, $"{REMOTE_BUFFER_DIR}/{filename}", wipeout);
                    Console.WriteLine($"Copied {filename} to {REMOTE_BUFFER_DIR}");

                    // Loads a Rapid module to the task in the robot controller
                    success = tRob1Task.LoadModuleFromFile($"{remotePath}/{filename}", RapidLoadMode.Replace);
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine("ERROR: Could not load module");
                Console.WriteLine(ex);
                throw new Exception("ERROR: Could not load module");
            }

            // True if loading succeeds without any errors, otherwise false.
            if (!success)
            {
                //// Gets the available categories of the EventLog.
                //foreach (EventLogCategory category in controller.EventLog.GetCategories())
                //{
                //    if (category.Name == "Common")
                //    {
                //        if (category.Messages.Count > 0)
                //        {
                //            foreach (EventLogMessage message in category.Messages)
                //            {
                //                Console.WriteLine("Program [{1}:{2}({0})] {3} {4}",
                //                    message.Name, message.SequenceNumber,
                //                    message.Timestamp, message.Title, message.Body);
                //            }
                //        }
                //    }
                //}
            }
            else
            {
                Console.WriteLine("Sucessfully loaded {0}", fullPath);
            }

            return(success);
        }