Jump to content

CONFIGURING WINDOWS SDK FUNTIONS IN LABVIEW


Recommended Posts

Hi all...HAPPY NEW YEAR.

I've been having alot of problems with calling SDK funtions. Is there any resources that clarifies the funtion parameters and how to configure them in labview.

found this link These are the some of the dll's I need to call.

One of the things I'm tring to do is find USB devices. The first thing I need to do;

-call the SetupDiGetClassDevs which is in the setupapi,dll. see link

SetupDiGetClassDevs returns a handle to a device information set that contains all installed devices that matched the supplied parameters.

Depending what I set for parameters i can get imformation on all devices connected to all ports.

My problem is don't know how the parameters are configured.

HDEVINFO

SetupDiGetClassDevs(

IN LPGUID ClassGuid, OPTIONAL (how do I configure each of the parmteters in labview)

IN PCTSTR Enumerator, OPTIONAL

IN HWND hwndParent, OPTIONAL

IN DWORD Flags

);

There are more call I need to make ,but need to get this imformation first.

Thanks

Link to comment

The attched VI is to get the computer Name using the GetComputerNameA funtion in the kernel32.dll.

I copied this code and added comments. Also added the build array to make it eaier to set up buffer and string.

http://msdn.microsoft.com/en-us/library/ms724295(VS.85).aspx I couldn't find the GetComputerNameA just GetComputerName.

feel free to add comments about the code

Thanks

Link to comment

QUOTE (mattdl68 @ Jan 1 2009, 03:21 PM)

Hi all...HAPPY NEW YEAR.

I've been having alot of problems with calling SDK funtions. Is there any resources that clarifies the funtion parameters and how to configure them in labview.

found this link These are the some of the dll's I need to call.

One of the things I'm tring to do is find USB devices. The first thing I need to do;

-call the SetupDiGetClassDevs which is in the setupapi,dll. see link http://msdn.microsoft.com/en-us/library/ms792959.aspx

SetupDiGetClassDevs returns a handle to a device information set that contains all installed devices that matched the supplied parameters.

Depending what I set for parameters i can get imformation on all devices connected to all ports.

My problem is don't know how the parameters are configured.

HDEVINFO

SetupDiGetClassDevs(

IN LPGUID ClassGuid, OPTIONAL (how do I configure each of the parmteters in labview)

IN PCTSTR Enumerator, OPTIONAL

IN HWND hwndParent, OPTIONAL

IN DWORD Flags

);

There are more call I need to make ,but need to get this imformation first.

Thanks

Hello matdl68,

Not all parameters in C/C++ is easy or visibly callable within LabVIEW, it maybe easy in LabWindow, since it is C. It would be easier if you write a C wrapper function around it, so that it only uses very basic parameter type, like int, string, cluster, array etc. The functions mentioned above still only return the handle (which is an integer) that you need to pass into another function to get device information... I would suggest just write wrapper function in C and return the final information of the device to LabVIEW as cluster. Let me know if you need help.

Irene

Link to comment

QUOTE (Irene_he @ Jan 3 2009, 12:20 AM)

Hello matdl68,

Not all parameters in C/C++ is easy or visibly callable within LabVIEW, it maybe easy in LabWindow, since it is C. It would be easier if you write a C wrapper function around it, so that it only uses very basic parameter type, like int, string, cluster, array etc. The functions mentioned above still only return the handle (which is an integer) that you need to pass into another function to get device information... I would suggest just write wrapper function in C and return the final information of the device to LabVIEW as cluster. Let me know if you need help.

Irene

Hi Irene. Thanks for the info.

I looked into doing a wrapper. But i don't Know c that well. I was trying also to use the VISA develoment wizzard. The wizzrd had errors trying to setup the setapi.dll.

Correct me if i"m wrong, even using c++ you need to know thr order in which to call the functions. For example...say i want to find all devices currently connected to the USB?What is the order of doing that? i'm assuming there are some outputs of some functions that feed the inputs of other funtions.

Is ther some documation for this?

the SetupDiGetClassDevs asked for a flag, Dword. DIGCF_ALLCLASSES is one of the fags. Is this a string?

The flag ClassGuid is it a key which looks in the Ini file supplied by manufactuer. To get the device id (number)

but seeing for know I what all devices connected. This should be set to null. So would I input a string constat(null) or a 0(U32)

Thanks for your help

Link to comment

QUOTE (mattdl68 @ Jan 3 2009, 02:38 PM)

Yes, there are orders that you call functions. I took a look at the link you provided above:

http://msdn.microsoft.com/en-us/library/ms792959.aspx

it does not seem obvious to me which order to call. Maybe check out the functions below, they all take the parameter HDEVINFO that you got returned from SetupDiGetClassDevs:

SetupDiEnumDeviceInterfaces

SetupDiGetDeviceInterfaceDetail

SetupDiDestroyDeviceInfoList

For SetupDiGetCalssDevs, you may also need to check out what values are DIGCF_ALLCLASSES etc. Do they start with 0 in the enumerator? I took a quick look, haven't found the mapping values, but I am sure you will find it sooner or later, it is just a matter of time. Yes, I guess the link above is the document that you need to look at. Also to find out the GUID ID for a specific class, you also need to call some other function, like this one: HidD_GetHidGuid(guid), this gives you for example GUID ID for HID class devices (like mouse etc. devices). I know it is very painful... but that is microsoft document. Can you also find some example from their document or examples in C, VB etc? that maybe very helpful to translate into LabVIEW.

Irene

Link to comment

QUOTE (normandinf @ Jan 3 2009, 06:23 PM)

See this link for commun typedefs. This will help you setup the DLL properly.

Thank norman. I configured the SetupDiGetClassDevsA as shown in your replay.

I guest the next step is calling function SetupDiEnumDeviceInterfaces. I think I understand this, but comments would be appriciated.

Link to comment

Thank norman. I configured the SetupDiGetClassDevsA as shown in your replay.

I guest the next step is calling function SetupDiEnumDeviceInterfaces. I think I understand this, but comments would be appriciated.

[/quote

I attached a vi. not my final version. needs comments and i will use a state machine.

I"m not getting imformation of devices on my system. Can some take a look and see what i'm doing wrong.

Thanks

Link to comment
I'm not getting information of devices on my system. Can some take a look and see what i'm doing wrong.

 

I'm not either. I've not succeeded in retrieving a handle the the proper DeviceInfo (and I won't have time to play with it since it's back to work tomorrow...) but here is a little tip: Use the GetLastError and FormatMessage functions from kernel32.dll. This way, you'll know what sort of problem you have.

It seems I've misled you with the datatypes I showed on my screenshot but I thought it was not important since those parameters are optional. The LPGUID typedef is a pointer to a GUID structure. Think of "struct" as a cluster in LabVIEW terminology. Hence, the datatype for GUID is something like this:

 

typedef struct _GUID {DWORD Data1; WORD Data2; WORD Data3; BYTE Data4[8]; } GUID;where for example this GUID: eeaf37d0-1963-47c4-aa48-72476db7cf49 would be represented by:DATA1 = EEAF37D0DATA2 = 1963DATA3 = 47C4DATA4 = {AA, 48, 72, 47, 6D, B7, CF, 49}

It is not trivial to get these to work in LabVIEW... The trick is to match the types and I personally find that frustrating sometimes!

In this case, I'm returned ERROR_INVALID_DATA. I'll leave it up to you to find a solution... But here's my Windows Error Extraction class if that can be of help. (Just input the error code from GetLastError() and Merge it to LV error cluster.

post-10515-1231128228.png?width=400

Download File:post-10515-1231128408.zip (LV 8.6)

Link to comment

This link is talking about how to get USB device. You will see someone got it to work with correct USB GUID ID. But then again, you still have to make up a GUID ID in LabVIEW. It is not an easy thing to do.

http://www.codeguru.com/forum/archive/inde...p/t-331907.html

static /*const*/ GUID GUID_DEVINTERFACE_USB_DEVICE =

{ 0xA5DCBF10L, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } };

Hope this is another tip.

Irene

Link to comment

QUOTE (jlk62628 @ Jan 5 2009, 03:11 PM)

I'm stuck on the SetupDiGetClassDevs function as well, but I successfully got my computer's USB GUID for HID devices. Here is my vi, I use HID.dll. This is LabView 7.1.

I just want to thank everyone for there input.

Were did you find the info on the guid to set up the cluster?

Thanks again

Link to comment

QUOTE (Val Brown @ Jan 3 2009, 05:05 PM)

Well, theoretically. In practice the Windows API is sometimes very complex and the most difficult part is that it usually pulls in a very large part of the Windows header files and some of them do contain C preprocessor defines and C language constructs where the DLL Wizard parser simply chokes on. I've been writing a C header file parser in the past using LabVIEW and it was a major pain and still is not doing as much as the DLL Wizard parser can handle.

So even if the actual function you try to import is not using complicated parameters it is quite possible to fail due to the pulling in of other Windows API headers that are undigestable for the parser.

And if it is using complicated parameters then it will fail a lot of times anyhow.

QUOTE (mattdl68 @ Jan 3 2009, 03:38 PM)

Hi Irene. Thanks for the info.

I looked into doing a wrapper. But i don't Know c that well. I was trying also to use the VISA develoment wizzard. The wizzrd had errors trying to setup the setapi.dll.

The VISA wizard is not about helping you call DLLs but about creating inf files for accessing VISA devices including USB devices. However for USB devices they should not be handled by an already installed or standard Windows driver as then VISA can not gain access to it.

You probably meant the Shared Libary Import Wizard and here you obviously need to point it to the right header file. In the case of the SetupDi... functions this would be the SetupAPI.h. Functions not defined in there but being exported by the SetupAPI.DLL (all the CMP_ and CM_ functions in your other screen shot) will of course cause errors but should not affect the SetupDi.. functions. However it all could still fail due to unparsable constructs in the SetupAPI.h file or in other depending header files.

QUOTE

Correct me if i"m wrong, even using c++ you need to know thr order in which to call the functions. For example...say i want to find all devices currently connected to the USB? What is the order of doing that? i'm assuming there are some outputs of some functions that feed the inputs of other funtions.

Is ther some documation for this?

Yes MSDN and the Windows Platform SDK. MSDN is mostly about the function prototype and documentation and the Platform SDK (PSDK) contains both the headers and C code samples how these functions can be used.

QUOTE

the SetupDiGetClassDevs asked for a flag, Dword. DIGCF_ALLCLASSES is one of the fags. Is this a string?

The flag
ClassGuid is it a key which looks in the Ini file supplied by manufactuer. To get the device id (number)

but seeing for know I what all devices connected. This should be set to null. So would I input a string constat(null) or a 0(U32)

Since the flag is a DWORD it must be a integer number or bit flag. What numeric value corresponds to the Preprocessor symbol DIGCF_ALLCLASSES you can sometimes lookup in MSDN and otherwise you have to search in the headers of the PSDK for it.

A GUID is a structure of 16 Bytes length as you seem to have been told already. This and anything else about datatypes can be also found on MSDN or in the headers of the PSDK.

The function expects a pointer to that. If you need to pass here a NULL value you would configure it as uInt32 (or (Un)Signed Pointer-sized Integer in LabVIEW >= 8.6 which will take care about adjusting for the different pointer size if you ever move to LabVIEW for Windows 64 bit) and then pass in a 0 integer.

QUOTE (Val Brown @ Jan 3 2009, 08:14 PM)

It is impressive to me how frequently that Wizard simply fails. Welcome to DLL Hell.

Ever written a C compiler? :rolleyes: Try and you will understand!

I admire the courage of the person not only attempting the task of creating the DLL Wizard (I've written a somewhat less exhaustive C header parser in LabVIEW for another project) but also adding it to the released version of LabVIEW. How it got past the release manager I'm not sure but that person probably had no idea about how difficult a good C parser is, so he or she believed it to work fine after being shown some successful imports from not to complicated APIs :shifty: .

Since it will be almost impossible to remove that tool now, it will stay there but I'm not sure there will be enough support for it once the father of this project moves on to other tasks.

Rolf Kalbermatter

Link to comment

QUOTE (normandinf @ Jan 6 2009, 08:59 AM)

http://forums.ni.com/ni/board/message?boar...ding&page=1

Thanks rolfk the link above will give you some history to my nightmare.......lol. What is confusing to me,is how to find the order of the dll's and functions to get what I need.

There has to be some documentation out there that would give you some idea of the order in which to call functions.........one would think....lol

I would think when trying to find USB devices using C++ they would need the order as well.

Link to comment

QUOTE (normandinf @ Jan 6 2009, 08:59 AM)

http://forums.ni.com/ni/board/message?boar...ding&page=1

Thanks rolfk the link above will give you some history to my nightmare.......lol. What is confusing to me,is how to find the order of the dll's and functions to get what I need.

There has to be some documentation out there that would give you some idea of the order in which to call functions.........one would think....lol

I would think when trying to find USB devices using C++ they would need the order as well.

Link to comment

QUOTE (normandinf @ Jan 6 2009, 08:59 AM)

http://forums.ni.com/ni/board/message?boar...ding&page=1

Thanks rolfk the link above will give you some history to my nightmare.......lol. What is confusing to me,is how to find the order of the dll's and functions to get what I need.

There has to be some documentation out there that would give you some idea of the order in which to call functions.........one would think....lol

I would think when trying to find USB devices using C++ they would need the order as well.

Link to comment

QUOTE (normandinf @ Jan 6 2009, 08:59 AM)

http://forums.ni.com/ni/board/message?boar...ding&page=1

Thanks rolfk the link above will give you some history to my nightmare.......lol. What is confusing to me,is how to find the order of the dll's and functions to get what I need.

There has to be some documentation out there that would give you some idea of the order in which to call functions.........one would think....lol

I would think when trying to find USB devices using C++ they would need the order as well.

Link to comment

QUOTE (normandinf @ Jan 6 2009, 08:59 AM)

http://forums.ni.com/ni/board/message?boar...ding&page=1

Thanks rolfk the link above will give you some history to my nightmare.......lol. What is confusing to me,is how to find the order of the dll's and functions to get what I need.

There has to be some documentation out there that would give you some idea of the order in which to call functions.........one would think....lol

I would think when trying to find USB devices using C++ they would need the order as well.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.