// 声明一个私有变量 动态创建扫描接口 创建与控制器的连接 public void DynamicCreation() { // 建立一个扫描接口的 引用变量 networkScanner NetworkScanner networkScanner = new NetworkScanner(); // 扫描接口 虚拟接口还是实际接口 条件运算符 ControllerInfo[] controllers = networkScanner.GetControllers(chooseSocket ? NetworkScannerSearchCriterias.Virtual : NetworkScannerSearchCriterias.Real); // 发现控制器后 if (controllers.Length > 0) { // 确认controller 包含哪些信息 Console.WriteLine(controllers); // 提取controller中的第默认序列第一的信息 ABBControllerinfo = controllers[0]; Console.WriteLine(ABBControllerinfo); // 根据控制器的信息创建一个实例 并且可以输出 其基本信息 ABBController = ControllerFactory.CreateFrom(ABBControllerinfo); Console.WriteLine($"Found one ABB.System Name is:{SystemName} System ID is:{SystemID} System IP is:{SystemIP}"); // $ 起到一个占位符的作用内容包含在 {} 中,可以用于获取{}中对应内容的信息 } else { MessageBox.Show("No ABB Robot Found."); } }
public LogEditor() { NetworkScanner netScan = new NetworkScanner(); netScan.Scan(); ctrlInfo = netScan.GetControllers(); foreach (var i in ctrlInfo) { if (i.SystemName.ToString() == "2600-109425") // ABB IRC5 Controller number 26-00268, 4600-800484 { aController = new Controller(i); } } // can be used like this, if you know which controller inside of ctrlInfo[] array. //aController = new Controller(ctrlInfo[0]); // using ControllerInfoCollection cntInfoColl - //cntInfoColl = netScan.Controllers; log = aController.EventLog; Console.WriteLine($"Application is running."); aController.EventLog.MessageWritten += _errorEventHappened; Console.ReadLine(); }
public void DynamicCreation() { // ABB 自带接口扫描类 NetworkScanner networkScanner = new NetworkScanner(); // 条件运算符 获取控制器类型 ControllerInfo[] controllers = networkScanner.GetControllers(chooseSocket ? NetworkScannerSearchCriterias.Virtual : NetworkScannerSearchCriterias.Real); if (controllers.Length > 0) { Console.WriteLine(controllers); // 获取控制器信息 ABBControllerInfo = controllers[0]; // 根据控制器信息 船舰实例 ABBController = ControllerFactory.CreateFrom(ABBControllerInfo); Console.WriteLine($"Found one ABB.System Name is:{SystemName} System ID is:{SystemID} System IP is:{SystemIP}"); // $ 起到一个占位符的作用内容包含在 {} 中,可以用于获取{}中对应内容的信息,避免了利用{0}的形式占位。 以前占位符 需要 {0} 和 变量 配合使用 } else { MessageBox.Show("No ABB Robot Found!"); } }
/// <summary> /// Searches the network for a robot controller and establishes a connection with the specified one by position. /// Performs no LogOn actions or similar. /// </summary> /// <returns></returns> private bool LoadController(int controllerID) { // Scan the network and hookup to the specified controller bool success = false; // This is specific to ABB, should become abstracted at some point... logger.Verbose("Scanning the network for controllers..."); NetworkScanner scanner = new NetworkScanner(); ControllerInfo[] controllers = scanner.GetControllers(); if (controllers.Length > 0) { int cId = controllerID > controllers.Length ? controllers.Length - 1 : controllerID < 0 ? 0 : controllerID; controller = ControllerFactory.CreateFrom(controllers[cId]); if (controller != null) { //isConnected = true; logger.Verbose($"Found controller {controller.SystemName} on {controller.Name}"); success = true; logger.Debug(controller); //Console.WriteLine(controller.RobotWare); //Console.WriteLine(controller.RobotWareVersion); //try //{ // this.robotWare = this.controller.RobotWare; // this.robotWareOptions = this.robotWare.Options; // this._hasMultiTasking = HasMultiTaskOption(this.robotWareOptions); // this._hasEGM = HasEGMOption(this.robotWareOptions); //} //catch //{ // Console.WriteLine("Could not access ROBOTWARE options"); //} } else { logger.Debug("Could not connect to controller..."); } } else { logger.Debug("No controllers found on the network"); } //if (!success) //{ // Disconnect(); // //throw new Exception("ERROR: could not LoadController()"); //} return(success); }
private void Scan(object sender, object e) { //Reset Controllers if (controllers != null) { foreach (var controller in controllers) { controller.LogOff(); } controllers = new List <Controller>(); } // Find ABB robots on the network NetworkScanner scanner = new NetworkScanner(); scanner.Scan(); if (ipAddresses != null) { // Scan the network for controllers and add them to our controller array. foreach (string ip in ipAddresses) { NetworkScanner.AddRemoteController(ip); } } ControllerInfo[] controllersID = scanner.GetControllers(); foreach (ControllerInfo id in controllersID) { controllers.Add(new AbbIRC5Contoller(id)); } // Possibility to scan for other robots // Allow value list to be updated updateVL = true; if (controllers != null) { if (controllers.Count > 0) { log.Add("Controllers found:"); // List the controller names that were found on the network. for (int i = 0; i < controllers.Count; i++) { log.Add(controllers[i].Name); } } else { log.Add("Scan timed out. No controllers were found."); } } ExpireSolution(true); }
static Controller CreateController() { NetworkScanner scanner = new NetworkScanner(); ControllerInfo[] controllers = scanner.GetControllers(NetworkScannerSearchCriterias.Virtual); if (controllers.Length > 0) { Controller dynamic = ControllerFactory.CreateFrom(controllers[0]); return(dynamic); } return(null); }
public void getControllers(NetworkScanner scanner) { if (scanner != null) { networkScanner = scanner; controllerInfos = scanner.GetControllers(); foreach (var controller in controllerInfos) { TestContrall(controller); } } }
public Controller RAB_ConnectToRob() { // scanning the network for the controllers NetworkScanner netScan = new NetworkScanner(); // getting all available controllers from the network ctrlInfo = netScan.GetControllers(); // can be used like this, if you know which controller inside of ctrlInfo[] array. aController = new Controller(ctrlInfo[0]); return(aController); }
static void Main(string[] args) { NetworkScanner scanner = new NetworkScanner(); ControllerInfo[] controllers = scanner.GetControllers(NetworkScannerSearchCriterias.Virtual); foreach (ControllerInfo c in controllers) { TestController(c); } Console.WriteLine("Press any key to terminate"); Console.ReadKey(); }
private void ABBDiscovery() { NetworkScanner networkScanner = new NetworkScanner(); networkScanner.Scan(); ControllerInfo[] controllerInfos = networkScanner.GetControllers(chooseSocket ? NetworkScannerSearchCriterias.Virtual : NetworkScannerSearchCriterias.Real); if (controllerInfos.Length > 0) { Console.WriteLine($"当前online {controllerInfos.Length} 个ABB机器人"); ABBControllerInfo = controllerInfos[0]; ABBController = ControllerFactory.CreateFrom(ABBControllerInfo); // 利用反射方式创建controller实例 Console.WriteLine($"Found one ABB.System Name is:{abbSystemName} System ID is:{abbSystemID} System IP is:{abbSystemIP}"); } else { Console.WriteLine("没有扫描到Online的机器人!"); } }
// Additional methods #region additional methods /// <summary> /// Get the controller /// </summary> /// <returns> The picked controller. </returns> private Controller GetController() { // Initiate and clear variables _controllerInstance.Clear(); ControllerInfo[] controllers; List <string> controllerNames = new List <string>() { }; // Scan for a network with controller NetworkScanner scanner = new NetworkScanner(); scanner.Scan(); // Try to get the controllers from the netwerok try { controllers = scanner.GetControllers(); } // Else return no controllers catch (Exception) { controllers = null; } // Get the names of all the controllers in the scanned network for (int i = 0; i < controllers.Length; i++) { _controllerInstance.Add(Controller.Connect(controllers[i], ConnectionType.Standalone)); controllerNames.Add(_controllerInstance[i].Name); } // Automatically pick the controller when one controller is available. if (controllerNames.Count == 1) { _pickedIndex = 0; } // Display the form and let the user pick a controller when more then one controller is available. else if (controllerNames.Count > 1) { // Display the form and return the index of the picked controller. _pickedIndex = DisplayForm(controllerNames); // Return a null value when the picked index is incorrect. if (_pickedIndex < 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No Station picked from menu!"); return(null); } } // Return a null value when no controller was found else { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No Station found!"); return(null); } // Select the picked controller return(_controllerInstance[_pickedIndex]); }
public void ScannNow() { NetScan = new NetworkScanner(); NetScan.Scan(); CtrlInfo = NetScan.GetControllers(); } // end of ScannNow method
protected override void SolveInstance(IGH_DataAccess DA) { bool activate = false; bool scan = false; bool kill = false; bool clear = false; string ip = System.String.Empty; int index = 0; bool connect = false; bool resetPP = false; bool begin = false; bool stop = false; bool monitorTCP = false; bool monitorIO = false; bool stream = false; Target targ = null; if (!DA.GetData(0, ref activate)) { ; } if (!DA.GetData(1, ref scan)) { ; } if (!DA.GetData(2, ref kill)) { ; } if (!DA.GetData(3, ref clear)) { ; } if (!DA.GetData(4, ref ip)) { ; } if (!DA.GetData(5, ref index)) { ; } if (!DA.GetData(6, ref connect)) { ; } if (!DA.GetData(7, ref resetPP)) { ; } if (!DA.GetData(8, ref begin)) { ; } if (!DA.GetData(9, ref stop)) { ; } if (!DA.GetData(10, ref monitorTCP)) { ; } if (!DA.GetData(11, ref monitorIO)) { ; } if (!DA.GetData(12, ref stream)) { ; } if (!DA.GetData(13, ref targ)) { ; } this.controllerIndex = index; this.start = begin; double cRobX = 0; double cRobY = 0; double cRobZ = 0; double cRobQ1 = 0; double cRobQ2 = 0; double cRobQ3 = 0; double cRobQ4 = 0; Quaternion cRobQuat = new Quaternion(); //Check for valid licence /*if (bool (Core.AuthTest.loggedIn) != true) * { * new GH_RuntimeMessage("Please sign in to confirm your licence", GH_RuntimeMessageLevel.Error); * return; * }*/ if (activate) { if (scan) { // Scan the network for controllers and add them to our controller array scanner.Scan(); controllers = scanner.GetControllers(); if (controllers.Length > 0) { log.Add("Controllers found:"); // List the controller names that were found on the network. for (int i = 0; i < controllers.Length; i++) { log.Add(controllers[i].ControllerName); } } else { log.Add("Scan timed out. No controllers were found."); } } if (kill && controller != null) { controller.Logoff(); controller.Dispose(); controller = null; log.Add("Process killed! Abandon ship!"); } if (clear) { log.Clear(); log.Add("Log cleared."); } if (connect) { if (controller == null && controllers.Length > 0) { string controllerID = controllers[index].ControllerName; log.Add("Selected robot controller: " + controllers[index].ControllerName + "."); if (controllers[index].Availability == Availability.Available) { log.Add("Robot controller " + controllers[index].ControllerName + " is available."); if (controller != null) { controller.Logoff(); controller.Dispose(); controller = null; } controller = ControllerFactory.CreateFrom(controllers[index]); controller.Logon(UserInfo.DefaultUser); log.Add("Connection to robot controller " + controller.SystemName + " established."); // Get T_ROB1 queue to send messages to the RAPID task. if (!controller.Ipc.Exists("RMQ_T_ROB1")) { controller.Ipc.CreateQueue("RMQ_T_ROB1", 10, Ipc.MaxMessageSize); } tasks = controller.Rapid.GetTasks(); IpcQueue robotQueue = controller.Ipc.GetQueue("RMQ_T_ROB1"); int queueID = robotQueue.QueueId; string queueName = robotQueue.QueueName; log.Add("Established RMQ for T_ROB1 on network controller."); log.Add("Rapid Message Queue ID:" + queueID.ToString() + "."); log.Add("Rapid Message Queue Name:" + queueName + "."); RobotQueue = robotQueue; } else { log.Add("Selected controller not available."); } ControllerID = controllerID; } else { if (controller != null) { return; } else { string exceptionMessage = "No robot controllers found on network."; ControllerID = "No Controller"; log.Add(exceptionMessage); } } } if (resetPP && controller != null) { using (Mastership m = Mastership.Request(controller.Rapid)) { // Reset program pointer to main. tasks[0].ResetProgramPointer(); log.Add("Program pointer set to main on the active task."); } } if (begin) { // Execute robot tasks present on controller. try { if (controller.OperatingMode == ControllerOperatingMode.Auto) { using (Mastership m = Mastership.Request(controller.Rapid)) { // Perform operation. tasks[0].Start(); log.Add("Robot program started on robot " + controller.SystemName + "."); } } else { log.Add("Automatic mode is required to start execution from a remote client."); } } catch (System.InvalidOperationException ex) { log.Add("Mastership is held by another client." + ex.Message); } catch (System.Exception ex) { log.Add("Unexpected error occurred: " + ex.Message); } } if (stop) { try { if (controller.OperatingMode == ControllerOperatingMode.Auto) { using (Mastership m = Mastership.Request(controller.Rapid)) { // Stop operation. tasks[0].Stop(StopMode.Immediate); log.Add("Robot program stopped on robot " + controller.SystemName + "."); } } else { log.Add("Automatic mode is required to stop execution from a remote client."); } } catch (System.InvalidOperationException ex) { log.Add("Mastership is held by another client." + ex.Message); } catch (System.Exception ex) { log.Add("Unexpected error occurred: " + ex.Message); } } // If active, update the status of the TCP. if (monitorTCP) { if (tcpMonitoringOn == 0) { log.Add("TCP monitoring started."); } cRobTarg = tasks[0].GetRobTarget(); cRobX = Math.Round(cRobTarg.Trans.X, 3); cRobY = Math.Round(cRobTarg.Trans.Y, 3); cRobZ = Math.Round(cRobTarg.Trans.Z, 3); Point3d cRobPos = new Point3d(cRobX, cRobY, cRobZ); cRobQ1 = Math.Round(cRobTarg.Rot.Q1, 5); cRobQ2 = Math.Round(cRobTarg.Rot.Q2, 5); cRobQ3 = Math.Round(cRobTarg.Rot.Q3, 5); cRobQ4 = Math.Round(cRobTarg.Rot.Q4, 5); cRobQuat = new Quaternion(cRobQ1, cRobQ2, cRobQ3, cRobQ4); tcp = Util.QuaternionToPlane(cRobPos, cRobQuat); tcpMonitoringOn += 1; tcpMonitoringOff = 0; } else if (tcpMonitoringOn > 0) { if (tcpMonitoringOff == 0) { log.Add("TCP monitoring stopped."); } tcpMonitoringOff += 1; tcpMonitoringOn = 0; } // If active, update the status of the IO system. if (monitorIO) { if (ioMonitoringOn == 0) { log.Add("Signal monitoring started."); } // Filter only the digital IO system signals. IOFilterTypes dSignalFilter = IOFilterTypes.Common; SignalCollection dSignals = controller.IOSystem.GetSignals(dSignalFilter); IOstatus.Clear(); // Iterate through the found collection and print them to the IO monitoring list. foreach (Signal signal in dSignals) { string sigVal = signal.ToString() + ": " + signal.Value.ToString(); IOstatus.Add(sigVal); } ioMonitoringOn += 1; ioMonitoringOff = 0; } else if (ioMonitoringOn > 0) { if (ioMonitoringOff == 0) { log.Add("Signal monitoring stopped."); } ioMonitoringOff += 1; ioMonitoringOn = 0; } if (stream) { if (targ != null) { IpcMessage message = new IpcMessage(); pos.X = (float)targ.Position.X; pos.Y = (float)targ.Position.Y; pos.Z = (float)targ.Position.Z; ori.Q1 = targ.Quaternion.A; ori.Q2 = targ.Quaternion.B; ori.Q3 = targ.Quaternion.C; ori.Q4 = targ.Quaternion.D; pose.Trans = pos; pose.Rot = ori; string content = "SD;[" + "\"Linear\"," + pos.ToString() + "," + ori.ToString() + "," + pose.ToString() + "]"; byte[] data = new UTF8Encoding().GetBytes(content); message.SetData(data); RobotQueue.Send(message); } } // Output the status of the connection. Status = log; DA.SetDataList(0, log); DA.SetDataList(1, IOstatus); DA.SetData(2, new GH_Plane(tcp)); ExpireSolution(true); } }