LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Switching control in the uir by switching between different c files in LabWindows/CVI.

Hello,
I am writing because I am problem switching the controls in my program from one function t another. Below I have included som information about my program:

I am working with two field point devices (FP-AI-110 and FP-AO-200) to input and output data to a device. I currently have the program setup, so that is sends data, using the FP-A0-200. I added a button to the uir to force and certain value to be sent to the device and override the previous function. The problem was that the LabWindows?CVI would stop whenever the second button was pressed. I later fixed that error, but noe the program, doesn't not recongize the function, when is is pressed in the user interface. I am looked at my code and have not been able to find the error. I wanted to now, if you have any suggests to how I might approach this program.Below I have included segments of my code, that I told might be helpful in explaining my problem better:

This segment of my code represents my first c file in the project. This is the function that sends the data to the FP-AO-200, depending on the user input.

/*=================================================*/
/* Function: Advise Loop */
/* Purpose: This is the callback function for the timer. This function */
/* calls read cache to get the last read values from the digital */
/* module and then updates the LEDs
=====================================================*/
int CVICALLBACK advise_loop (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)
{
IAStatus status = IA_SUCCESS;
SYSTEMTIME timestamp;
char valueStr[BUFFER_SIZE];
unsigned short mask = 1;
float temp; // Temporary value holder
//////////////////////////////////////////////////
float* valuei; // Value of analog input
IAStatus result;
/////////////////////////////////////////////////

if (Callloop==Call_moveclose)
{ istart=5;
// return 0;
}
else if (Callloop==Call_moveopen)
{
istart=5;
// return 0;
}
//THIS IS THE PROGRAM BEFORE THE ABOVE MOVE FUCTIONS WERE ADDED

if (istart==1) //This was just an if statement, added else to make work w/call loop functions
{
pvalue = (float*)value;
switch(event)
{
case EVENT_TIMER_TICK:
icountertime++;
///////////////////////////////////////////////////////
//Information for the FP-AI-110
result = FP_ReadCache (FP_handle,advise_IDi, current_readi, 100, &timestamp);

for (i=0; i {
valuei = (float*)(current_readi+(i*4));
SetCtrlVal (panelHandle, PANEL_NUMERIC0_2+i, *valuei);
}
//////////////////////////////////////////////////
if (icountertime==fmAvalues[iIndex][1])

...........................................
Then I write, once the process is complete


This part of the code refers to the second c file of the project. This code represents the button in the uir that will send the same output to all of the devices used. I was aslo wondering why the EVENT_LEFT_DOUBLE_CLICK, was not working either.

int CVICALLBACK MoveClose (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{

int setval; //Stores the value of the MOVECLOSE
int co; //Counter Variable
float temp=.004;
switch (event)
{
case EVENT_COMMIT:

GetCtrlVal(panelHandle, PANEL_MCButton, &setval);

if (setval==1)
{
istart=5;
Callloop=Call_moveclose;
/***************************************
*Apply 4 mA to all eight channels **
**************************************/
for (co=0; co {
SetCtrlVal (panelHandle, ictl[co+10], &temp);
memcpy (value + (co*4), &temp, 4);
}
}
break;
}
return 0;
}

Thank You Very Much

All help is greatly appreicated.

EF
0 Kudos
Message 1 of 4
(3,414 Views)
We would be able to help you better having some more details on your program. Here I add some hypotesis based on the source abstract you added to your question.

1. In MoveClose Function you wrote SetCtrlVal (panelHandle, ictl[co+10], &temp); This is maybe a mistake in reporting your source code, since to read a control's value you must use GetCtrlVal
2. Again in MoveClose you read a control's value and put it in setVal: in case the control you read is the button associated with the callback, its value will be 0 unless it is a toggle or a binary switch button. If you are using a normal command button, your program will never execute code in the if (setval == 1) construct
3. istart and callloop aren't defined elsewere in the code you sent, so I assume they are common to all code. If this is the case, and assuming they are not used elsewere in your program, I think one of them is redundant. In MoveClose you can set istart and read it in the timer callback. Be sure to reset its value when you want to go back to the normal behaviour of the program. I suggest you to avoid using two variables to define the same program behaviour, since it makes more difficult to debug the program
4. Are you resetting istart to 1 elsewhere in the program?

As you see, these are very general notes, that maybe don't apply to your situation. Maybe the best suggestion I can give to you is to put some brakpoints in the program and execute it step-by-step to follow its behaviour. A good place to break is for example the first if statement in moveclose function (check the value of setval).
Another suggestion is to create a false else statment in the timer callback that way:
if (istart == 1) {
// Your code
}
else {
; // dummy statement to break into
}

and put a breakpoint on the semicolon, to check the behaviour of your program when the button is pressed that alters the normal flow of operations.

Hope this all helps you a little. In case, reply to me adding some more details about your problem.
Roberto


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?
Message 2 of 4
(3,414 Views)
Dear Mr. Bozzolo,

Hi thanks for responing to my question once again. All your suggestions were very useful.

MoveClose Function:
The suggestion you made about the moveclose function has me a bit confused.
Is it necessary to read the data displayed in the user interface (This data is
displayed in a numberic box)? I was trying to overwrite these values. I have
eight numberic boxes that contains different values of current (mA) that are sent
to the device. I was trying to over write all these data boxes with the value of 4mA.
I guess I can assume that this is the same problem for the all the other functions that I
am using is FP_AI_110 file.

istart & callloop:
I am only using istart the advise loop function. I declared this value as a global
in this c file only. I reset this value to five at the end of the advise loop function
and inside of the two if statements that contain callloop, call_moveclose, and callmove_open.
I defined the callloop as a "static char callloop" in both files.
I didn't have a component in the program to reset it. I am thinking to add another button
that the user can click on just set istart to it orginal value.

I am sending some more information about the MoveClose function just in case u you any more
suggestions.

/*=========Flag*For*MoveOpen & MoveClose* Fuctions==========*/
static char Callloop=9;
static char Call_moveclose;
static char Call_moveopen;
/*==========================================================*/

/*This function will apply a 4mA signal to all the channels for as long as the **
user consider it necessary */

int CVICALLBACK MoveClose (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{

int setval; //Stores the value of the MOVECLOSE
int co; //Counter Variable
float temp=.004;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal(panelHandle, PANEL_MCButton, &setval);
if (setval==1)
{
//istart=5;
Callloop=Call_moveclose;
for (co=0; co {
SetCtrlVal (panelHandle, ictl[co+10], &temp);
memcpy (value + (co*4), &temp, 4);
}
fprintf (stream, "Apply 4 mA to all eight channels");

}
break;
}
return 0;
}


-------------------------------------------------------------
Other c file
*=========================================================================*/
/* Function: Advise Loop */
/* Purpose: This is the callback function for the timer. This function */
/* calls read cache to get the last read values from the digital */
/* module and then updates the LEDs. */
/*=========================================================================*/
int CVICALLBACK advise_loop (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
IAStatus status = IA_SUCCESS;
SYSTEMTIME timestamp;
char valueStr[BUFFER_SIZE]; // Value converted to a string
unsigned short mask = 1; // Mask used to mask off bits for the LEDs
float temp; // Temporary value holder

//////////////////////////////////////////////////
float* valuei; // Value of analog input
IAStatus result;
/////////////////////////////////////////////////

if (Callloop==Call_moveclose)
{
istart=5;
return 0;
}
else if (Callloop==Call_moveopen)
{
istart=5;
return 0;
}


if (istart==1)
{
pvalue = (float*)value;
switch(event)
{
case EVENT_TIMER_TICK:
icountertime++;
/////////////////////////////////////////////////////////////////////
//Information for the FP-AI-110
result = FP_ReadCache (FP_handle,advise_IDi, current_readi, 100,
&timestamp);

for (i=0; i {
valuei = (float*)(current_readi+(i*4));
SetCtrlVal (panelHandle, PANEL_NUMERIC0_2+i, *valuei);
}
/////////////////////////////////////////////////////////////////////

if (icountertime==fmAvalues[iIndex][1])
{
for (co=0; co {
//Checks which valves are in manual or auto mode
if (iChecked_Unchecked[co]==0)
{ // Manual mode (Data From User)
//Set the numeric controls
// value = (float*)(current_read + (co*4));

//Get current value of numeric controls
GetCtrlVal (panelHandle, ictl[co+10], &temp);
memcpy (value + (co*4), &temp, 4);
}
..............................
Thank You Very Much, all your help is greatly appriecated.

EF
0 Kudos
Message 3 of 4
(3,414 Views)
I will check the code you added in a few days (now I'm outside my office).
In the meanwhile, I can comment one point briefly; it's not necessary at all to read a control's value before changing it, but in your statement you are setting the control to &temp: since temp is declared as a float (not pointer) you are putting the address of temp in the control, not its value.
Roberto


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 4
(3,414 Views)