LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

SetCtrlAttribute question

Hi everybody,

i'm a new user of this IDE (a couple of week) so i apologize if this is a dumb question, but i cannot find anything with the search since i really don't know exactly what to search for.

My problem is that i send trought TCP a packet with 2 infos in, one is the data and the other one is the place where i want write the data

 

e.g:

data = 10;

index = "data_1"

 

where index a string that is identical to a Constant Name of  numeric field on a panel so, when the data arrive i wanna put the data in that field.

I tryed using this command founded in some google search "int SetCtrlAttribute (int panelHandle, int controlID, int controlAttribute, ...);" but for specify wich is the field to edit the command only accept an int; so i'm wondering if there is another command for do this thing or some elegant way for avoid this kind of problem.

 

Many thanks 

0 Kudos
Message 1 of 5
(4,162 Views)

The constant names (IDs) of controls are evaluated to an integer at compile time, so you cannot directly do what you want. One approach would be to construct an array of structures, tying together these control IDs with arbitrary strings. Then when a string is received over TCP, you just scan the array to find the ID of the matching string and then the job is easy. Something like:

 

static struct {int ID; char *descr;} ID_list [] = {PANEL_NUMERIC1, "data_1",

                                                   PANEL_NUMERIC2, "data_2,

                                                   PANEL_NUMERIC3, "etc..."};

 

Alternatively, you could investigate the use of Ring or List controls, which can automatically locate an entry within the control, based on a given string. Depending on your application, this may not be appropriate.

 

JR

0 Kudos
Message 2 of 5
(4,159 Views)

Hi Jr,

your solution is a thing that certainly will work out for what i must do, but im worried if the numbers of the field will increase (atm i must manage 30 field.

It will be nice if you have some links that can give me a good introduction on "Ring or List controls" maybe they will suit my project issues.

 

Thanks again.

0 Kudos
Message 3 of 5
(4,134 Views)

fema,

 

You could use the ATTR_CONSTANT_NAME attribute; this will provide you with the 'Constant Name' you assigned to the control in the UIR editor, as a string.

 

  • Step through all the controls on the panel, using the panel attribute ATTR_PANEL_FIRST_CTRL and the control attribute ATTR_NEXT_CTRL
  • Get the name of the current control:
  • GetCtrlAttribute (panel, control, ATTR_CONSTANT_NAME, name);
  • Check for the correct control using the CompareStrings() function
  • Validate the control using ATTR_CTRL_MODE and ATTR_DATA_TYPE
  • Set the value

 

Regards,

Colin.

 

Message 4 of 5
(4,102 Views)

Thanks Colin i tryed also your way and it worksw without problems.

 

0 Kudos
Message 5 of 5
(4,076 Views)