qq_39703510
钴龘子
采纳率50%
2021-06-09 20:49 阅读 68

编写适用于simulink real time的pci1724u板卡驱动

100

 我在编写适用于simulink real time的pci1724u板卡驱动,现在驱动可以下载运行,但是没有电流输出。不知道是哪里出了问题,大神们帮我看看吧!!!!救救孩子

/* adadvPCI1724.c - xPC Target, non-inlined S-function driver for A/D section of Advantech PCI1724 board */   
   
   
#define     S_FUNCTION_LEVEL    2   
#define     S_FUNCTION_NAME     adadvPCI1724u   
   
#include    <stdlib.h>   
   
#include    "simstruc.h"    
   
#ifdef      MATLAB_MEX_FILE   
#include    "mex.h"   
#else   
#include    <windows.h>   
#include    "io_xpcimport.h"   
#endif   
   
   
   
/* Input Arguments */   
#define NUM_PARAMS             (4) 
#define BASE_ADDRESS_ARG       (ssGetSFcnParam(S,0))   
#define CHANNEL_ARG            (ssGetSFcnParam(S,1))   
#define RANGE_ARG              (ssGetSFcnParam(S,2))   
#define SAMPLE_TIME_PARAM      (ssGetSFcnParam(S,3))  
   
/* Convert S Function Parameters to Varibles */   
   
#define SAMPLE_TIME            ((real_T) mxGetPr(SAMPLE_TIME_PARAM)[0])   
#define SAMPLE_OFFSET          ((real_T) mxGetPr(SAMPLE_TIME_PARAM)[1])    

int BASE;
static char_T msg[256];   
   
/*====================*  
 * S-function methods *  
 *====================*/   
   
static void mdlCheckParameters(SimStruct *S)   
{   
}   
   
static void mdlInitializeSizes(SimStruct *S)   
{   
    uint_T i;   
        
    ssSetNumSFcnParams(S, NUM_PARAMS);   
       
    if (ssGetNumSFcnParams(S) == ssGetSFcnParamsCount(S)) {   
        mdlCheckParameters(S);   
        if (ssGetErrorStatus(S) != NULL) {   
            return;   
        }   
    } else {   
        return; /* Parameter mismatch will be reported by Simulink */   
    }   
   
    ssSetNumContStates(S, 0);   
    ssSetNumDiscStates(S, 0);/*No use*/   
   
       
   
    if (!ssSetNumOutputPorts(S, 0)) return; 
   
    if (!ssSetNumInputPorts(S, mxGetNumberOfElements(CHANNEL_ARG))) return; 
   
    for (i=0;i<mxGetNumberOfElements(CHANNEL_ARG);i++) {                      
        ssSetInputPortWidth(S, i, 1);   
    }   
   
    ssSetNumSampleTimes(S, 1);                                              
   
    ssSetSFcnParamNotTunable(S,0);
    ssSetSFcnParamNotTunable(S,1);   
    ssSetSFcnParamNotTunable(S,2);   
    ssSetSFcnParamNotTunable(S,3);   
   
    ssSetOptions(S, SS_OPTION_EXCEPTION_FREE_CODE | SS_OPTION_PLACE_ASAP);   
       
}   
   
static void mdlInitializeSampleTimes(SimStruct *S)                   
{   
    ssSetSampleTime(S, 0, SAMPLE_TIME);   
    ssSetOffsetTime(S, 0, SAMPLE_OFFSET);   
}   
   
    
#define MDL_START   
static void mdlStart(SimStruct *S)   
{   
   #ifndef MATLAB_MEX_FILE   
    unsigned char ucStatus;
	PCIDeviceInfo pciinfo;
    char devName[20];   
    strcpy(devName,"PCI-1724u");    
	rl32eGetPCIInfo(0x13FE, (unsigned short)0x1724, &pciinfo);
    BASE = (uint_T)pciinfo.BaseAddress[2];
    rl32eOutpDW((unsigned short)(BASE+4),0);           /* 同步输出*/   
#endif                    
}   
   
static void mdlOutputs(SimStruct *S, int_T tid)   
{   
   
#ifndef MATLAB_MEX_FILE   
   
    uint_T i,j, n, channel;     
    real_T *y, range, res;
    unsigned char ucStatus;
    rl32eOutpB((unsigned short)(BASE+4),0);
    for (i=0;i<mxGetNumberOfElements(CHANNEL_ARG);i++) {     
        y=ssGetInputPortSignal(S,i);                                          
        rl32eOutpDW((unsigned short)BASE,0x11cfff);
		rl32eOutpDW((unsigned short)BASE,0x12cfff);
		rl32eOutpDW((unsigned short)BASE,0x10cfff); 
        res=(rl32eInpW((unsigned short)BASE)&0xFFFF);
	}  
    
#endif   
}     
   
static void mdlTerminate(SimStruct *S)   
{      
}   
   
   
#ifdef MATLAB_MEX_FILE  /* Is this file being compiled as a MEX-file? */   
#include "simulink.c"   /* Mex glue */   
#else   
#include "cg_sfun.h"    /* Code generation glue */   
#endif  

想知道问题具体出在哪里?怎么编写成功啊?

  • 点赞
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • qq_39703510 钴龘子 2021-06-09 21:27

    或者有其他研华pci的输出板卡适用于simulink real time(xpc)的例子也可以的

    点赞 评论 复制链接分享
  • Feng_wwf 王文峯 2021-06-09 23:43

    代码如下,如有帮助,请采纳一下,谢谢

     

    点赞 评论 复制链接分享
  • QA_Assistant 有问必答小助手 2021-06-10 11:08

    您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

    如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

    ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

    点赞 评论 复制链接分享

相关推荐