K8055 - syntax error in K8055D.h

Hello everybody,

I am working with the K8055 board (XP SP2 / Borland c++ 5.0.2).
I wrote a simple C routine to convert a number into a voltage as an output using OutputAnalogChannel().
Everything works fine but I needed to put in comments the declaration FUNCTION bool __stdcall ReadDigitalChannel(long Channel) in K8055D.h. If I don’t do that, I have a syntax error when I compile the program.

Here is the program

[code]#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>

#include “K8055D.h”

int main()
{
int h,i,a;
a = 1;
do
{
h = OpenDevice(0);
printf(“h = %d\n”,h);
printf("Input an integer: ");
fscanf(stdin, “%d”, &i);
OutputAnalogChannel(2,i);
} while (a == 1);
ClearAnalogChannel(1);
CloseDevice();
return 0;
}[/code]

Does anybody have an idea why I have this mistake ? Did I forget something ?
For the moment I don’t need the function ReadDigitalChannel() then everything is fine. But perhaps I will have tu use it.

Thank you in advance.
LePapat.

In french now :slight_smile:
Bonjour,
je realise une routine simple en C (win xp sp2 / borland c++ 5.0.2) pour communiquer avec la K8055. Vous trouverez le code ci dessus. Pour que le programme fonctionne, je suis oblige de mettre en commentaires la ligne FUNCTION bool __stdcall ReadDigitalChannel(long Channel) dans le fichier K8055D.h. Sinon j’ai une ‘syntax error.’

je ne sais pas pourquoi. Si vous avez des ides je suis preneur. merci d’avance.
LePapat.

Maybe your compiler does not recognize the bool type.

Hello,

you’re right. I tought that I used some booleans in the past with this compiler :blush:

Thank you.

LePapat

C does not have a boolean data type, C++ does. So there’s a bit of a glitch in the header file:

#ifdef __cplusplus
extern "C" { // <- switch to C
#endif

bool foobar(); // <- C doesn't have a bool data type

#ifdef __cplusplus
}
#endif

Which doesn’t really make sense. The strict C (Windows) version would be:


// K8055D.h

#ifdef __cplusplus
extern "C" {
#endif

#include <windows.h>
// Defines the custom C 'BOOL' data type,
// not to be confused with 'bool' in C++

#ifndef DLLIMPORT
#define DLLIMPORT __declspec(dllimport)
#endif

DLLIMPORT DWORD WINAPI OpenDevice(DWORD addr);
DLLIMPORT VOID  WINAPI CloseDevice();
DLLIMPORT DWORD WINAPI ReadAnalogChannel(DWORD chan);
DLLIMPORT VOID  WINAPI ReadAllAnalog(LPDWORD d1, LPDWORD d2);
DLLIMPORT VOID  WINAPI OutputAnalogChannel(DWORD chan, DWORD data);
DLLIMPORT VOID  WINAPI OutputAllAnalog(DWORD d1, DWORD d2);
DLLIMPORT VOID  WINAPI ClearAnalogChannel(DWORD chan); 
DLLIMPORT VOID  WINAPI ClearAllAnalog();
DLLIMPORT VOID  WINAPI SetAnalogChannel(DWORD chan); 
DLLIMPORT VOID  WINAPI SetAllAnalog();
DLLIMPORT VOID  WINAPI WriteAllDigital(DWORD data);
DLLIMPORT VOID  WINAPI ClearDigitalChannel(DWORD chan);
DLLIMPORT VOID  WINAPI ClearAllDigital();
DLLIMPORT VOID  WINAPI SetDigitalChannel(DWORD chan);
DLLIMPORT VOID  WINAPI SetAllDigital();
DLLIMPORT BOOL  WINAPI ReadDigitalChannel(DWORD chan);
DLLIMPORT DWORD WINAPI ReadAllDigital();
DLLIMPORT DWORD WINAPI ReadCounter(DWORD idx);
DLLIMPORT VOID  WINAPI ResetCounter(DWORD idx);
DLLIMPORT VOID  WINAPI SetCounterDebounceTime(DWORD idx, DWORD t_debounce);

#ifdef __cplusplus
}
#endif

// main.c

#include <stdio.h>
#include "K8055D.h"

int main()
{
	int h, i, a = 1;

	do
	{
	   h = OpenDevice(0);

	   printf("h = %d\n", h);
	   printf("Input an integer: ");
	   scanf("%d", &i);

	   OutputAnalogChannel(2, i);
	}
	while (a == 1);

	ClearAnalogChannel(1);
	CloseDevice();

	return 0;
}

Thanks for this adapted .h.

I modified the type bool by long in the original librairy but your solution is better :laughing:
Even with yours, I have some warnings about some functions
‘Call to function ClearAllAnalog with no prototype’
‘Call to function CloseDevice with no prototype’

It works but it is weird that I have this kind of warnings.

LePapat

Something is wrong, please double-check that the K8055D.h is added to your project and is being used

This message means that the compiler has noticed you trying to call a function which the compiler has no (or only minimal) information about (didn’t see your .h file). Under most compilers, this is a warning message, not an error, because the compiler is willing to assume certain things about unknown functions, and will let you try to call them. However, the assumptions it makes might not be right, and the compiler won’t be able to check that you’ve called the function with the correct number and type of arguments, which is why it issues the warning.

Hello,

I included the librairy in my C file and linked the K8055d.lib to my project (using in Borland C++ the function AddNode. I did it for several projects in the past and everything was fine.

It is very surprising because I am using most of the functions provided by the Velleman librairy and have this warning only for a few functions.

In the examples provided by the cd, I noticed that the #pragma directive is used but I don’t use it in my program. I don’t know if it can play a rule ?

Patrick

I don’t have an explanation, maybe we’re missing something obvious… Do you use those two functions anywhere else? Somewhere where the .h file is not included…

The pragma is probably used to import the .lib file. You can do this with your project settings too.

Hi,

I use these functions in a single c file with the librairy included.

I also use the c librairy in a matlab routine by using loadlibrary and callib and I have no warnings for these 2 functions.

I added the #pragma in the c project to be more consistent but no effect on the warnings as expected.

A new IT mystery :slight_smile:

LePapat