Write to RAPID variable from C# PC SDK
in RobotStudio
Hello, i'am trying to write to the RAPID variable from my PC SDK App written on C# (Visual Studio 2017).
Here is a piece my code where the problem occurs:
double val;
double val;
RapidData rd = this.controller.Rapid.GetRapidData("T_ROB1", "Module1", "val_try");
if (rd.Value is ABB.Robotics.Controllers.RapidDomain.Dnum)
{
val = (ABB.Robotics.Controllers.RapidDomain.Dnum)rd.Value;
val = 1.25;
using (Mastership.Request(this.controller.Rapid))
{
rd.Value = val; //here I have an error which says that it is not possible to convert the type double to 'ABB.Robotics.Controllers.IRapidData'
}
}
I have tried this with a bool variable and it works fine, but Ido not understand how to change the number value from C# in RAPID code running on the controller.
Thanks in advance,
Nazar
I have tried this with a bool variable and it works fine, but Ido not understand how to change the number value from C# in RAPID code running on the controller.
Thanks in advance,
Nazar
0
Comments
-
Hello,
Have you tried searching the forum before writing your post?
I did a quick search and found this post: https://forums.robotstudio.com/discussion/comment/22811#Comment_22811
Is it perhaps all you need?—Maxim RiabichevPC Software Support Engineer1 -
Hi,
Dnum is structure so casting or setting directly the value won't work.
You can fill the Dum from string like followingDnum dn = new Dnum();dn.FillFromString(newValue);_rapidData.Value = dn;
or at Dnum constructor give the double value, so no need to fill from string. (Like: Dnum dn = new Dnum(val);)
There is also method dn.FillFromDnum(val) but don't use it as documentation said it is obsolete
Mika1 -
Hello Maxim and Mika, first of all thanks for your answer.Maxim Riabichev said:Hello,
Have you tried searching the forum before writing your post?
I did a quick search and found this post: https://forums.robotstudio.com/discussion/comment/22811#Comment_22811
Is it perhaps all you need?
I have already used API from the link like a base for my code project, and finally, after modifying some assignments I have solved the problem of writing on variables.msalminen said:Hi,
Dnum is structure so casting or setting directly the value won't work.
You can fill the Dum from string like followingDnum dn = new Dnum();dn.FillFromString(newValue);_rapidData.Value = dn;
or at Dnum constructor give the double value, so no need to fill from string. (Like: Dnum dn = new Dnum(val);)
There is also method dn.FillFromDnum(val) but don't use it as documentation said it is obsolete
Mika
//After establishing comunication with controller i am asigning tasks
aTask = controller.Rapid.GetTasks();
//After that i am updating my RapidData variables :void update_values(){rdice = aTask[0].GetRapidData("Module1", "dice_txt");rangle = aTask[0].GetRapidData("Module1", "angle_txt");rx = aTask[0].GetRapidData("Module1", "x_txt");ry = aTask[0].GetRapidData("Module1", "y_txt");if ((rdice.Value is ABB.Robotics.Controllers.RapidDomain.Num)&&(rangle.Value is ABB.Robotics.Controllers.RapidDomain.Num)&& (rx.Value is ABB.Robotics.Controllers.RapidDomain.Num)&& ((ry.Value is ABB.Robotics.Controllers.RapidDomain.Num))){val = (ABB.Robotics.Controllers.RapidDomain.Num)rdice.Value;val.FillFromNum(arr[0]);val = (ABB.Robotics.Controllers.RapidDomain.Num)rangle.Value;val.FillFromNum(arr[1]);val = (ABB.Robotics.Controllers.RapidDomain.Num)rx.Value;val.FillFromNum(arr[2]);val = (ABB.Robotics.Controllers.RapidDomain.Num)ry.Value;val.FillFromNum(arr[3]);Mastership m;using (m = Mastership.Request(controller.Rapid)){rdice.Value = val;rangle.Value = val;rx.Value = val;ry.Value = val;m.Release();}}
At this point everything is working fine if the update_values() is executing ones, for example by clicking on the button.
But If I try to execute it periodically (every 500ms), using a timer:
private void timer1_Tick(object sender, EventArgs e){
update_values();
}
I have another problem related to the mastership. It says that there is another request holding on. Can it be robotstuido fault? It will be a problem with the real controller?
Thanks in advance,
Best regards,
Nazar0
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