Thread: Data Acquisition

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    2

    Data Acquisition

    Hi, I have this NI USB data acquisition device and although NI gives Labview but our prof had asked us to write a c program to access data from that card. Please give me directions on how to proceed on this.. Any tutorials , examples would of great help to me .
    Please HEP!!!!!

  2. #2

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    505
    Quote Originally Posted by entsecy View Post
    Hi, I have this NI USB data acquisition device and although NI gives Labview but our prof had asked us to write a c program to access data from that card. Please give me directions on how to proceed on this.. Any tutorials , examples would of great help to me .
    Please HEP!!!!!
    To communicate with USB IO Driver one must first enumerate the
    device. The enumeration of the device returns a device name. This
    device name is used to open the interface, using CreateFile(). Once
    you have the handle from CreateFile() you can use DeviceIOControl()
    to communicate to the USB IO Device and CloseHandle() to close it.
    The hardest part is getting the device name the rest is simply. To send
    commands to the USB IO device simply build a command packet and
    submit it using the DeviceIOControl functions.

    To get the device name use Windows™
    device manger. To do this one calls a function in the setupapi.dll.
    Simply poll the device manger with the USB I/O GUID for all the
    devices that match the GUID given. The device manger will return
    the device names for all the devices currently available on your
    system.

    Use the DEFINE_GUID macro to build the GUID.
    Code:
    // {B5157D69-75F8-11d3-8CE0-00207815E611}
    DEFINE_GUID(USBIODS_GUID,
    0xb5157d69, 0x75f8, 0x11d3, 0x8c, 0xe0, 0x0, 0x20, 0x78, 0x15,
    0xe6, 0x11);
    This GUID is passed to SetupDiGetClassDevs(), which returns a
    handle to the device. The enumeration functions are found in the
    setupapi library.

    Code:
    HDEVINFO hinfo = SetupDiGetClassDevs(&USBIODS_GUID, NULL,
    NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
    The first argument identifies the interface you’re looking for. The
    flag bits in the last argument indicate that you are looking for the
    interfaces exported by the USB I/O device.

    Once you have a handle to the device information set, you can
    perform an enumeration of all the devices that export the particular
    interface you’re interested in. See Microsoft function documentation
    for more information on setupapi.dll library functions.

    Poll the device manager till there are no matching devices left.

    Code:
    int i;
    Cstring Devices[10];
    // an array of cstrings
    for (DWORD i=0; ; ++i)
    {
    SP_INTERFACE_DEVICE_DATA Interface_Info;
    Interface_Info.cbSize = sizeof(Interface_Info);
    // Enumerate device
    if (!SetupDiEnumInterfaceDevice(hInfo, NULL, (LPGUID)
    &USBIODS_GUID,i, &Interface_Info))
    {
    SetupDiDestroyDeviceInfoList(hInfo);
    return(i);
    }
    
    DWORD needed;
    // get the required lenght
    SetupDiGetInterfaceDeviceDetail(hInfo, &Interface_Info,
    NULL, 0, &needed, NULL);
    PSP_INTERFACE_DEVICE_DETAIL_DATA detail =
    (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc(needed);
    if (!detail)
    
    {
    SetupDiDestroyDeviceInfoList(hInfo);
    return(i);
    }
    // fill the device details
    detail->cbSize =
    sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
    if (!SetupDiGetInterfaceDeviceDetail(hInfo,
    &Interface_Info,detail, needed,NULL, NULL))
    {
    free((PVOID) detail);
    SetupDiDestroyDeviceInfoList(hInfo);
    return(i);
    }
    
    char name[MAX_PATH];
    strncpy(name, detail->DevicePath, sizeof(name));
    free((PVOID) detail);
    Devices[i] = name;
    // keep a copy of each device name
    } // end of for loop
    After this code runs you end up with a list of device names, or NULL
    if no devices could be found (i = 0). Each device name will represent
    one USB I/O device that is plugged into your computer. If you know
    that you will only support one USB I/O device on your system at one
    time, you can reduce the enumeration code by dropping the for loop
    and only going through the code once. The device name(s) that are
    returned from the above code have a port number prefixed to the
    original GUID. The port number is related to order of the plug and
    play devices on your machine and can not be predetermined. The
    device name should look like the following.

    Code:
    \\.\0000000000000012#{b5157d69-75f8-11d3-8ce0-00207815e611}
    This is the complete device name one will use in order to
    communicate with the USB I/O device.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-06-2011, 07:43 AM
  2. How get data acquisition from printer using winsock?
    By Galvatron in forum Networking/Device Communication
    Replies: 1
    Last Post: 05-21-2008, 03:16 AM
  3. Replies: 14
    Last Post: 12-28-2007, 12:26 AM
  4. Replies: 21
    Last Post: 11-03-2007, 02:56 PM
  5. Image acquisition code
    By ejohns85 in forum C Programming
    Replies: 14
    Last Post: 08-24-2006, 11:36 PM