qq_39703510
钴龘子
2021-06-16 19:08
采纳率: 50%
浏览 55

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

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

#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 BASE                   ((uint_T) mxGetPr(BASE_ADDRESS_ARG)[0])   
#define SAMPLE_TIME            ((real_T) mxGetPr(SAMPLE_TIME_PARAM)[0])   
#define SAMPLE_OFFSET          ((real_T) mxGetPr(SAMPLE_TIME_PARAM)[1])    

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;
    char devName[20];   
    strcpy(devName,"PCI-1724u");    
    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;
    uint_T baseAddr = BASE;
    
    unsigned char ucStatus;
    rl32eOutpB((unsigned short)(BASE+4),0);
    for (i=0;i<mxGetNumberOfElements(CHANNEL_ARG);i++) {     
        y=ssGetInputPortSignal(S,i);                                          
        rl32eOutpDW((unsigned short)baseAddr,(unsigned short)1097983);
		rl32eOutpDW((unsigned short)baseAddr,(unsigned short)1163519);
		rl32eOutpDW((unsigned short)baseAddr,(unsigned short)1229055); 
	}  
#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  

 程序里我通过手写基地址,查询板卡基地址为d300,我输入了转换后的值:54016,并且给电流最大值常值。驱动在simulink中可以编译和运行,但是没有实际电流输出。

运行过程中,MATLAB出了以下问题,但没有停止运行:

警告: 执行为类 MathWorks.xPCTarget.FrameWork.xPCTargetPC 定义的事件 Unloaded 的侦听程序回调时出现错误:
错误使用 SimulinkRealTime.internal.ToolStripContext/targetUnloadedCB
Invalid Simulink object handle

出错 SimulinkRealTime.internal.ToolStripContext>@(varargin)this.targetUnloadedCB(varargin{:})

出错 SimulinkRealTime.target/XCPLoadingCB

出错 SimulinkRealTime.target>@(varargin)tg.XCPLoadingCB(varargin{:})

出错 SimulinkRealTime.target/load

出错 SimulinkRealTime.internal.ToolStrip

出错 SimulinkRealTime.internal.ToolStrip

出错 SimulinkRealTime.internal.ToolStrip - Show complete stack trace 
> In SimulinkRealTime/target/XCPLoadingCB
  In SimulinkRealTime.target>@(varargin)tg.XCPLoadingCB(varargin{:})
  In SimulinkRealTime.target/load
  In SimulinkRealTime.internal.ToolStrip
  In SimulinkRealTime.internal.ToolStrip
  In SimulinkRealTime.internal.ToolStrip 
警告: 执行为类 MathWorks.xPCTarget.FrameWork.xPCTargetPC 定义的事件 Loaded 的侦听程序回调时出现错误:
错误使用 SimulinkRealTime.internal.ToolStripContext/synchToolStripWithSelectedTarget
Invalid Simulink object handle

出错 SimulinkRealTime.internal.ToolStripContext/targetLoadedCB

出错 SimulinkRealTime.internal.ToolStripContext>@(varargin)this.targetLoadedCB(varargin{:})

出错 SimulinkRealTime.target/load

出错 SimulinkRealTime.internal.ToolStrip

出错 SimulinkRealTime.internal.ToolStrip

出错 SimulinkRealTime.internal.ToolStrip - Show complete stack trace 
> In SimulinkRealTime.target/load
  In SimulinkRealTime.internal.ToolStrip
  In SimulinkRealTime.internal.ToolStrip
  In SimulinkRealTime.internal.ToolStrip 

 

是这个问题导致了我的电流输出无信号吗?有没有什么简单的方法验证错误的具体原因?

或者是否有其他型号pci输出板卡的simulink real time(xpc)驱动能够为我提供一些借鉴?

 

附上pci1724u板卡的寄存器说明,希望有帮助:

 

  • 点赞
  • 收藏

1条回答 默认 最新

  • QA_Assistant
    有问必答小助手 2021-06-18 19:10

    你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答

    本次提问扣除的有问必答次数,已经为您补发到账户,我们后续会持续优化,扩大我们的服务范围,为您带来更好地服务。

    点赞 评论

相关推荐