LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ring control getctrlval demanding a *int when it's declared to store *char/string

This segment of code produces the following error when run, I have verified MANY times that I've got the proper panel handle and control ID.
FATAL RUN-TIME ERROR:   "XML2TREE.c", line 429, col 42, thread id 0x000013D4:   Invalid argument type: found 'pointer to char', expected 'pointer to int'.
ADDTEST_TESTTYPE is a ring control with it's data type set to string.
 
Also: I have tried fetching an index and then getting a val from index, it also fails rather... epicly... I've been fighting this for the better part of 4 hours.
 
void AddTestTypeDependantFields(CVIXMLElement parent)
{
   char           TestType[48];
   int            index = -1;
   int            x;
   CVIXMLElement  child;
   char           FieldType[20];
   char           FieldValue[20];
  
   GetCtrlVal(ADDTEST, ADDTEST_TESTTYPE, TestType);
   RemoveSurroundingWhiteSpace(TestType);  
   if (strcmp(TestType, "Impedence") == 0)
   {
      x = 1;
      while (x <=NUMIMPFORCEDELEMENTS)
      {
         CVIXMLNewElement(parent, -1, ImpFields[x-1], &child);
         CVIXMLSetElementValue(child, ImpDefaults[x-1]);
         CVIXMLDiscardElement(child);
      }
   }
   else if (strcmp(TestType, "Resistance") == 0)                                                           
   {
      //Resistance
   }
   else if (strcmp(TestType, "SelfResonatingFrequency") == 0)
   {
      //SRF
   }
   else
   {
      //omg epicphail!
   }
}
0 Kudos
Message 1 of 7
(4,274 Views)
If I understand your question, you may want code that looks like this:

  GetCtrlIndex( hSerialPanel, SeriaPAN_2_CP_COMPORT, &Comport_index);  
  GetLabelFromIndex( hSerialPanel, SeriaPAN_2_CP_COMPORT, Comport_index,Comport_name);


Comport_Index holds the integer value from the ring and then the next line gets the associated text to that "point" on the ring.
0 Kudos
Message 2 of 7
(4,260 Views)
hmm, well I think i'm either: a) misunderstand ring controls or b) poorly explaining... so let me try again 😛
 
I have a ring control that contains values of type char *, i don't want the label back, I want the value.  I've tried using the get index/ get value from index method, it doens't work as expected either.
0 Kudos
Message 3 of 7
(4,258 Views)

A ring is a control  that holds two elements for each item: a label (which is always a string) and a "value" of a type defined by the user (char *, int, double...) The default data type for a ring control is integer, so unless you have modified it while creating the label/value list (it's the first parameter on top of that panel) GetCtrlVal expects a variable of type int (well, actually a pointer to...).

Looking at the error returned, it seems that the ring control still has its default integer data type: that's why you get the error while passing a string. But are you sure you want the value back and not the label? You are treating the return value as a string, so it seems to me that you expect to have the label back...

A possible solution to operate on ring values instead of labels could be like this:

A) Create the list of items keeping the default int data type and adding elements like these:
     Label                      Value
     "Impedance"                  0
     "Resistance"                 1
     "SelfResonatingFrequency"    2

B) Get the ring value and operate accordingly:
     int   testTypeVal;

     GetCtrlVal(ADDTEST, ADDTEST_TESTTYPE, &TestTypeVal);
     switch (TestTypeVal) {
          case 0:               // Impedance
               x = 1;
              while (x <=NUMIMPFORCEDELEMENTS)
              {
                       CVIXMLNewElement(parent, -1, ImpFields[x-1], &child);
                       CVIXMLSetElementValue(child, ImpDefaults[x-1]);
                       CVIXMLDiscardElement(child);
              }
              break;
          case 1:               // Resistance
              // Your code here
              break;
          case 2:               // Self Resonating Frequency
              // Your code here
              break;
          default:               // Unknown value ?
              // Your code here
              break;
     }

There can be another reason for the error you are receiving. It seems strange to me that a panel handle has the same name of the panel itself (in this case ADDTEST😞 it is possible that you are passing an incorrect variable to GetCtrlVal as the panel handle, so the program is actually operating on a panel and control different from the one you want, with different associated data type, from which the error.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 7
(4,243 Views)
... I'm gonna go kill myself now... yeah it's the panel handle, that's exactly what's wrong... I forgot that you can get multiple instances of a panel and have to create the handle and yeah... okay... now I feel dumb cuz I've done this at least 100 times...
0 Kudos
Message 5 of 7
(4,241 Views)
You can try this, it works on my system:
 
char myStringVal[100];
GetCtrlVal (panelHandle, PANEL_RING, myStringVal);
 
This returns the string value of the currently selected element in the ring control, assuming that you assigned string values to the control in the properties.
 
Let me know if that works for you, or what goes wrong if it doesn't.
Jervin Justin
NI TestStand Product Manager
0 Kudos
Message 6 of 7
(4,237 Views)
thank you, but I got it, I'm just a really poor excuse for a coder this week, onset of sickness and brain fried for 60 hours at work and then 40 hours on my own C# projects kinda gets my brain in a twist... if anyone wants to take a look at my CVIXML post tho that'd be appreciated.
0 Kudos
Message 7 of 7
(4,234 Views)