Modify value of a num in module with C#
ko414du4
✭
Hi all,
I am trying to read a num data from MainModule.mod, modify it in C# and send it back to MainModule.mod.
So far I have succeeded in reading the num data, modifying it in C#, but not sending it back. How do I send the modified value back to MainModule.mod.
Any thoughts deeply appreciated.
I am trying to read a num data from MainModule.mod, modify it in C# and send it back to MainModule.mod.
So far I have succeeded in reading the num data, modifying it in C#, but not sending it back. How do I send the modified value back to MainModule.mod.
Any thoughts deeply appreciated.
Tagged:
0
Best Answer
-
See the following examples (make sure you defined your Rapid variable as PERS):
<div>MODULE MainModule </div><div> </div><div> PERS num Value := 4; </div><div> </div><div>ENDMODULE </div>
<div>using System; </div><div>using ABB.Robotics.Controllers; </div><div>using ABB.Robotics.Controllers.Discovery; </div><div>using ABB.Robotics.Controllers.RapidDomain; </div><div><br></div><div>namespace PCSDKTest2 </div><div>{ </div><div> class Program </div><div> { </div><div> static void Main(string[] args) </div><div> { </div><div> // variables </div><div> NetworkScanner ns; </div><div> Controller c; </div><div> Task t; </div><div> Module m; </div><div> RapidData r; </div><div> Num v; </div><div><br></div><div> // scan network </div><div> ns = new NetworkScanner(); </div><div> ns.Scan(); </div><div><br></div><div> // get first found controller </div><div> if (ns.Controllers.Count > 0) </div><div> { </div><div> try </div><div> { </div><div> // create the controller </div><div> c = new Controller(ns.Controllers[0]); </div><div> if (c != null) </div><div> { </div><div> // log on </div><div> c.Logon(UserInfo.DefaultUser); </div><div><br></div><div> // request mastership </div><div> using (Mastership ms = Mastership.Request(c.Rapid)) </div><div> { </div><div> try </div><div> { </div><div> // get task </div><div> t = c.Rapid.GetTask("T_ROB1"); </div><div> if (t != null) </div><div> { </div><div> // get module </div><div> m = t.GetModule("MainModule"); </div><div> if (m != null) </div><div> { </div><div> // get variable </div><div> r = m.GetRapidData("Value"); </div><div> if (r != null) </div><div> { </div><div> // read value </div><div> v = (Num)r.Value; </div><div><br></div><div> // increase value </div><div> v = new Num(v.Value + 1); </div><div><br></div><div> // save value </div><div> r.Value = v; </div><div> } </div><div><br></div><div> // dispose module </div><div> m.Dispose(); </div><div> } </div><div><br></div><div> // dispose task </div><div> t.Dispose(); </div><div> } </div><div> } </div><div> catch (Exception) { } </div><div> } </div><div><br></div><div> // log off </div><div> c.Logoff(); </div><div><br></div><div> // dispose controller </div><div> c.Dispose(); </div><div> } </div><div> } </div><div> catch(Exception) { } </div><div> } </div><div> } </div><div> } </div><div>} </div>
5
Answers
-
Hi John_Verheij,
Spot on! Thanks that works..0
Categories
- All Categories
- 5.5K RobotStudio
- 395 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 249 ScreenMaker
- 2.7K Robot Controller
- 310 IRC5
- 59 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 785 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 4 Job listings