LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Always getting errors when trying to control YOKOGAWA 7651 power supply on Labwindows/CVI

Solved!
Go to solution

Hi,

 

I'm trying to set the voltage on the YOKOGAWA 7651 power supply through labwindows/cvi. I've set up a numeric slide on my userinterface with callback function "yoko7651dcvolts" and constant name "YOKO7651DCVOLTS".

 

I always get this error when I run my program:

 

 

"FATAL RUN-TIME ERROR: "DcSource.c", line 53, col 65, thread id 0x00001F3C:   Invalid argument type: found 'pointer to double', expected 'pointer to int'."

 

 

This error points to the third argument of the GetCtrlVal function below. The program/compiler wants me pass the variable "yoko1volts" as integer, but I want to (and should) be able to set voltages as floating numbers.

 

Plus, even when I declare "yoko1volts" as integer, it stills doesn't work. All I get is zero, zero, and zero...on the power supply meter everytime I press the numeric slide.

 

This is the section of the C code that is problemic:

 

 

int CVICALLBACK yoko7651dcvolts (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
double yoko1volts;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (yoko76511Panel, YOKO7651_1_YOKO7651DCVOLTS, &yoko1volts); // to read the values entered on the numerical meter on the user interface

yk7651_set_volts (yoko76511Panel, yoko1volts); // set the entered values as voltage on the instrument

break;
}
return 0;
}

 

 

 

This is the related h-file:

 

 

#define  YOKO7651_1                       4
#define YOKO7651_1_YOKO7651SWITCH 2 /* control type: binary, callback function: yoko7651switch */
#define YOKO7651_1_YOKO7651DCVOLTS 3 /* control type: scale, callback function: yoko7651dcvolts */


 

 

 

Please help, how can I fix this issue?

 

 

All the drivers (including the YOKOGAWA 7651 power supply) are properly installed and mounted. As a matter of fact, I can successfully turn the power supply on and off with the code below:

 

int CVICALLBACK yoko7651switch (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int yoko7651switchstate;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (yoko76511Panel, YOKO7651_1_YOKO7651SWITCH, &yoko7651switchstate);
SetCtrlVal (yoko76511Panel, YOKO7651_1_YOKO7651SWITCH, !yoko7651switchstate);
yk7651_output (yoko76511Panel, !yoko7651switchstate);
break;
}
return 0;
}


 

 

It's just setting the voltage on the power supply that is very problematic. Any help is appreciated...Thanks.

0 Kudos
Message 1 of 8
(4,987 Views)

Go to the numeric slide control YOKO7651DCVOLTS in the UI editor and make sure it's defined as a double, not an int.

0 Kudos
Message 2 of 8
(4,983 Views)

Yes, the numeric slide was always defined as double. That was the first thing I checked when I got that error. But it was still showing the same error message. So yes, I have the data type of the numeric slide as "double" and the control mode as "Hot". I tried all possible control modes, but to no avail.

0 Kudos
Message 3 of 8
(4,980 Views)

Which line is line 53?  GetCtrlVal() or yk7651_set_volts()?

 

If the error is occuring on yk7651_set_volts(), check the documentation for that function.  It's possible that it wants an integer if it defaults to units of millivolts.

 

Does the value returned to yoko1volts match the setting on the slide?

 

If you're working with multiple panels, it's possible that you have overwritten a panel handle and that you're pointing to a control on another panel.

 

Can you read the voltage setting back from your yk7651 after you set it?

0 Kudos
Message 4 of 8
(4,972 Views)

Line 53 is :

GetCtrlVal (yoko76511Panel, YOKO7651_1_YOKO7651DCVOLTS, &yoko1volts);

And when that error message pops up, the third argument (&yoko1volts)  is highlighted because the program expects yoko1volts to point to integer instead of double.

 

 

I'm indeed working with mutlitple panels. But the reason I believe I have the panels set correctly is because the following code does display 2.5478 V as voltage on the power supply.

 

 

int CVICALLBACK yoko7651dcvolts (int panel, int control, int event,
		void *callbackData, int eventData1, int eventData2)
{
    double yoko1volts = 2.5478;
	switch (event)
	{
		case EVENT_COMMIT:
                
                yk7651_set_volts (yoko76511Panel, yoko1volts); 
 
                break;
	}
	return 0;
}

 I think the problem stems from the GetCtrlVal function. And to your other question, the value returned to yoko1volts never matched the setting on the slide. If I declared yoko1volts as double as shown in my very fist post, then that error message pops up. And, if I declare yoko1volts as integer and set the data type of the numeric slide as integer also, then the power supply always return and display zero no matter what voltage you set on the slide.

 

0 Kudos
Message 5 of 8
(4,939 Views)

OK, so you know your yk7651_set_volts() function works with a double.

 

There seems to be a disconnect between your UI and either the panel handle or the control ID.  There is not a bug like that in GetCtrlVal().  I believe you're somehow pointing to the wrong panel or control.

Here are a couple of things to try.

1. Search for all occurances of yoko76511Panel and make sure it's not being overwritten or discarded.

2. In your original code on line 53, right-click on YOKO7651_1_YOKO7651DCVOLTS, and select Find UI Object.  Make sure it's pointing to the control you expect.

3.1 Put a breakpoint in your code at the line where you use LoadPanel to assign the value to yoko76511Panel and make a note of its value.

3.2 Put another breakpoint at line 53 and double check that the value of yoko76511Panel is unchanged.

4. Change line 53 to SetCtrlAttribute (yoko76511Panel, YOKO7651_1_YOKO7651SWITCH, ATTR_DIMMED, 1); and check your panels to see which control got dimmed.

5.1 In your code at the yoko7651dcvolts() callback definition before line 53, right-click on the callback function name and select Find UI Object to make sure the callback function is correctly associated with the control.

5.2 If the callback is associated with the numeric slide, change line 53 to GetCtrlVal (panel, control, &yoko1volts);  This won't work if the callback is to a command button, but will work if it's the numeric slide. You shouldn't need to do this, but there's something else we're missing and this will just make sure you're using the correct panel handle and control ID (if it's the callback for the numeric slide).  Even if this works, I think you still need to get to the bottom of why the original code doesn't work.  There's still some kind of disconnect there.

 

0 Kudos
Message 6 of 8
(4,926 Views)
Solution
Accepted by topic author protonic

I second Al opinion of a disconnection between the UIR and the variable that holds the panel handle.

 

As a side note, I noted that the problematic line is reading the value of the controll whose callback is executed:

 

#define  YOKO7651_1_YOKO7651DCVOLTS       3       /* control type: scale, callback function: yoko7651dcvolts */

int CVICALLBACK yoko7651dcvolts (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
double yoko1volts;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (yoko76511Panel, YOKO7651_1_YOKO7651DCVOLTS, &yoko1volts); // to read the values entered on the numerical meter on the user interface

yk7651_set_volts (yoko76511Panel, yoko1volts); // set the entered values as voltage on the instrument

break;
}
return 0;
}

 

In a situation like this, I would try using GetCtrlVal (panel, control, &yoko1volts); instead, that should get rid of all problems in panel handle / control ID.

 

Despite this solution is working, in any case I would deep into the problem as an incorrect panel handle can lead to erratical behaviour in other places of the program.



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 7 of 8
(4,909 Views)

Thank you so much Roberto and Al for your help.

 

GetCtrlVal (panel, control, &yoko1volts) did fix the problem. And Al, you were right. There was a disconnect between my UI and my panel handle. Because when I replaced line 53 with "SetCtrlAttribute (yoko76511Panel, YOKO7651_1_YOKO7651SWITCH, ATTR_DIMMED, 1);" as you mentioned, it was a button from the main panel on the first user interface that was dimmed, and not the binary switch.

 

But "GetCtrlVal (panel, control, &yoko1volts)" magically fixed this issue, and diplay any voltage on the power supply that I set on the slide.

 

Again, thank you guys so much Smiley Happy

0 Kudos
Message 8 of 8
(4,895 Views)