/*----------------------------------------------------------------------------*\ Read method for the Pb Ai card \*----------------------------------------------------------------------------*/ static pwr_tStatus IoCardRead ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { io_sCardLocal *local; pwr_sClass_Pb_Ai *op; io_sChannel *chanp; pwr_sClass_ChanAi *cop; pwr_sClass_Ai *sop; pwr_tInt16 data = 0; pwr_tUInt16 udata = 0; pwr_tFloat32 actvalue; int i; local = (io_sCardLocal *) cp->Local; op = (pwr_sClass_Pb_Ai *) cp->op; if (op->Status >= 1) { for (i=0; i<cp->ChanListSize; i++) { chanp = &cp->chanlist[i]; if (!chanp->cop) continue; cop = (pwr_sClass_ChanAi *) chanp->cop; sop = (pwr_sClass_Ai *) chanp->sop; if (cop->CalculateNewCoef) io_AiRangeToCoef(chanp); if (cop->ConversionOn) { if (local->scancount[i] <= 1) { memcpy(&udata, local->input_area + op->OffsetInputs + 2*i, 2); if (local->byte_swap == 1) udata = swap16(udata); data = (pwr_tInt16) udata; sop->RawValue = data; sop->SigValue = data * cop->SigValPolyCoef1 + cop->SigValPolyCoef0; switch(chanp->ChanClass) { case pwr_cClass_ChanAi: io_ConvertAi(cop, data, &actvalue); break; case pwr_cClass_ChanAit: io_ConvertAit((pwr_sClass_ChanAit *) cop, data, &actvalue); break; } // Filter if (sop->FilterType == 1 && sop->FilterAttribute[0] > 0 && sop->FilterAttribute[0] > ctx->ScanTime) { actvalue = *(pwr_tFloat32 *) chanp->vbp + ctx->ScanTime / sop->FilterAttribute[0] * (actvalue - *(pwr_tFloat32 *) chanp->vbp); } *(pwr_tFloat32 *) chanp->vbp = actvalue; local->scancount[i] = cop->ScanInterval + 1; } local->scancount[i]--; } // if ...ConversionOn } // for } // if ...op->Status return 1; }
/*----------------------------------------------------------------------------*\ \*----------------------------------------------------------------------------*/ static pwr_tStatus IoCardRead ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { pwr_tStatus sts; io_sLocal *local; pwr_tUInt16 data = 0; pwr_sClass_Ai_7436 *op; int i; pwr_tFloat32 actvalue; pwr_tFloat32 *polycoef_p; io_sChannel *chanp; pwr_sClass_ChanAi *cop; pwr_sClass_Ai *sop; if ( cp->AgentControlled) return IO__SUCCESS; local = (io_sLocal *) cp->Local; op = (pwr_sClass_Ai_7436 *) cp->op; chanp = &cp->chanlist[0]; for ( i = 0; i < cp->ChanListSize; i++) { if ( !chanp->cop) { chanp++; continue; } cop = (pwr_sClass_ChanAi *) chanp->cop; sop = (pwr_sClass_Ai *) chanp->sop; if ( cop->CalculateNewCoef) AiRangeToCoef( chanp); if ( cop->ConversionOn) { if ( local->ScanCount[i] <= 1) { data = rtpai_read( local->RackAddress, (local->Address & 0xf), i, /* mask out fix bits */ local->CardType[i]); if (io_readerr || io_fatal_error) { /* Exceptionhandler was called */ if ( io_fatal_error) { /* Activate emergency break */ errh_Error( "Fatal read error, card '%s', IO is stopped", cp->Name); ctx->Node->EmergBreakTrue = 1; return IO__ERRDEVICE; } /* Increase error count and check error limits */ op->ErrorCount++; if ( op->ErrorCount == op->ErrorSoftLimit) errh_Error( "IO Error soft limit reached on card '%s'", cp->Name); if ( op->ErrorCount >= op->ErrorHardLimit) { errh_Error( "IO Error hard limit reached on card '%s', IO stopped", cp->Name); ctx->Node->EmergBreakTrue = 1; return IO__ERRDEVICE; } chanp++; continue; } /* Convert rawvalue to sigvalue and actualvalue */ sop->RawValue = data; switch ( chanp->ChanClass) { case pwr_cClass_ChanAi: io_ConvertAi( cop, (pwr_tInt16) data, &actvalue); break; case pwr_cClass_ChanAit: io_ConvertAit( (pwr_sClass_ChanAit *) cop, (pwr_tInt16) data, &actvalue); break; } /* Filter */ sts = io_AiFilter( (void *) op, &actvalue, local->FilterData[i]); *(pwr_tFloat32 *) chanp->vbp = actvalue; local->ScanCount[i] = cop->ScanInterval + 1; } local->ScanCount[i]--; } chanp++; } return 1; }
/*----------------------------------------------------------------------------*\ \*----------------------------------------------------------------------------*/ static pwr_tStatus IoCardRead ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { io_sLocal *local; pwr_tInt16 data = 0; pwr_sClass_Ai_AI32uP *op; int i; pwr_tFloat32 actvalue; io_sChannel *chanp; pwr_sClass_ChanAi *cop; pwr_sClass_Ai *sop; int sts; qbus_io_read rb; local = (io_sLocal *) cp->Local; op = (pwr_sClass_Ai_AI32uP *) cp->op; chanp = &cp->chanlist[0]; for ( i = 0; i < cp->ChanListSize; i++) { if ( !chanp->cop) { chanp++; continue; } cop = (pwr_sClass_ChanAi *) chanp->cop; sop = (pwr_sClass_Ai *) chanp->sop; if ( cop->CalculateNewCoef) AiRangeToCoef( chanp); if ( cop->ConversionOn) { if ( local->ScanCount[i] <= 1) { #if defined(OS_ELN) vaxc$establish(machfailread); #endif rb.Address = local->Address + 2*i; sts = read( local->Qbus_fp, &rb, sizeof(rb)); data = (unsigned short) rb.Data; if ( sts == -1) { #if 0 /* Exceptionhandler was called */ if ( io_fatal_error) { /* Activate emergency break */ errh_Error( "Fatal read error, card '%s', IO is stopped", cp->Name); ctx->Node->EmergBreakTrue = 1; return IO__ERRDEVICE; } #endif /* Increase error count and check error limits */ op->ErrorCount++; if ( op->ErrorCount == op->ErrorSoftLimit) errh_Error( "IO Error soft limit reached on card '%s'", cp->Name); if ( op->ErrorCount >= op->ErrorHardLimit) { errh_Error( "IO Error hard limit reached on card '%s', IO stopped", cp->Name); ctx->Node->EmergBreakTrue = 1; return IO__ERRDEVICE; } chanp++; continue; } /* Convert rawvalue to sigvalue and actualvalue */ sop->RawValue = data; sop->SigValue = data * cop->SigValPolyCoef1 + cop->SigValPolyCoef0; switch ( chanp->ChanClass) { case pwr_cClass_ChanAi: io_ConvertAi( cop, data, &actvalue); break; case pwr_cClass_ChanAit: io_ConvertAit( (pwr_sClass_ChanAit *) cop, data, &actvalue); break; } /* Filter */ if ( sop->FilterType == 1 && sop->FilterAttribute[0] > 0 && sop->FilterAttribute[0] > ctx->ScanTime) { actvalue = *(pwr_tFloat32 *)chanp->vbp + ctx->ScanTime / sop->FilterAttribute[0] * (actvalue - *(pwr_tFloat32 *)chanp->vbp); } *(pwr_tFloat32 *) chanp->vbp = actvalue; local->ScanCount[i] = cop->ScanInterval + 1; } local->ScanCount[i]--; } chanp++; } return 1; }
/*----------------------------------------------------------------------------*\ \*----------------------------------------------------------------------------*/ static pwr_tStatus IoCardRead ( io_tCtx ctx, io_sAgent *ap, io_sRack *rp, io_sCard *cp ) { io_sLocal *local; io_sRackLocal *r_local = (io_sRackLocal *)(rp->Local); pwr_tInt16 data = 0; pwr_sClass_Ssab_BaseACard *op; pwr_sClass_Ssab_RemoteRack *rrp; int i; pwr_tFloat32 actvalue; io_sChannel *chanp; pwr_sClass_ChanAi *cop; pwr_sClass_Ai *sop; int sts; qbus_io_read rb; int bfb_error = 0; pwr_tTime now; local = (io_sLocal *) cp->Local; op = (pwr_sClass_Ssab_BaseACard *) cp->op; chanp = &cp->chanlist[0]; for ( i = 0; i < cp->ChanListSize; i++) { if ( !chanp->cop || !chanp->sop) { chanp++; continue; } cop = (pwr_sClass_ChanAi *) chanp->cop; sop = (pwr_sClass_Ai *) chanp->sop; if ( cop->CalculateNewCoef) AiRangeToCoef( chanp); if ( cop->ConversionOn) { if ( local->ScanCount[i] <= 1) { #if defined(OS_ELN) vaxc$establish(machfailread); #endif if (r_local->Qbus_fp != 0 && r_local->s == 0) { rb.Address = local->Address + 2*i; sts = read( local->Qbus_fp, &rb, sizeof(rb)); data = (unsigned short) rb.Data; } else { /* Ethernet I/O, Get data from current address */ data = bfbeth_get_data(r_local, (pwr_tUInt16) (local->Address + 2*i), &sts); /* Yes, we want to read this address the next time aswell */ bfbeth_set_read_req(r_local, (pwr_tUInt16) (local->Address + 2*i)); if (sts == -1) { /* Error handling for ethernet Qbus-I/O */ rrp = (pwr_sClass_Ssab_RemoteRack *) rp->op; if (bfb_error == 0) { op->ErrorCount++; bfb_error = 1; if ( op->ErrorCount == op->ErrorSoftLimit) errh_Error( "IO Error soft limit reached on card '%s'", cp->Name); if ( op->ErrorCount == op->ErrorHardLimit) errh_Error( "IO Error hard limit reached on card '%s', stall action %d", cp->Name, rrp->StallAction); if ( op->ErrorCount >= op->ErrorHardLimit && rrp->StallAction == pwr_eSsabStallAction_ResetInputs ) { data = 0; sts = 1; } if ( op->ErrorCount >= op->ErrorHardLimit && rrp->StallAction == pwr_eSsabStallAction_EmergencyBreak ) { ctx->Node->EmergBreakTrue = 1; return IO__ERRDEVICE; } } if (sts == -1) { chanp++; continue; } } else { op->ErrorCount = 0; } } if ( sts == -1) /* Error handling for local Qbus-I/O */ { #if 0 /* Exceptionhandler was called */ if ( io_fatal_error) { /* Activate emergency break */ errh_Error( "Fatal read error, card '%s', IO is stopped", cp->Name); ctx->Node->EmergBreakTrue = 1; return IO__ERRDEVICE; } #endif /* Increase error count and check error limits */ time_GetTime( &now); if (op->ErrorCount > op->ErrorSoftLimit) { /* Ignore if some time has expired */ if (now.tv_sec - local->ErrTime.tv_sec < 600) op->ErrorCount++; } else op->ErrorCount++; local->ErrTime = now; if ( op->ErrorCount == op->ErrorSoftLimit) errh_Error( "IO Error soft limit reached on card '%s'", cp->Name); if ( op->ErrorCount >= op->ErrorHardLimit) { errh_Error( "IO Error hard limit reached on card '%s', IO stopped", cp->Name); ctx->Node->EmergBreakTrue = 1; return IO__ERRDEVICE; } chanp++; continue; } /* Convert rawvalue to sigvalue and actualvalue */ sop->RawValue = data; sop->SigValue = data * cop->SigValPolyCoef1 + cop->SigValPolyCoef0; switch ( chanp->ChanClass) { case pwr_cClass_ChanAi: io_ConvertAi( cop, data, &actvalue); break; case pwr_cClass_ChanAit: io_ConvertAit( (pwr_sClass_ChanAit *) cop, data, &actvalue); break; } /* Filter */ if ( sop->FilterType == 1 && sop->FilterAttribute[0] > 0 && sop->FilterAttribute[0] > ctx->ScanTime) { actvalue = *(pwr_tFloat32 *)chanp->vbp + ctx->ScanTime / sop->FilterAttribute[0] * (actvalue - *(pwr_tFloat32 *)chanp->vbp); } *(pwr_tFloat32 *) chanp->vbp = actvalue; local->ScanCount[i] = cop->ScanInterval + 1; } local->ScanCount[i]--; } chanp++; } return 1; }