public Controller ConnectbyGuid(string strGuid)
 {
     try
     {
         if (controller != null)
         {
             controller.Logoff();
             controller.Dispose();
             controller = null;
         }
         ControllerInfo myControllerInfo = null;
         Guid           myGuid           = Guid.Empty;
         if (Guid.TryParse(strGuid, out myGuid))
         {
             networkScanner.TryFind(myGuid, out myControllerInfo);
         }
         else
         {
             throw new Exception("Invalid guid string");
         }
         if (myControllerInfo == null || myControllerInfo.Availability != Availability.Available)
         {
             throw new Exception("Wrong guid string");
         }
         else
         {
             controller = Controller.Connect(myControllerInfo, ConnectionType.Standalone);
             return(controller);
         }
     }
     finally { }
 }
示例#2
0
        /// <summary>
        /// Get Controller from Controller property and axis values.
        /// </summary>
        /// <param name="component">Component that owns the changed property.</param>
        /// <param name="sTasksList">Tasks list delimited by ";".</param>
        /// <returns>Found Controller</returns>
        protected Controller GetController(SmartComponent component)
        {
            Controller controller = null;
            string     guid       = ((string)component.Properties["Controller"].Value).Split(' ')[0];

            if (guid != "")
            {
                Guid systemId = new Guid(guid);

                NetworkScanner scanner = new NetworkScanner();
                if (scanner.TryFind(systemId, TimeSpan.FromSeconds(60), 1, out ControllerInfo controllerInfo))
                {
                    controller = ControllerFactory.CreateFrom(controllerInfo);                    //new Controller(systemId);
                    if (controller.SystemId == systemId)
                    {
                        if (controller.Connected)
                        {
                            int iCtrlMechCount = controller.MotionSystem.MechanicalUnits.Count;
                            component.Properties["CtrlMechanism"].Attributes["MaxValue"] = iCtrlMechCount.ToString();
                            if (iCtrlMechCount == 1)
                            {
                                component.Properties["CtrlMechanism"].UIVisible = false;
                                component.Properties["CtrlMechanism"].Value     = 1;
                            }
                            else
                            {
                                component.Properties["CtrlMechanism"].UIVisible = true;
                            }

                            try
                            {
                                UpdateAxis(component, controller);
                            }
                            catch (ABB.Robotics.GenericControllerException)
                            { }
                        }
                    }
                }
                else
                {
                    //Try to connect controller later with OnControlerAdded
                }
            }
            else
            {
                component.Properties["Status"].Value = "Disconnected";
            }
            return(controller);
        }