accessing my sensor using APIs

  • Follow


Dear All,

Lately during one of my projects i have encountered a problem and
stuck on that point. I have an optical sensor that i have attached to
my pc and it detects colors in terms of RGB values. The sensor is from
a famous company and has been supplied with its own software where I
could see the data. Now to access those RGB values on visual C (so i
could further manipulate the data) the company has provided me with a
header file and lib file and ofcourse the dll file. In the
documentation  which is poorly written they have also described some
API functions that have been defined in the header file and should be
called in order to access the values from sensor. For example, int
USB_DLL_API MTCSGetADCAVR2( int iIndex, unsigned short* usBuf, int
iCounts); is one of the functions that I have to use.
Now since I am new to dll programming and want to use these functions
so I could access the values from sensor, I was wondering if someone
could give me a help in order to trigger off my work. I mean I read
some articles on how to make a dll but they are rather confusing and I
think if the company has already given me the files with functions it
should be rather easier to use.
I would deeply appreciate your help.

regards,
Faraz
0
Reply farashes (1) 2/2/2010 4:32:06 PM

On Feb 2, 11:32=A0am, Faraz <faras...@gmail.com> wrote:
> Dear All,
>
> Lately during one of my projects i have encountered a problem and
> stuck on that point. I have an optical sensor that i have attached to
> my pc and it detects colors in terms of RGB values. The sensor is from
> a famous company and has been supplied with its own software where I
> could see the data. Now to access those RGB values on visual C (so i
> could further manipulate the data) the company has provided me with a
> header file and lib file and ofcourse the dll file. In the
> documentation =A0which is poorly written they have also described some
> API functions that have been defined in the header file and should be
> called in order to access the values from sensor. For example, int
> USB_DLL_API MTCSGetADCAVR2( int iIndex, unsigned short* usBuf, int
> iCounts); is one of the functions that I have to use.
> Now since I am new to dll programming and want to use these functions
> so I could access the values from sensor, I was wondering if someone
> could give me a help in order to trigger off my work. I mean I read
> some articles on how to make a dll but they are rather confusing and I
> think if the company has already given me the files with functions it
> should be rather easier to use.
> I would deeply appreciate your help.
>
> regards,
> Faraz

You said the company has provided you with a DLL, but you seem to be
asking how to make a DLL.  Do you really mean to ask how to use a DLL?

To use a DLL you must #include the provided .h file and you must add
the name of the provided .lib file into your project's linker settings
(at 'Additional Dependencies').  Then you can call functions in the
DLL.  When you run the program make sure the provided DLL is in the
same directory as your program.


0
Reply ScottMcP 2/2/2010 5:06:04 PM


Faraz wrote:
> The sensor [...] has been supplied with its own software where I 
> could see the data. Now to access those RGB values on visual C (so i
> could further manipulate the data) the company has provided me with a
> header file and lib file and ofcourse the dll file.

So far, that is common.

> Now since I am new to dll programming and want to use these functions
> so I could access the values from sensor, I was wondering if someone
> could give me a help in order to trigger off my work.

Some steps:
1. Create a new VC project for C or C++.
2. Add "#include <sensor_header.h>" in a source file. You might have to
tweak the path where the compiler searches for include files or move the
file so it gets found.
3. Add "#pragma comment(lib, "sensor_library.lib")" in a source file. You
might have to tweak the path where the linker searches for libraries or
move the lib file so it gets found.
4. Add "&MTCSGetADCAVR2;" in a function in a source file. This just takes
the address of a function of the library for testing, so the DLL must be
present for that. You might have to move the DLL so it gets found, see the
documentation for LoadLibrary() at http://msdn.microsoft.com. 

After each step, verify that your project still compiles, links and runs
correctly. If you're through, you have a working setup capable of using the
functions declared in the header.

> I mean I read some articles on how to make a dll but they are rather
> confusing and I think if the company has already given me the files
> with functions it should be rather easier to use.

You don't want to create a DLL but use the one you already got. ;)

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

0
Reply Ulrich 2/2/2010 5:20:51 PM

On Tue, 2 Feb 2010 08:32:06 -0800 (PST), Faraz <farashes@gmail.com>
wrote:

>Dear All,
>
>Lately during one of my projects i have encountered a problem and
>stuck on that point. I have an optical sensor that i have attached to
>my pc and it detects colors in terms of RGB values. The sensor is from
>a famous company and has been supplied with its own software where I
>could see the data. Now to access those RGB values on visual C (so i
>could further manipulate the data) the company has provided me with a
>header file and lib file and ofcourse the dll file. In the
>documentation  which is poorly written they have also described some
>API functions that have been defined in the header file and should be
>called in order to access the values from sensor. For example, int
>USB_DLL_API MTCSGetADCAVR2( int iIndex, unsigned short* usBuf, int
>iCounts); is one of the functions that I have to use.
>Now since I am new to dll programming and want to use these functions
>so I could access the values from sensor, I was wondering if someone
>could give me a help in order to trigger off my work. I mean I read
>some articles on how to make a dll but they are rather confusing and I
>think if the company has already given me the files with functions it
>should be rather easier to use.
>I would deeply appreciate your help.

Earlier posts provide good detail. I'll add a somewhat different
perspective.

The usual, and easier, method is to use static binding. For this, you
1) use #include for the header file so your compiler recognizes the
functions, etc.
2) link to the lib file. You can use a #pragma as an earlier post
suggested, or you can modify the settings in your project file
(probably using the settings dialog in your IDE)
3) distribute the DLL with your executable, and put it in a directory
that the operating system searches for DLLs (could be with the
executable)

If you want your program to run even when the DLL is not present, you
need to use dynamic linking. For this, you
1) use #include for the header file
2) use LoadLibrary and GetProcAddress to load the DLL and access its
functions.
I don't think this is the way to go for your project, so I didn't
bother with some important details.

>
>regards,
>Faraz

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com
Useful reading (be sure to read its disclaimer first):
   http://catb.org/~esr/faqs/smart-questions.html
0
Reply r_z_aret 2/2/2010 5:44:53 PM

On Feb 2, 9:44=A0am, r_z_aret@pen_fact.com wrote:
> On Tue, 2 Feb 2010 08:32:06 -0800 (PST), Faraz <faras...@gmail.com>
> wrote:
>
>
>
>
>
> >Dear All,
>
> >Lately during one of my projects i have encountered a problem and
> >stuck on that point. I have an optical sensor that i have attached to
> >my pc and it detects colors in terms of RGB values. The sensor is from
> >a famous company and has been supplied with its own software where I
> >could see the data. Now to access those RGB values on visual C (so i
> >could further manipulate the data) the company has provided me with a
> >header file and lib file and ofcourse the dll file. In the
> >documentation =A0which is poorly written they have also described some
> >API functions that have been defined in the header file and should be
> >called in order to access the values from sensor. For example, int
> >USB_DLL_API MTCSGetADCAVR2( int iIndex, unsigned short* usBuf, int
> >iCounts); is one of the functions that I have to use.
> >Now since I am new to dll programming and want to use these functions
> >so I could access the values from sensor, I was wondering if someone
> >could give me a help in order to trigger off my work. I mean I read
> >some articles on how to make a dll but they are rather confusing and I
> >think if the company has already given me the files with functions it
> >should be rather easier to use.
> >I would deeply appreciate your help.
>
> Earlier posts provide good detail. I'll add a somewhat different
> perspective.
>
> The usual, and easier, method is to use static binding. For this, you
> 1) use #include for the header file so your compiler recognizes the
> functions, etc.
> 2) link to the lib file. You can use a #pragma as an earlier post
> suggested, or you can modify the settings in your project file
> (probably using the settings dialog in your IDE)
> 3) distribute the DLL with your executable, and put it in a directory
> that the operating system searches for DLLs (could be with the
> executable)
>
> If you want your program to run even when the DLL is not present, you
> need to use dynamic linking. For this, you
> 1) use #include for the header file
> 2) use LoadLibrary and GetProcAddress to load the DLL and access its
> functions.
> I don't think this is the way to go for your project, so I didn't
> bother with some important details.
>
>
>
> >regards,
> >Faraz
>
> -----------------------------------------
> To reply to me, remove the underscores (_) from my email address (and ple=
ase indicate which newsgroup and message).
>
> Robert E. Zaret, eMVP
> PenFact, Inc.
> 20 Park Plaza, Suite 400
> Boston, MA 02116www.penfact.com
> Useful reading (be sure to read its disclaimer first):
> =A0 =A0http://catb.org/~esr/faqs/smart-questions.html- Hide quoted text -
>
> - Show quoted text -

Dear All,
Thanks so far!
Using the implicit Dll call atleast I have started the way you said
and have written a code. What I have done is that in Project settings-
>preprocesser->include directories, I have given the path of where my
header file is, in my case I have set to D:\Program Files\Microsoft
Visual Studio\MyProjects\sensor\MTCSApi.h because this is where I have
placed my header file (is this the right place for it?). Similarly for
linker I have given the path putting .lib file in debug folder where
my exe also exists.

I have written a small code


#include<iostream.h>
#include<MTCSApi.h>



main()
{


/* The actual call to the function contained in the dll */
int ReturnVal =3D MTCSInitSystem("0", 0x152a, 0x8220);
cout<<"The value"<<ReturnVal;


}



just to see, as you said that if sensor was being initialized or not.
i made this cpp file like normal win32 console application, and have
included the header as shown. Now at compilation I am getting the
following errors:

d:\program files\microsoft visual studio\vc98\include\mtcsapi.h(43) :
error C2146: syntax error : missing ';' before identifier
'MTCSDllGetVersion'
d:\program files\microsoft visual studio\vc98\include\mtcsapi.h(43) :
error C2182: 'USB_DLL_API' : illegal use of type 'void'
d:\program files\microsoft visual studio\vc98\include\mtcsapi.h(43) :
fatal error C1004: unexpected end of file found

and when I try to debug it takes me to the header file of the sensor
with the above mentioned errors. I was wondering if one of you could
suggest that where the problem lies since it is a prechecked h file
from the company.
regards
0
Reply Faraz 2/4/2010 6:35:58 PM

On Feb 4, 10:35=A0am, Faraz <faras...@gmail.com> wrote:
> On Feb 2, 9:44=A0am, r_z_aret@pen_fact.com wrote:
>
>
>
>
>
> > On Tue, 2 Feb 2010 08:32:06 -0800 (PST), Faraz <faras...@gmail.com>
> > wrote:
>
> > >Dear All,
>
> > >Lately during one of my projects i have encountered a problem and
> > >stuck on that point. I have an optical sensor that i have attached to
> > >my pc and it detects colors in terms of RGB values. The sensor is from
> > >a famous company and has been supplied with its own software where I
> > >could see the data. Now to access those RGB values on visual C (so i
> > >could further manipulate the data) the company has provided me with a
> > >header file and lib file and ofcourse the dll file. In the
> > >documentation =A0which is poorly written they have also described some
> > >API functions that have been defined in the header file and should be
> > >called in order to access the values from sensor. For example, int
> > >USB_DLL_API MTCSGetADCAVR2( int iIndex, unsigned short* usBuf, int
> > >iCounts); is one of the functions that I have to use.
> > >Now since I am new to dll programming and want to use these functions
> > >so I could access the values from sensor, I was wondering if someone
> > >could give me a help in order to trigger off my work. I mean I read
> > >some articles on how to make a dll but they are rather confusing and I
> > >think if the company has already given me the files with functions it
> > >should be rather easier to use.
> > >I would deeply appreciate your help.
>
> > Earlier posts provide good detail. I'll add a somewhat different
> > perspective.
>
> > The usual, and easier, method is to use static binding. For this, you
> > 1) use #include for the header file so your compiler recognizes the
> > functions, etc.
> > 2) link to the lib file. You can use a #pragma as an earlier post
> > suggested, or you can modify the settings in your project file
> > (probably using the settings dialog in your IDE)
> > 3) distribute the DLL with your executable, and put it in a directory
> > that the operating system searches for DLLs (could be with the
> > executable)
>
> > If you want your program to run even when the DLL is not present, you
> > need to use dynamic linking. For this, you
> > 1) use #include for the header file
> > 2) use LoadLibrary and GetProcAddress to load the DLL and access its
> > functions.
> > I don't think this is the way to go for your project, so I didn't
> > bother with some important details.
>
> > >regards,
> > >Faraz
>
> > -----------------------------------------
> > To reply to me, remove the underscores (_) from my email address (and p=
lease indicate which newsgroup and message).
>
> > Robert E. Zaret, eMVP
> > PenFact, Inc.
> > 20 Park Plaza, Suite 400
> > Boston, MA 02116www.penfact.com
> > Useful reading (be sure to read its disclaimer first):
> > =A0 =A0http://catb.org/~esr/faqs/smart-questions.html-Hide quoted text =
-
>
> > - Show quoted text -
>
> Dear All,
> Thanks so far!
> Using the implicit Dll call atleast I have started the way you said
> and have written a code. What I have done is that in Project settings->pr=
eprocesser->include directories, I have given the path of where my
>
> header file is, in my case I have set to D:\Program Files\Microsoft
> Visual Studio\MyProjects\sensor\MTCSApi.h because this is where I have
> placed my header file (is this the right place for it?). Similarly for
> linker I have given the path putting .lib file in debug folder where
> my exe also exists.
>
> I have written a small code
>
> #include<iostream.h>
> #include<MTCSApi.h>
>
> main()
> {
>
> /* The actual call to the function contained in the dll */
> int ReturnVal =3D MTCSInitSystem("0", 0x152a, 0x8220);
> cout<<"The value"<<ReturnVal;
>
> }
>
> just to see, as you said that if sensor was being initialized or not.
> i made this cpp file like normal win32 console application, and have
> included the header as shown. Now at compilation I am getting the
> following errors:
>
> d:\program files\microsoft visual studio\vc98\include\mtcsapi.h(43) :
> error C2146: syntax error : missing ';' before identifier
> 'MTCSDllGetVersion'
> d:\program files\microsoft visual studio\vc98\include\mtcsapi.h(43) :
> error C2182: 'USB_DLL_API' : illegal use of type 'void'
> d:\program files\microsoft visual studio\vc98\include\mtcsapi.h(43) :
> fatal error C1004: unexpected end of file found
>
> and when I try to debug it takes me to the header file of the sensor
> with the above mentioned errors. I was wondering if one of you could
> suggest that where the problem lies since it is a prechecked h file
> from the company.
> regards- Hide quoted text -
>
> - Show quoted text -

just for clarity i am also adding the header file

#ifdef EXE
	#ifdef USB_DLL_EXPORTS
	#define USB_DLL_API   __declspec(dllexport) __stdcall
	#else
	#define USB_DLL_API  __declspec(dllimport) __stdcall
	#endif
#endif

#ifdef INDEX
#include "MTCSApi_idx.h"
#endif


#ifndef OBJECT
#if defined(__cplusplus)
extern "C" {
#endif
#endif


 void USB_DLL_API   MTCSDllGetVersion(char* cBuf);
 int USB_DLL_API	MTCSInitSystem( char cTyp, int iVendorID, int
iProductID );
 int USB_DLL_API    MTCSReadVersion( char* cBuf);
 int USB_DLL_API    MTCSReadMemory( unsigned char* cBuf, int iNum);
 int USB_DLL_API    MTCSWriteMemory( unsigned char* cBuf, int iNum);
 int USB_DLL_API    MTCSGetADCBL( unsigned short* usBuf, int iCounts);
 int USB_DLL_API    MTCSGetADCAVR( unsigned short* usBuf, int
iCounts);
 int USB_DLL_API    MTCSGetADCBuf( unsigned short* usBuf);
 int USB_DLL_API    MTCSGetADC(  unsigned short* usBuf);
 int USB_DLL_API    MTCSSetSwitch(  int iCounts);
 int USB_DLL_API    MTCSSetEPoti(  int iCounts);
 int USB_DLL_API    MTCSGetRGB(  unsigned short* usBuf);
 int USB_DLL_API    MTCSStartRGB(  unsigned short* usBuf, int iTime,
int iCycles);
 int USB_DLL_API    MTCSStopRGB(  unsigned short* usBuf);
 int USB_DLL_API   	MTCSCloseDevice(void);
 int USB_DLL_API    MTCSSetUpdateMode(void);


void USB_DLL_API MTCSGetSerienNummer( unsigned char idx, char
*buffer);
int USB_DLL_API  MTCSGetADCAVR2( int iIndex, unsigned short* usBuf,
int iCounts);
int USB_DLL_API  MTCSGetADCSummen( int iIndex, unsigned long* ulBuf,
int iCounts);
int USB_DLL_API  MTCSSetParameter( int iIndex, int iVerst, int iTol);
int USB_DLL_API	 MTCSSearchAmplification( int iIndex, unsigned short*
usBuf, int iLimit);
int USB_DLL_API  MTCSReadMemFromAdr( int  iIndex, unsigned char* cBuf,
int iAdr, int iNum);
int USB_DLL_API  MTCSWriteMemToAdr(int iIndex, unsigned char* cBuf,
int iAdr, int iNum);
int USB_DLL_API  MTCSSetShift( int iIndex, int iShift);

#ifndef OBJECT
#ifdef __cplusplus
 }
#endif
#endif

/
***************************************************************************=
***********/

#endif	/*	_USB_API_H_ */

/
***************************************************************************=
***********/
0
Reply Faraz 2/4/2010 6:38:58 PM

Dear All,
Above is the header file. Despite after defining the paths where this
"h" file is and linking the .lib with C++ 6 compiler by changing the
project settings, I have encountered some linking errors. I was
wondering if once could give it a look and tell me the solution.


en2.obj : error LNK2001: unresolved external symbol
__imp__MTCSGetADCAVR2
libcid.lib(iostrini.obj) : error LNK2001: unresolved external symbol
"void * __cdecl operator new(unsigned int,int,char const *,int)" (??
2@YAPAXIHPBDH@Z)
libcid.lib(_ios.obj) : error LNK2001: unresolved external symbol "void
* __cdecl operator new(unsigned int,int,char const *,int)" (??
2@YAPAXIHPBDH@Z)
libcid.lib(streamb.obj) : error LNK2001: unresolved external symbol
"void * __cdecl operator new(unsigned int,int,char const *,int)" (??
2@YAPAXIHPBDH@Z)
Debug/Sensor2.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

Sensor2.exe - 5 error(s), 0 warning(s)
0
Reply Faraz 2/5/2010 6:08:24 AM

6 Replies
237 Views

(page loaded in 0.118 seconds)

Similiar Articles:













7/24/2012 12:14:10 PM


Reply: