Read/Write Record structure
newform
✭
Dear All,
I am developing an application using PC SDK and C#. We tried to read/write a RECORD variable in Rapid by following the example in RAB manual. We always got system exception. These examples cannot work. Anybody knows how to do that? Many thanks
The RECORD structure in Rapid is:
---------------------------------------
RECORD P3
num p1;
num p2;
num P3;
ENDRECORD
PERS P3 pOrigin = [0, 0, 0];
-------------------------------------
The code in our application is :
---------------------------------
RapidData rdOrigin;
RapidDataType rdtOrigin;
double x = 100.0;
double y = 50.0;
double z = 60.0;
rdOrigin = Controller.Rapid.GetRapidData(taskName, moduleName, "pOrigin");
rdtOrigin = Controller.Rapid.GetRapidDataType(taskName, moduleName, "pOrigin");
UserDefined ud = new UserDefined(rdtOrigin);
ud.Components[0].FillFromString(x.ToString());
ud.Components[1].FillFromString(y.ToString());
ud.Components[2].FillFromString(z.ToString());
rdOrigin.Value = ud;
-------------------------------------------------------------------
When we create variable "ud", we got the exception "Components' threw an exception of type 'System.InvalidOperationException" such that the following operation with components will throw exception then.
newform2010-02-03 18:23:21
0
Comments
-
Hi,You missed one line. ( mentioned in RAB Manual under section Reading User Defined DataPlease check the folloeing code. Its working fine-
RapidData rdOrigin;
RapidDataType rdtOrigin;
try
{
double x = 100.0;
double y = 50.0;
double z = 60.0;
ctr.Logon(UserInfo.DefaultUser);
rdOrigin = ctr.Rapid.GetRapidData("T_ROB1", "test1", "pOrigin");
rdtOrigin = ctr.Rapid.GetRapidDataType("T_ROB1", "test1", "pOrigin");
UserDefined ud = new UserDefined(rdtOrigin);
ud = (UserDefined)rdOrigin.Value; //You missed this line
ud.Components[0].FillFromString(x.ToString());
ud.Components[1].FillFromString(y.ToString());
ud.Components[2].FillFromString(z.ToString());
using (Mastership.Request(ctr.Rapid))
{
rdOrigin.Value = ud;
}
}If still having problem , please writeRegardsRegards
Saleem Javed0 -
Thank you very much for your help.
I added this line and had a try. When the application run at the newly added line, it still throws an exception "Exception of type 'System.Exception' was thrown."
I run the application in debug mode and checked the fields of the variable "rdOrigin". The value of "Value" field is "Exception of type 'System.Exception' was thrown.". But the value of its "StringValue" field is "[0,0,0]", which is the initial value we set. Does it mean "rdOrigin" is not created properly?
I am using RobotWare 5.12 and the IDE is VS2008.
newform2010-02-04 15:55:560 -
Hi,
I just found that when our application load Rapid program to controller and initialize "rdOrigin". Its all fields are correctly set. When our application start the Rapid program, the contents in its "Value" field becomes "System Exception ...". Therefore, userdefined "ud" variable can not be initialized. Thus, we initialize "ud" whenever "rdOrigin" is initialized. Up to now, our application is running well, though the process is wield a little bit.
I have another question now. I need read/write speeddata in Rapid. There is no corresponding NET object in RapidDomain. How can read/write a speeddata variable then?
0 -
Hi ,
Its good that finally your program is runnin
For speeddata, you can wrap userdefined data in a .NET Structure by using IRapidData.For more details please refer to section "Implement your own struct representing a RECORD" in RAB User's Guide.RegardsRegards
Saleem Javed0 -
Hi,
Thank you very much. That is what I tried yesterday. But the FillFromString always throw exception. Right now, I write speed data to userdefined data component by component. It works well.
Thanks a lot for your help and time. Have a good day!
0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 799 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings