LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Get an CAObjHandle from a struct

Hello

I'm new on this forum, i usually work with LabWindows/CVI. I'm trying to comunicate with a robot and i have created ActiveX controllers. My problem is that i need to know the position of the robot and for that purpose there's a function that returns a CAObjHandle instead of the struct that has all of the data of position and orientation of the robot. So i need to create an CAObjHandle that is related with that struct. How can i do this? using the VARIANT functions? Is there any sample of how to do this

Thanks in advance

Juan
0 Kudos
Message 1 of 14
(6,100 Views)
Hey Juan,

I'm not quite sure that I understand what you want to do, so if this doesn't answer your question let me know and I will give it another try.

A CAObjHandle, when relating to ActiveX controls, is typically passed back by reference from some function. It is then used to access another related function. For example, if I had a Windows Media Player ActiveX control that I wished to load a movie into I would perform 2 steps.

/*This include is needed in order for you to be able to declare CAObjHandle*/
#include "userint.h"

/*Declare the windows media player ID object handle*/
CAObjHandle MediaPlayerID;

/*Get the actual object handle of the Media Player ActiveX control*/
GetActiveXCtrlFromObjHandle (panel,PANEL_MEDIAPLAYER , &MediaPlayerID);

/*Load 'c:\Test.avi' into the media player whose ID we just got*/
WMP_IWMPPlayerSetURL (MediaPlayerID, NULL, "c:\Test.avi");

In your case you probably will need to use the CAObjHandle as a parameter to a function that will return the position of the robot.
0 Kudos
Message 2 of 14
(6,070 Views)
Hi Dave,

I'm working with an abb robot, and i can ask the robot some parameters (versions of controllers, status,...) and it answers, the problem begins when i ask for the position. The next function that returns the position, orientation,.. of the robot

RimbaseLib__DHelperS4CurrentPositionGet (CAObjHandle objectHandle, ERRORINFO *errorInfo, CAObjHandle robpos, short *returnValue);

CAObjHandle objectHandle, is the handle of the control that communicates with the robot.
ERRORINFO *errorINFO, is a pointer that they say it has to be NULL.
CAObjHandle robpos, is where the position is returned.
short *returnValue, return a negative number if error occurs.

The variable robpos it's supposed to be the next struct

typedef struct
{
//Position
double Pos[3];
//Orientation
double Orient[4];
//Extern joints
double ExtJoints[6];
//Config data
double ConfigData[4];
} ROBPOSDATA;

So i'm not sure about what i have to do, i think that first i would need to define the object handle, but i don't know how can i do it. Then pass it to the function and get the returned values, but how can i check them?

Thank you Dave

Juan
0 Kudos
Message 3 of 14
(6,059 Views)
Hi Juan,

You actually have two object handles in this parameter: 'CAObjHandle objectHandle' and 'CAObjHandle robpos'

To define 'objectHandle' you can use the following function:

GetActiveXCtrlFromObjHandle (panel,PANEL_MYCONTROL , &objectHandle );

replace the 'panel' parameter with the name of the panel that robot communication control is on and the 'PANEL_MYCONTROL' the name of the control.

Before I talk about the 'CAObjHandle robpos' parameter I wanted to ask if that is passed into the function as a parameter, or is it returned by reference (and you might have missed the *)? Let me know.
0 Kudos
Message 4 of 14
(6,050 Views)
Hi Dave,

the first object handle i got it with the funtion:

GetActiveXCtrlFromObjHandle (panel, PANEL_MYCONTROL , &objectHandle );

And is the one i use to communicate with the robot, and i need the other to return the position of the robot. The 'CAObjHandle robpos' parameter is passed into the function as a parameter.

The problem with this application is that the communication with the robot is designed for VisualBasic and VisualC++, but i'm very interested in designing it on LabWindows/CVI as the rest of the software is developed on this language. It has a group of ActiveX controls to communicate with the robot, and i haven't found anyone that has done it this way.

Thanks in advance

Juan
0 Kudos
Message 5 of 14
(6,046 Views)
Hi Juan,

In order to get the 'CAObjHandle robpos' parameter you will need to call another function that returns it first. Here is where it is easy to get confused because the 'robpos' value is probably not actually be returned as a 'CAObjHandle', however the return value may still be used as a 'CAObjHandle' parameter in a function.

For example, if I wish to edit a cell in Excel using the ActiveX control I would call a function that gets a handle for the cell and returns it in the following format: 'Excel_ObjCell myCell'. However, when I want to lock a cell using the 'Excel_CellFormatSetLocked' function, it asks me to pass a CAObjHandle handle not an Excel_ObjCell handle. Yet i can still use the value in myCell as a valid parameter to this function.

So perhaps you call some other function that returns a RimBaseLib_RobPos variable or something similar. This is the variable that you would use as the robpos variable even though the name of the type is different.
0 Kudos
Message 6 of 14
(6,040 Views)
Hi Dave

I've been going over the application and i have realise that the program it works when i ask about properties, but when i ask about methods it doesn't. When i work with functions that ask about methods they ask me for a server, and i'm not sure what shall i write there, i've tried with the IP direction of the robot, but it doesn't work. Why it can happen this?
0 Kudos
Message 7 of 14
(6,020 Views)
Hi Juan,

Typically your ActiveX server objects for more obscure ActiveX controls(if you have one running) will be located on your local machine which means you would pass NULL into the server parameter, which would direct the function to look on your local machine(in fact if you are using Win95 or WinNT4.0 my understanding is that you have to use the local machine). I think that the entering of NULL for the local machine is standard, but I am not sure, so anyone reading this feel free to jump in and correct me.

But the other thing I am wondering is if you really need to use those functions that ask you for an ActiveX server location, since you are actually working with an ActiveX control (the robot controller). I have done a fair amount of work with ActiveX and I have never had occasion to mix the two (though I've certainly never worked with your particular ActiveX control). I would make sure that you really need to use the functions that ask you for an ActiveX server.
0 Kudos
Message 8 of 14
(6,012 Views)
Hi Dave,

I'm sending you the code of the application so it's clear for you what i'm trying to do. All of this code it goes inside the main function.

int ctrlHelper; //Helper control ID
int errorCtrlHelper; //Error obtaining Helper control ID
char * robotNames; //Robots names (alias)
CAObjHandle controlHelperHandle; //Handle from control Helper
char selectedRobot[16]; //Name of the selected robot
CAObjHandle positionHandle; //Handle of the object
VARIANT myVariant; //Variant to store the position of the robot
float robotPosX; //Float to store the position of the robot in X

CA_InitActiveXThreadStyleForCurrentThread (0, COINIT_APARTMENTTHREADED);

//Creates a Helper control and obtains the handle of the control
RimbaseLib_New_DHelper (panelHandle, "", 0, 0, &ctrlHelper, &errorCtrlHelper);
GetObjHandleFromActiveXCtrl (panelHandle, ctrlHelper, &controlHelperHandle);

//Returns the total number of robots connected
RimbaseLib__DHelperGetAliasListCount (controlHelperHandle, NULL, &numAlias);

//Ask for all the robots connected and select the first one on the list (in this case the only robot
//connected)
for (i = 0 ; i < numAlias ; i++)
{
//This is a read-only String array property that contains the list of configured Alias names.
RimbaseLib__DHelperGetAliasList (controlHelperHandle, NULL, i, &robotNames);
InsertListItem (panelHandle, PANEL_ROBOTSELECTOR, -1, robotNames, robotNames);
}
GetCtrlVal (panelHandle, PANEL_ROBOTSELECTOR, selectedRobot);
//This is a String property used to select the S4 control alias that the WebWare ActiveX control is
//attached
RimbaseLib__DHelperSetRobot (controlHelperHandle, NULL, selectedRobot);

//Till this point everything works ok, i'm only have asked about properties, the problem comes when i begin
//to ask about methods

//Use this function to create a new IPos object, and obtain a handle to the object. This one is the one
//that asks for the server
RimbaseLib_NewIPos (NULL, 0, LOCALE_NEUTRAL, 0, &positionHandle);
//This object type encapsulates the RAPID pos data type (array of three elements, x, y, z positions)
RimbaseLib_IPosGetList (positionHandle, NULL, 1, &myVariant);
//It returns a float with the robot position in X
RimbaseLib_IPosGetx (positionHandle, NULL, &robotPosX);

This last functions (that are methods) don't seem to work properly, they must be doing something because the values obtained change, but, for instance, the the robotPosX is always 0.00 (even moving the robot in that axis). I've asked the people from ABB and they told me thet it could be a problem with the definition of the server, but as they don't develop applications in C they don't know what should i do. What i don't understand is why the control Helper doesn't need the server to communicate with the robot, and the other control does.

I haven't use on this sample the function RimbaseLib__DHelperS4CurrentPositionGet, because it doesn't work, and is not clearly explained.

Now i send you all the definitions of the funtions that are not from NI so you know what they use:

RimbaseLib_New_DHelper (int panel, const char *label, int top, int left, int *controlID, int *UILError);
RimbaseLib__DHelperGetAliasListCount (CAObjHandle objectHandle, ERRORINFO *errorInfo, short *returnValue);
RimbaseLib__DHelperGetAliasList (CAObjHandle objectHandle, ERRORINFO *errorInfo, short index, char **returnValue);
RimbaseLib__DHelperSetRobot (CAObjHandle objectHandle, ERRORINFO *errorInfo, const char *newValue);
RimbaseLib_NewIPos (const char *server, int supportMultithreading, LCID locale, int reserved, CAObjHandle *objectHandle);
RimbaseLib_IPosGetList (CAObjHandle objectHandle, ERRORINFO *errorInfo, short num, VARIANT *returnValue);
RimbaseLib_IPosGetx (CAObjHandle objectHandle, ERRORINFO *errorInfo, float *returnValue);

I hope that this is useful to show you what i'm trying to do, and how the functions work.
0 Kudos
Message 9 of 14
(6,002 Views)
Hi Juan,

From looking at your code I think I can begin to see what you might need to do.

I find that when trying to use ActiveX controls that are really designed for OO(object oriented) languages it is helpful to create an object model. So let me construct a very simple object model of your robot and see if we can go from there.

Robots -> Robot -> IPosition -> xPos,YPos,ZPos

The first part of the code works fine as you said. We get into the 'Robots' collection, and from there we get a bunch of individual 'Robot' objects.

The problem I see with the part of the code that doesn't work is that you are creating a new 'IPosition' object entirely. What you should be doing is retrieving an 'IPosition' object from an existing 'Robot' object. So rather than use a function such as NewIPos to create a completely new object, look for a function that takes a 'Robot' object handle and returns an 'IPosition' handle.

As far as seeing the values change, I wouldn't put much stock in that. When you declare your variables, none of them are initilized so they will all start out with random values assigned. If the function errors and doesn't bother to set the pointer that you passed into it back to 0, you will still have random values coming back from the function. They will just be the same random value assigned to the variable at the start of the code. If you want to check to see if the function is working I would put some error variables as return values. Error variables are technically supposed to be typed as HRESULT but I usually get lazy and use int instead. You can also try getting the error message returned by the function but I have found that usually they are too general to be of much help.

Do you have access to any object models for this API, or a website with information. A quick search turned up a 'pcrob.pdf' document for me, but nothing in there seemed related to what you were trying to do.
0 Kudos
Message 10 of 14
(5,998 Views)