微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 测试测量 > 虚拟仪器 > LabView和VC混合编程,需要什么软件?

LabView和VC混合编程,需要什么软件?

时间:12-13 整理:3721RD 点击:
呵呵~~
给您磕头了,回信箱,谢谢

什么叫混合编程啊,通过CIN代码接口就可以了吧

这个CIN是lv自带的不?不要其他软件了吧?

对头,将需调用的外部代码编译成LabVIEW所能识别的格式后与CIN的结点相连即可,Function Pallet-Advanced-Code Interface Node

看看labview自带的文档
D:\Program Files\National Instruments\LabVIEW 7.0\manuals\lvexcode.pdf

精华区x-6-2

这个虽然古老了一点,但是还是很不错的

我用的是在lv里调用vc里做的dll,呵呵
也很方便啊
而且这个不光lv可以调用,很多都可以调用

通过CIN或者CLF都可以做到
CLF主要是调用vc生成的dll

偶编译的时候说VC里的一个头文件使用的一个数据结构不对,怎么弄?

lv的manual里有简单的例子,按它的步骤走一遍看看。
还不成的话就把代码贴上来让大家看看
lv中对于数组等数据类型的定义和c不一样,编写cin时要注意。

事实上那个防止数据结构定义区别的头文件我加进去了啊
出错的数据结构是驱动代码里的一个很长的名字的数据结构,在打开设备文件的函数里使用的,当时师兄说是头文件版本不对
我用的是LV7和VC6加XP DDK,一个ISA卡的驱动程序要用VI调用.
VC下调用驱动代码是:
include <windows.h>
#include <stdio.h>
#include <setupapi.h>
//一定在xxxGUID.H前
#include <initguid.h>  
//设备的GUID
#include "SCSGUID.H"
#include <winioctl.h>
//设备的控制命令宏定义
#include "SCSIOCTLs.H"
#define MAXNUM 200
typedef union tt
{
        unsigned int time;
        unsigned char t[2];
}timer;
typedef union cc
{
    unsigned long value;
        unsigned char r[4];
}counter;
typedef struct DeviceInfo
{
        //DeviceInfoList[7]记录设备的状态信息
        UCHAR  DeviceInfoList[7];
        //DeviceInfoBase结构记录基地址信息
    PUCHAR DeviceInfoPortBase;
}DeviceInfo;
HANDLE GetDeviceViaInterface(GUID* pGuid, DWORD Instance);
HANDLE GetDeviceViaInterface(GUID* pGuid, DWORD Instance)
{
        HDEVINFO Info = SetupDiGetClassDevs(pGuid, NULL, NULL, DIGCF_PRESENT|DIGCF_INTERFACEDEVICE);
        if(Info == INVALID_HANDLE_VALUE)
        {
                printf("No HDEVINFO available for this GUID\n");
                return NULL;
        }
        SP_INTERFACE_DEVICE_DATA Infodata;
        Infodata.cbSize = sizeof(Infodata);
        if(!SetupDiEnumDeviceInterfaces(Info, NULL, pGuid,Instance, &Infodata))
        {
                printf("NO SP_INTERFACE_DEVICE_DATA available for this GUID\n");
        SetupDiDestroyDeviceInfoList(Info);
                return NULL;
        }
        //获取符号连接名字节数
        DWORD RegLen;
        SetupDiGetDeviceInterfaceDetail(Info, &Infodata, NULL, 0, &RegLen, NULL);
        PSP_INTERFACE_DEVICE_DETAIL_DATA ifDetail =
                (PSP_INTERFACE_DEVICE_DETAIL_DATA)(new char [RegLen]);
        if(ifDetail == NULL)
        {
                SetupDiDestroyDeviceInfoList(Info);
        return NULL;
        }
        //获得符号连接名
        ifDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
    if(!SetupDiGetDeviceInterfaceDetail(Info, &Infodata, ifDetail, RegLen, NULL, NULL))
        {
                SetupDiDestroyDeviceInfoList(Info);
                delete ifDetail;
                return NULL;
        }
        printf("Symbolic link is %s\n", ifDetail->DevicePath);
        HANDLE rv = CreateFile(ifDetail->DevicePath,
                                   GENERIC_READ|GENERIC_WRITE,
                                                   FILE_SHARE_READ|FILE_SHARE_WRITE,
                                                   NULL, OPEN_EXISTING,
                                                   FILE_ATTRIBUTE_NORMAL, NULL);
        if(rv == INVALID_HANDLE_VALUE)
                rv = NULL;
        delete ifDetail;
        SetupDiDestroyDeviceInfoList(Info);
        return rv;
}
int main(int argc, char* argv[])
{
        //获得文件句柄
        DWORD dwNewPtr;
        DeviceInfo DI;
        int select;
        timer time;
        counter counter, counter2;
        HANDLE hDevice;
        DWORD TxdBytes;
        unsigned char lpInBuffer[7] ;
        unsigned char lpOutBuffer[7] ;
        bool State = false;
    unsigned long charvalue[MAXNUM];
        int j;
        for(j=0;j<MAXNUM;j++)
        {
                charvalue[j] = 0;
        }
        hDevice = GetDeviceViaInterface((LPGUID)&GUID_ISASCS, 0);
        if(hDevice == NULL)
        {
                printf("Can not open device handle.\n");
                return 1;
        }
        printf("Open device successfully.\n");
        State = DeviceIoControl(hDevice,
                                    IOCTL_READ_DEVICE_INFO,
                                                        NULL,
                                                        0,
                                                        &DI,
                                                        sizeof(DI),                                            
                                                        &TxdBytes,
                                                        NULL);
        
        //printf("Get device info:\n%x\n%x\n%x\n%x\n%x\n%x\n%x\n%x\n",DI.DeviceInfoList[0],
        //                                                                  DI.DeviceInfoList[1],
        //                                                                                  DI.DeviceInfoList[2],
        //                                                                                  DI.DeviceInfoList[3],
        //                                                                                  DI.DeviceInfoList[4],
        //                                                                                  DI.DeviceInfoList[5],
        //                                                                                  DI.DeviceInfoList[6],
        //                                                                                  DI.DeviceInfoPortBase);
    
        //printf("TxdBytes of %d.\n",TxdBytes);
        //getchar();
        printf("选择定时(为0)或定数(非0):");
    scanf("%d",&select);
        if(select == 0)
        {
            //设置文件指针:0偏移
            dwNewPtr = SetFilePointer(hDevice, 0x00, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
        lpInBuffer[0] = 0;
        lpInBuffer[1] = 0;
            lpInBuffer[2] = 1;
            lpInBuffer[3] = 0;
            WriteFile(hDevice, lpInBuffer, sizeof(lpInBuffer), &TxdBytes, NULL);
            //printf("Setting Bytes\n");
                //printf("Setting Bytes\n");
                //printf("Setting Bytes\n");
                //printf("Setting Bytes\n");
                //printf("Setting Bytes\n");
                //printf("Setting Bytes\n");
                for(j=0;j<100000;j++)
                {
            //设置文件指针:1偏移
            dwNewPtr = SetFilePointer(hDevice, 0x01, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
        time.time = 10;
            lpInBuffer[0] = time.t[0];
        lpInBuffer[1] = time.t[1];
                time.time = 65535;
            lpInBuffer[2] = time.t[0];
            lpInBuffer[3] = time.t[1];
            lpInBuffer[4] = 0;
                lpInBuffer[5] = 0;
                lpInBuffer[6] = 0;
            WriteFile(hDevice, lpInBuffer, sizeof(lpInBuffer), &TxdBytes, NULL);
            //printf("Setting %d Bytes\n", TxdBytes);
                //设置文件指针:2偏移
            dwNewPtr = SetFilePointer(hDevice, 0x02, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
            WriteFile(hDevice, lpInBuffer, sizeof(lpInBuffer), &TxdBytes, NULL);
            //printf("clear #2.Setting %d Bytes\n", TxdBytes);
                //设置文件指针:3偏移
            dwNewPtr = SetFilePointer(hDevice, 0x03, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
            WriteFile(hDevice, lpInBuffer, sizeof(lpInBuffer), &TxdBytes, NULL);
            //printf("clear #3.Setting %d Bytes\n", TxdBytes);
                //设置文件指针:0偏移
            dwNewPtr = SetFilePointer(hDevice, 0x00, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
            lpInBuffer[0] = 0;
        lpInBuffer[1] = 0;
            lpInBuffer[2] = 1;
            lpInBuffer[3] = 1;
            WriteFile(hDevice, lpInBuffer, sizeof(lpInBuffer), &TxdBytes, NULL);
            //printf("start.Setting %d Bytes\n", TxdBytes);
            //设置文件指针:1偏移
            dwNewPtr = SetFilePointer(hDevice, 0x01, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
        do{
                ReadFile(hDevice, lpOutBuffer, sizeof(lpOutBuffer), &TxdBytes, NULL);
                }while((lpOutBuffer[6]&0x01) != 1);
        //printf("end.\n");
                //设置文件指针:0偏移
            dwNewPtr = SetFilePointer(hDevice, 0x00, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
        lpInBuffer[0] = 0;
        lpInBuffer[1] = 0;
            lpInBuffer[2] = 1;
            lpInBuffer[3] = 0;
            WriteFile(hDevice, lpInBuffer, sizeof(lpInBuffer), &TxdBytes, NULL);
            //printf("stop.Setting %d Bytes\n", TxdBytes);
                //设置文件指针:2偏移
            dwNewPtr = SetFilePointer(hDevice, 0x02, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
                ReadFile(hDevice, lpOutBuffer, sizeof(lpOutBuffer), &TxdBytes, NULL);
        counter.r[0] = lpOutBuffer[0];
                counter.r[1] = lpOutBuffer[1];
                counter.r[2] = lpOutBuffer[2];
                counter.r[3] = lpOutBuffer[3];
                counter.r[4] = lpOutBuffer[4];
                if(counter.value<MAXNUM)
                {
                    charvalue[counter.value] += 1;
                }
                //printf("Count : %ld\n",counter.value);
                }
                for(j=0;j<20;j++)
                {
                        printf("Count: %5d record ",charvalue[j]);
                }              
            getchar();      
        }
        if(select == 1)
        {
                for(j=0;j<10;j++)
                {
            //设置文件指针:0偏移
            DWORD dwNewPtr = SetFilePointer(hDevice, 0x00, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
        lpInBuffer[0] = 1;
        lpInBuffer[1] = 0;
            lpInBuffer[2] = 1;
            lpInBuffer[3] = 0;
            WriteFile(hDevice, lpInBuffer, sizeof(lpInBuffer), &TxdBytes, NULL);
            printf("Setting %d Bytes\n", TxdBytes);
            //设置文件指针:1偏移
            dwNewPtr = SetFilePointer(hDevice, 0x01, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
            lpInBuffer[4] = 0;
                lpInBuffer[5] = 0;
                lpInBuffer[6] = 0;
            WriteFile(hDevice, lpInBuffer, sizeof(lpInBuffer), &TxdBytes, NULL);
            printf("Setting %d Bytes\n", TxdBytes);
                //设置文件指针:2偏移
            dwNewPtr = SetFilePointer(hDevice, 0x02, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
        time.time = 1001;
            lpInBuffer[0] = time.t[0];
        lpInBuffer[1] = time.t[1];
            lpInBuffer[2] = 0;
            lpInBuffer[3] = 0;
            WriteFile(hDevice, lpInBuffer, sizeof(lpInBuffer), &TxdBytes, NULL);
            //printf("clear #2.Setting %d Bytes\n", TxdBytes);
                //设置文件指针:3偏移
            dwNewPtr = SetFilePointer(hDevice, 0x03, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
            WriteFile(hDevice, lpInBuffer, sizeof(lpInBuffer), &TxdBytes, NULL);
            //printf("clear #3.Setting %d Bytes\n", TxdBytes);
                //设置文件指针:0偏移
            dwNewPtr = SetFilePointer(hDevice, 0x00, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
            lpInBuffer[0] = 1;
        lpInBuffer[1] = 0;
            lpInBuffer[2] = 1;
            lpInBuffer[3] = 1;
            WriteFile(hDevice, lpInBuffer, sizeof(lpInBuffer), &TxdBytes, NULL);
            printf("Setting %d Bytes\n", TxdBytes);
            //设置文件指针:2偏移
            dwNewPtr = SetFilePointer(hDevice, 0x02, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
        do{
                ReadFile(hDevice, lpOutBuffer, sizeof(lpOutBuffer), &TxdBytes, NULL);
                }while((lpOutBuffer[5] & 0x01) != 0x01);
                //设置文件指针:0偏移
            dwNewPtr = SetFilePointer(hDevice, 0x00, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
        lpInBuffer[0] = 1;
        lpInBuffer[1] = 0;
            lpInBuffer[2] = 1;
            lpInBuffer[3] = 0;
            WriteFile(hDevice, lpInBuffer, sizeof(lpInBuffer), &TxdBytes, NULL);
            printf("Setting %d Bytes\n", TxdBytes);
                //设置文件指针:1偏移
            dwNewPtr = SetFilePointer(hDevice, 0x01, NULL, FILE_BEGIN);
            if(dwNewPtr == 0xFFFFFFFF)
                return 0;
                ReadFile(hDevice, lpOutBuffer, sizeof(lpOutBuffer), &TxdBytes, NULL);
        counter.r[0] = lpOutBuffer[4];
                counter.r[1] = lpOutBuffer[5];
                counter.r[2] = 0;
                counter.r[3] = 0;
                counter2.r[0] = lpOutBuffer[0];
                counter2.r[1] = lpOutBuffer[1];
                counter2.r[2] = lpOutBuffer[2];
                counter2.r[3] = lpOutBuffer[3];
            printf("time : %d \n", counter.value, counter2.value);
                }
            getchar();
        }
        CloseHandle(hDevice);
        printf("Device close.\n");
        getchar();
        return 0;
}
但是LV下调用那些函数就编译说数据结构有问题.
基本上在LV下我就是把这些代码直接使用在LV的CIN代码里了,当然入口函数改成了LV的CIN入口函数,打印函数之类的地方也做了修改。也加了CIN必要的头文件。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top