void FORTE_X20DI9371::executeEvent(int pa_nEIID){ switch (pa_nEIID){ case scm_nEventINITID: if(QI() == true){ m_bInitOk = false; CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); // Get settings for intputs CProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixOut()->getModuleEntries(CNID(), MODID()); if(moduleIOs){ // Inputs (process inputs) always start with i = 1 // Check xap.xml if a BitUnused is present for(unsigned int i = 1; i < moduleIOs->getNrOfEntries() - 1; i++){ m_oEplMapping.m_lCurrentValues.push_back(new SEplMapping::SEplMappingValues(moduleIOs->getEntry(i)[0], moduleIOs->getEntry(i)[1], moduleIOs->getEntry(i)[2])); } delete moduleIOs; eplStack.registerCallback((IEplCNCallback*) this); m_bInitOk = true; } } QO() = QI(); CNIDO() = CNID(); sendOutputEvent(scm_nEventINITOID); break; case scm_nEventREQID: if(QI() == true && m_bInitOk){ m_oSync.lock(); SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); for(int i = 3; i < m_pstInterfaceSpec->m_nNumDOs && it != itEnd; i++, ++it){ bool ioVal = false; ioVal = *(it->m_pchCurrentValue) != 0x00; *static_cast<CIEC_BOOL*>(getDO(i)) = ioVal; } m_oSync.unlock(); } QO() = QI(); sendOutputEvent(scm_nEventCNFID); break; } }
int t4012___store(int *niddsc, InStoreStruct *setup) { int channels; int pts; int memPerChannel; int channels_read; int dig; int dig_nid; static int memsize=0; static unsigned short *mem; int idxmin; int idxmax; char digname[512]; char *nodename; int chan_nid = 0; struct _t4012_status { unsigned sampling : 1; unsigned calibrate : 1; unsigned master_armed : 1; unsigned master_enabled : 1; unsigned stop_received : 1; unsigned triggered : 1; unsigned t4012p : 1; unsigned cal_mem : 1; unsigned : 24; } dig_status; int status; static short offset; static float coefficient; static float f[2]; static DESCRIPTOR_A_BOUNDS(raw,sizeof(short),DTYPE_W,0,1,0); static int *lbound = &raw.bounds[0].l; static int *ubound = &raw.bounds[0].u; static unsigned int *acoef = &raw.m[0]; static DESCRIPTOR_A(f2_d,sizeof(f[0]),DTYPE_NATIVE_FLOAT,f,8); static DESCRIPTOR(counts_str,"counts"); static DESCRIPTOR(volts_str,"volts"); static DESCRIPTOR(seconds_str,"seconds"); static DESCRIPTOR_LONG(start_d,&raw.bounds[0].l); static DESCRIPTOR_LONG(end_d,&raw.bounds[0].u); static int trigger_nid; static DESCRIPTOR_NID(stop_d,&trigger_nid); static int switch_trig_nid; static DESCRIPTOR_NID(swi_d,&switch_trig_nid); static int extern_clock_nid; static DESCRIPTOR_NID(ext_clock_d,&extern_clock_nid); static struct descriptor offset_d = {2,DTYPE_W, CLASS_S, (char *)&offset}; static DESCRIPTOR_FLOAT(coef_d,&coefficient); static DESCRIPTOR_FLOAT(f1_d,f); static int _roprand = 32768; static DESCRIPTOR_FLOAT(roprand,&_roprand); static FUNCTION(1) value = {2,DTYPE_FUNCTION,CLASS_R,(unsigned char *)&OpcValue,0,0}; static DESCRIPTOR_FUNCTION_2(subtract_exp,(unsigned char *)&OpcSubtract,&value,&offset_d); static DESCRIPTOR_FUNCTION_2(mult_exp,(unsigned char *)&OpcMultiply,&coef_d,&subtract_exp); static DESCRIPTOR_WITH_UNITS(counts,&raw,&counts_str); static DESCRIPTOR_WITH_UNITS(volts,&mult_exp,&volts_str); static DESCRIPTOR_FUNCTION_2(rangesub,(unsigned char *)&OpcSubtract,0,&f1_d); static DESCRIPTOR_WINDOW(window,&start_d,&end_d,&stop_d); static struct descriptor *begin_ptrs[] = {&roprand,0}; static struct descriptor *end_ptrs[] = {(struct descriptor *)&rangesub,&roprand}; static DESCRIPTOR_APD(begin_apd,0,begin_ptrs,2); static DESCRIPTOR_APD(end_apd,0,end_ptrs,2); static DESCRIPTOR_RANGE(int_clock1_d,0,0,&f1_d); static DESCRIPTOR_RANGE(int_clock2_d,&begin_apd,&end_apd,&f2_d); static int clock_out_nid; static DESCRIPTOR_NID(clock_out_d,&clock_out_nid); static DESCRIPTOR_DIMENSION(dimension,&window,&clock_out_d); static DESCRIPTOR_WITH_UNITS(seconds,&dimension,&seconds_str); static DESCRIPTOR_SIGNAL_1(signal,&volts,&counts,&seconds); void *ctx = 0; max_time=-1; trigger_nid = setup->head_nid + T4012_N_TRIGGER; switch_trig_nid = setup->head_nid + T4012_N_SWITCH_TRIG; extern_clock_nid = setup->head_nid + T4012_N_EXTERN_CLOCK; clock_out_nid = setup->head_nid + T4012_N_CLOCK_OUT; pio(8,0,0); status = Input(setup,14); dig_status = *(struct _t4012_status *)&status; if (dig_status.sampling) { return DEV$_NOT_TRIGGERED; } channels = Input(setup,1); pts = Input(setup,2); memPerChannel = Input(setup,3) * 1024; if (Input(setup,7) == 1) TreePutRecord(clock_out_nid,(struct descriptor *)&ext_clock_d,0); else { int shift = Input(setup,6); f[0] = freqs[Input(setup,4)]; if (shift) { f[1] = freqs[Input(setup,5)]; rangesub.arguments[0] = begin_ptrs[1] = (shift == 1) ? &swi_d : &stop_d; TreePutRecord(clock_out_nid,(struct descriptor *)&int_clock2_d,0); } else TreePutRecord(clock_out_nid,(struct descriptor *)&int_clock1_d,0); } idxmin = (pts - 8.)/8. * memPerChannel; idxmax = idxmin + memPerChannel - 1; if (memsize < (memPerChannel * 2)) { if (memsize) free(mem); memsize = memPerChannel * 2; mem = malloc(memsize); } return_on_error(AccessTraq(setup,0x8001,16,0,0),status); /* Remote control */ nodename = TreeGetPath(setup->head_nid); strcpy(digname,nodename); TreeFree(nodename); strcat(digname,":T28%%_%%"); status = TreeFindNodeWild(digname,&dig_nid,&ctx,1 << TreeUSAGE_DEVICE); for (dig=1,channels_read=0;(channels_read < channels) && (status & 1);dig++) { static int dig_nids[1+8*T28XX_K_NODES_PER_INP]; static int nidlen; static NCI_ITM itmlst[] = {{sizeof(dig_nids),NciCONGLOMERATE_NIDS,(unsigned char *)&dig_nids,&nidlen}, {0,NciEND_OF_LIST,0,0}}; if (status & 1) { int i; int digchannels; status = TreeGetNci(dig_nid,itmlst); digchannels = (nidlen/sizeof(dig_nid)-1)/T28XX_K_NODES_PER_INP; for (i=0;i<digchannels && (status & 1) && channels_read < channels;i++) { if (TreeIsOn(CNID(i,HEAD))&1) { int channel_select = 0x0A000 | (channels_read + 1); AccessTraq(setup,channel_select,24,0,0); if (chan_nid && (*acoef > 1)) { return_on_error(TreePutRecord(chan_nid,(struct descriptor *)&signal,0),status); chan_nid = 0; } else DevWait((float).005); chan_nid = CNID(i,HEAD); *lbound = (DevLong(&CNID(i,STARTIDX),(int *)lbound) & 1) ? min(idxmax,max(idxmin,*lbound)) : idxmin; *ubound = (DevLong(&CNID(i,ENDIDX), (int *)ubound) & 1) ? min(idxmax,max(idxmin,*ubound)) : idxmax; *acoef = *ubound - *lbound + 1; if (*acoef > 0) { int points_read = 0; int first_sample_offset = *lbound-idxmin; int chunk = first_sample_offset/1024; int chunk_offset = first_sample_offset % 1024; float calib[]={0,0}; status = ReadChannel(setup, chunk,*acoef+chunk_offset,mem,&points_read,&CNID(i,CALIBRATION),calib); if (status & 1) { offset = calib[0]; if (calib[0] == calib[1]) coefficient = (offset > 1000) ? 10./4096 : 5./4096.; else coefficient = calib[1]; raw.pointer = (char *)(mem + chunk_offset); raw.a0 = raw.pointer - *lbound * sizeof(*mem); *ubound = (points_read - chunk_offset) + *lbound - 1; *acoef = (points_read - chunk_offset); raw.arsize = *acoef * 2; } } } channels_read++; } } if (channels_read < channels && (status & 1)) status = TreeFindNodeWild(digname,&dig_nid,&ctx,1 << TreeUSAGE_DEVICE); } TreeFindNodeEnd(&ctx); if (chan_nid && (*acoef > 1)) return_on_error(TreePutRecord(chan_nid,(struct descriptor *)&signal,0),status); return status; }