Hi, I am looking to program a digital to analog converter to output voltage on 12 of the available analog channels. I am an novice-intermediate programmer but cannot seem to solve a problem with undefined references.
I downloaded Measurement Computing's "DAQ" and "Instacal" programs to allow for the USB-3105 board to be recognized. Included with instillation is the Universal Library example programs for the USB-3105 DAC.
I am running windows 7 and using Code::Blocks with a GNU GCC compiler to try and run this sample program on the board. The program is also written in C/C++
When I load the VOut01.C file from the examples it reads:
/* Prototypes */
void ClearScreen (void);
void GetTextCursor (int *x, int *y);
void MoveCursor (int x, int y);
void main ()
{
/* Variable Declarations */
int ch;
int Row, Col;
int BoardNum = 0;
int ULStat = 0;
int Gain = BIP10VOLTS;
int Options = DEFAULTOPTION;
int Chan;
float DataValue;
int UDStat = 0;
float min, max;
float RevLevel = (float)CURRENTREVNUM;
/* Declare UL Revision Level */
ULStat = cbDeclareRevision(&RevLevel);
/* Initiate error handling
Parameters:
PRINTALL :all warnings and errors encountered will be printed
DONTSTOP :program will continue even if error occurs.
Note that STOPALL and STOPFATAL are only effective in
Windows applications, not Console applications.
*/
cbErrHandling (PRINTALL, DONTSTOP);
/* set up the display screen */
ClearScreen();
printf ("Demonstration of cbVOut()\n\n");
/* get the D/A channel to sample */
printf ("Enter the channel to display: ");
scanf("%i", &Chan);
printf ("\n\nNote: Please make certain that the board you are using supports\n");
printf (" the gain you are choosing and if it is not a programmable\n");
printf (" gain that the switches on the board are set correctly.\n\n");
GetTextCursor (&Col, &Row);
while (Gain > 0 && !kbhit())
{
do
{ /* select gain */
MoveCursor(Col,Row);
printf("Please select one of the following ranges(1 to 4):\n\n");
printf(" 10 VOLTS UNIPOLAR --> 1\n");
printf(" 10 VOLTS BIPOLAR ---> 2\n");
printf(" 5 VOLTS UNIPOLAR --> 3\n");
printf(" 5 VOLTS BIPOLAR ---> 4\n");
printf(" Quit ---> 0\n\n");
printf(" Your Choice ---> ");
scanf ("%i",&Gain);
} while ((Gain < 0) || (Gain > 4));
/* Set Gain, MaxVal, and MinVal */
switch (Gain)
{
case 0:
exit(1);
case 1:
Gain = UNI10VOLTS;
min=0.0;
max=10.0;
break;
case 2:
Gain = BIP10VOLTS;
min=-10.0;
max=10.0;
break;
case 3:
Gain = UNI5VOLTS;
min=0.0;
max=5.0;
break;
case 4:
Gain = BIP5VOLTS;
min=-5.0;
max=5.0;
break;
default:
break;
}
UDStat = NOERRORS;
while (UDStat == NOERRORS)
{
printf ("\n\nEnter a voltage between %.1f and +%.1f: ", min, max);
scanf ("%f", &DataValue);
ULStat = cbVOut (BoardNum, Chan, Gain, DataValue, Options);
if(UDStat == NOERRORS)
{
printf ("\n %.2f volts has been sent to D/A %d.\n\n", DataValue, Chan);
printf ("Press Q to quit , any other key to continue:\n ");
while (!kbhit()){}
ch=getch();
if (ch=='q' || ch=='Q')
exit(1);
}
}
}
}
/***************************************************************************
*
* Name: GetTextCursor
* Arguments: x,y - screen coordinates of new cursor position
* Returns: *x and *y
*
* Returns the current (text) cursor position.
*
***************************************************************************/
The main function has trouble referencing three of the functions included in the header file cbw.h
The undefine references to the functions state:
"undefined reference to cbDelareRevision@4"
"undefined reference to cbErrHandling@8"
"undefined reference to cbVOut@20"
I do not know how to solve this problem. I have tried including the entire header file location in the quotations at the beginning but that does not seem to solve the problem. I have also tried moving the header file's directory but that also does not seem to work.
All of the functions that have undefined references are dimmed in the header file after the statements:
#if !defined (NT_DRIVER) && ! defined (WIN95_DRIVER)
#if defined (__cplusplus)
extern "C"
{
#endif
#if defined (_WIN32)
/* Win32 prototypes */
#ifdef EVENTCALLBACK
#undef EVENTCALLBACK
#endif
Afterwards all three functtions are declared as:
int EXTCCONV cbDeclareRevision(float *RevNum);
int EXTCCONV cbErrHandling (int ErrReporting, int ErrHandling);
int EXTCCONV cbVOut (int BoardNum, int Chan, int Gain, float DataValue, int Options);
The program Instacal in combination with the header file is supposed to recognize the "BoardNum" and allows for the "int Chan", "int Gain", "float DataValue", and all other subsequent dependent variables to exist.
However, I am still retaining these undefined reference errors even when I used Instacal to define the variables of the board (BoardNum, int Chan, ...ect) and added the full location of the header file.
My questions are:
-Why is this section of the header file dimmed after the endif statements?
-Is this reference problem a problem with the header files directory?
-Do the declarations of the function in the header file prevent them from being access due to their names and or symbolism?
-Why are the reference errors @4, @8, or @20, and what does this mean?
-Is this a problem with my compiler?
If anyone can help or know about this problem please help. Thanks.
> Why is this section of the header file dimmed after the endif statements?
you can declare a function as many times as you want. But it should only be 1 definition
> Is this reference problem a problem with the header files directory?
No, the problem is with the source, or with the libraries, that are not linked
> Do the declarations of the function in the header file prevent them from being access due to their names and or symbolism?
No, your program compiles. It knows about the existence of the function and how they should be used, but couldn't find a body for the functions.