Specifications

A.1. ANALOG IN FILE
17
unsigned int ChLst[scanSize];
for (i = 0; i < scanSize; i++) {
ChLst[i]= CHLIST_ENT((int)mxGetPr(ChannelList)[i],(int)mxGetPr(GainSet)[0]-1,(int)mxGetPr(SlowBit)[0]);}
Handle = PdAcquireSubsystem(board, BoardLevel, 1);
if(Handle <0) {
printf("AI: PdAcquireSubsystem error %d\n", Handle);}
retVal = PdGetPciConfiguration(Handle, &pciConfig);
if(retVal != 0) {
printf("AI: PdGetPciConfiguration error %d\n", retVal);}
retVal = _PdAInSetCfg(Handle, aiCfg, 0, 0);
if (retVal < 0) {
printf("AI: _PdAInSetCfg error %d\n", retVal);}
retVal = _PdAInSetChList(Handle, scanSize, ChLst);
if (retVal < 0) {
printf("AI: _PdAInSetChList error %d\n", retVal);}
retVal = _PdAInEnableConv(Handle, TRUE);
if (retVal < 0) {
printf("AI: _PdAInEnableConv error %d\n", retVal);}
retVal = iopl(3);
if(retVal != 0) {
printf("AI: iopl failed, make sure you have root permission\n");}
if((mem_fd = open("/dev/mem", O_RDWR)) < 0) {
printf("AI: open(/dev/mem) error %d\n", mem_fd);}
bar0Address = mmap(0, 16384, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, pciConfig.BaseAddress0);
if(bar0Address == (void*)-1 || bar0Address == NULL) {
printf("AI: mmap error %d\n", (int)bar0Address);}
retVal = _PdAInSwStartTrig(Handle);
if (retVal < 0) {
printf("AI: _PdAInSwStartTrig failed with %d.\n", retVal);}
#endif
}
static void mdlInitializeSampleTimes(SimStruct *S) {
ssSetSampleTime(S,0,CONTINUOUS_SAMPLE_TIME);
ssSetOffsetTime(S,0,0.0);
}
static void mdlOutputs(SimStruct *S, int_T tid) {
real_T *y;
#ifndef MATLAB_MEX_FILE
unsigned long* rawbuffer[16]; //change if more channels are needed
double buffer[16]; //change if more channels are needed
AiGetAIValue(scanSize, rawbuffer, Delay);
for(i=0; i < scanSize; i++) {
y=ssGetOutputPortRealSignal(S,i);
y[0]=(((unsigned long)rawbuffer[i] ^ 0x8000) * BitWeight + Displacement)/Gain;
}
#endif }
static void mdlTerminate(SimStruct *S) { #ifndef MATLAB_MEX_FILE
munmap(bar0Address, mem_fd);
close(mem_fd);
retVal = _PdAInReset(Handle);
if (retVal < 0) {
printf("AI: PdAInReset error %d\n", retVal);}
retVal = PdAcquireSubsystem(Handle, BoardLevel, 0);
if (retVal < 0) {
printf("AI: PdReleaseSubsystem error %d\n", retVal);}
#endif }