Sync DataDeclaration
This example provides information to synchronize data declaration like tool, workobjects onto virtual controller. An active Station is required for this example.
You need to pass the RsTask and Irc5Controller as parameters. To check the result of the addin, ensure that the data appears in Offline tab of RobotStudio in a module.
Use this procedure to Synchronize Data:
Get virtual Controller Instance based on Rs
Irc5Controller object's SystemId .Request for RAPID Mastership from controller.
If granted then call Sync
Data(string, Sync Instance method of RsTask type for synchronize to controller.Direction, List<Sync Log Message>)
Solution
Get virtual controller Instance based on RsIrc5Controller object's SystemId.
ABB.Robotics.Controllers.Controller controller = new ABB.Robotics.Controllers.Controller(new Guid(rsIrc5Controller.SystemId.ToString()));
Request for RAPID Mastership from controller.
using (ABB.Robotics.Controllers.Mastership m = ABB.Robotics.Controllers.Mastership.Request(controller.Rapid))
If granted then call SyncData Instance method of RsTask type for synchronize to controller.
task.SyncData(dd.ModuleName + "/" + dd.Name, SyncDirection.ToController, new System.Collections.Generic.List<SyncLogMessage>());
Example
This example provides information to synchronize data declaration like tool, workobjects to virtual controller.
private static bool SyncDataDeclaration(RsTask task, RsIrc5Controller rsIrc5Controller)
{
Project.UndoContext.BeginUndoStep("SyncDataDeclaration");
try
{
//Get virtual controller instance from rsIrc5Controller
ABB.Robotics.Controllers.Controller controller =
new ABB.Robotics.Controllers.Controller(new Guid(rsIrc5Controller.SystemId.ToString()));
foreach (RsDataDeclaration dd in task.DataDeclarations)
{
if (dd is RsToolData || dd is RsWorkObject)
{
if (!dd.Name.Equals("tool0") && !dd.Name.Equals("wobj0"))
{
//Request for Mastership from controller
//If granted then call SyncData instance method of RsTask
using (ABB.Robotics.Controllers.Mastership m =
ABB.Robotics.Controllers.Mastership.Request(controller.Rapid))
{
try
{
dd.Synchronize = true;
//Synchronize
task.SyncData(dd.ModuleName + "/" + dd.Name,
SyncDirection.ToController,
new System.Collections.Generic.List<SyncLogMessage>());
}
catch (System.Exception)
{
return false;
}
}
}
}
}
}
catch (Exception ex)
{
Logger.AddMessage(new LogMessage(ex.Message.ToString()));
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
}
finally
{
Project.UndoContext.EndUndoStep();
}
return true;
}
Required Namespaces
ABB.
ABB.