08-18-2009 11:59 AM
GetCtrlVal and SetCtrlVal work with the data type of the control. In your case, you were getting the value from an int control, and setting the value of a string control.
Please review the CVI function help for GetCtrlVal and SetCtrlVal. There's a lot of good info there.
NI also offers very good hands-on training. You'll really be giving yourself a headstart if you get some training.
08-18-2009 12:16 PM
Its difficult converting back from c++ to c. especially when you cant go backwards from c++ to c. i cant write the same programs in c++ and then copy and paste them in c.
it just wont work. So basically i have started using the basic c since two weeks.
I only having problems with binary and bit conversion thats all really. everything else im pretty descent.
ok i do have one more thing im using the code that you sent with bit conversion, it not spitting to the string box. this i did everything as far the SetCtrlVal and GetCtrlVal right.
also is there a quicker way to just set all of my numeric switches to everything at once. you will see what im talking about when you open the program.
i dont want to have come up with five different function calls.
08-18-2009 12:18 PM
Its difficult converting back from c++ to c. especially when you cant go backwards from c++ to c. i cant write the same programs in c++ and then copy and paste them in c.
it just wont work. So basically i have started using the basic c since two weeks ago.
I only having problems with binary and bit conversion thats all i really need. everything else im pretty descent.
ok i do have one more thing im using the code that you sent with bit conversion, it not spitting to the string box. this i did everything as far the SetCtrlVal and GetCtrlVal right.
also is there a quicker way to just set all of my numeric switches to everything at once. you will see what im talking about when you open the program.
i dont want to have come up with five different function calls.
08-18-2009 12:23 PM
// this is my example i wrote in c++ to spit out the bit conversion, but when i adjust the syntax to c in cvi i get errors.
//when i say adjust i take out of the cout and cin and replace them with printf and scanf just to see if it would work before i put it behind the gui
// so i know how to code in c++ well, its just im learning c at the moment . How would i switch this to C.
#include <iostream>
using namespace std;
void binary(int);
void main(void) {
int number;
cout << "Please enter a positive integer: ";
cin >> number;
if (number < 0)
cout << "That is not a positive integer.\\n";
else {
cout << number << " converted to bits is: ";
binary(number);
cout << endl;
}
}
void binary(int number) {
char temp[][10]={"00000000","00000001","00000010","00000100","00001000","0001000"};
cout<<temp[number];
}
08-18-2009 12:48 PM
this does not really show the use of C++... plus it will happilly crash when you enter a number greater than 9.
(out of topic: i confess that, was C++ correctly defined, we would write: cout << bin << (1 << number-1); but everybody knows that displaying binary is completely useless since K&R told us so 40 years ago, that's why nobody ever thought of introducing such a stream manipulator into the C++ standard. however, the octal manipulator still exists while it does not make any sense nowadays. who said computing was a fast evolving field ?)
08-18-2009 01:07 PM - edited 08-18-2009 01:12 PM
did i say greater than 9 ? sorry, i meant greater than 5. (but i can't find the edit button).
(edit: i finally found the edit button, and also learned how to count to 5. now i am no more a software engineer: i became a mathematician)
08-18-2009 02:51 PM
08-18-2009 07:07 PM - edited 08-18-2009 07:10 PM
Darnell:
To reply to your post on 08-19-2009 12:16 PM:
In the code you posted, you never call BIT_CONVERSION(), so it's never executed.
Here's a troubleshooting tip: if you think a chunk of code isn't working, put a breakpoint in it and view the variables and execution as you step through it. If you had put a breakpoint in BIT_CONVERSION(), the breakpoint would never have been reached, which should indicate to you that the code was never executed.
CVI Help has a good sections on Breakpoints. Take a look at it.
Here's a couple of tips on your UIR.
Give meaningful names to your controls. For example, instead of calling the input for Switch 1 NUMERIC_2 and the output BINARY_READ_6, call them SWITCH1_INPUT and SWITCH1_OUTPUT.
Use the input control properties to set input limits. If the maximum number to be entered is 8, edit the control and set the Maximum to 8. That way you won't get a runtime error if the operator enters a higher than expected number.
Why do you use String control to label the switches instead of using the controls' built in labels?
Why do you want to set all your switches at once? If you only change one input value at a time, you only need to update one output at a time. But that doesn't mean you need 5 functions to do the conversion and display. The easiest thing to do will be to have 5 callback functions that all call the same conversion function, passing the input control ID and the output control ID.
// Here's the new prototype for BIT_CONVERSION()
int BIT_CONVERSION(int inputControl, int outputControl);
// here's one sample callback
int CVICALLBACK DECIMAL_INPUT_1 (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
// the name of the input control parameter ('control') will be the same for every callback,
// since it's automatically passed to the callback,
// but the output control parameter (PANEL_BINARY_READ_6)
// will be unique for each callback based on which control to write to
BIT_CONVERSION(control, PANEL_BINARY_READ_6);
break;
}
return 0;
}
// here's the updated BIT_CONVERSION() function
int BIT_CONVERSION(int inputControl, int outputControl)
{
char myString[9]; // 8 characters followed by NULL
int bitValue;
GetCtrlVal (panelHandle, inputControl, &bitValue);
strcpy(myString, "00000000");
// set one bit to 1
if (bitValue > 0)
myString[8 - bitValue] = '1';
SetCtrlVal (panelHandle, outputControl, myString);
return 0;
}
08-19-2009 06:13 AM
Hi Al S, IM up studying some cvi . i was wondering if there is a option to stop the numeric indicator that im using in my gui to entering in the result im returning automatically.
the thing its doing : I would enter in a number and then , i would go to the next switch , the first switch i just just left from would automatically enter the result. IM TRYING TO PREVENT THAT FROM HAPPENING.
I want it to BE where in Im hitting my update button and then it enters my result. instead when i hit the update button it resets everything . I was wondering if i could get some assistance. I tried everything possible that i knew.
you will see what im talking about in the attachment.
08-19-2009 07:41 AM
Darnell:
The outputs are updated after you enter each number because each numeric control has a callback function that runs BIT_CONVERSION().
If you only want the update to happen when you press the Update button, you need to do the following.
- Edit each numeric control using the UIR editor, and delete the callback function name. Just leave the box blank.
- Edit the Update control and assign a callback function name.
- Right-click on the Update control in the UIR editor and generate the callback function.
- Edit the callback function for the Update control to call BIT_CONVERSION() for each numeric control. If you have 5 numeric controls, you will have 5 calls to BIT_CONVERSION(), with each call having a unique inputControl (e.g. PANEL_NUMERIC_2) and outputControl (e.g. PANEL_BINARY_READ_6).
- Delete the callback functions for each numeric control from the .c file.
To get a better understanding on why the updates were happening "automatically", review the CVI Help entry for Callback functions