static long read_longin(longinRecord *plongin) { F3RP61_LI_DPVT *dpvt = (F3RP61_LI_DPVT *) plongin->dpvt; M3IO_ACCESS_COM *pacom = &dpvt->u.acom; M3IO_ACCESS_REG *pdrly = &dpvt->u.drly; char device = dpvt->device; char option = dpvt->option; int uword = dpvt->uword; int lng = dpvt->lng; /* &L flag */ int BCD = dpvt->BCD; /* BCD flag */ int command = M3IO_READ_REG; unsigned short wdata[2]; unsigned long ldata; unsigned long dataFromBCD = 0; /* For storing returned value in binary-coded-decimal format */ unsigned short i, data_temp; /* Used when calculating BCD value */ void *p = (void *) pdrly; /* Set ioctl 'command' for this device*/ switch (device) { case 'X': command = M3IO_READ_INRELAY; break; case 'Y': command = M3IO_READ_OUTRELAY; break; case 'r': command = M3IO_READ_COM; pacom->pdata = &wdata[0]; p = (void *) pacom; break; case 'W': case 'R': break; default: // For 'A' switch (option) { case 'L': command = M3IO_READ_REG_L; pdrly->u.pldata = &ldata; break; default: pdrly->u.pwdata = &wdata[0]; } } /* USE API FUNCTIONS TO READ FROM DEVICE*/ /* For device 'r' and Registers and I/Os of specific modules (X,Y,A,..)*/ if (device != 'W' && device != 'R') { if (ioctl(f3rp61_fd, command, p) < 0) { errlogPrintf("devLiF3RP61: ioctl failed [%d] for %s\n", errno, plongin->name); return (-1); } } /* For Link Register W*/ else if (device == 'W') { if (readM3LinkRegister(pacom->start, pacom->count, &wdata[0]) < 0) { errlogPrintf("devLiF3RP61: readM3LinkRegister failed [%d] for %s\n", errno, plongin->name); return (-1); } } /* For Shared Register R*/ else { if (readM3ComRegister(pacom->start, pacom->count, &wdata[0]) < 0) { errlogPrintf("devLiF3RP61: readM3ComRegister failed [%d] for %s\n", errno, plongin->name); return (-1); } } plongin->udf=FALSE; /* Decode BCD to decimal*/ if(BCD) { i = 0; data_temp = wdata[0]; while(i < 4) { /* max is 9999 */ if (((unsigned short) (0x0000000f & data_temp)) > 9) { dataFromBCD += 9 * pow(10, i); recGblSetSevr(plongin,HIGH_ALARM,INVALID_ALARM); } else { dataFromBCD += ((unsigned short) (0x0000000f & data_temp)) * pow(10, i); } data_temp = data_temp >> 4; i++; } } /* Write to VAL field*/ switch (device) { case 'X': if (uword) { plongin->val = (long) pdrly->u.inrly[0].data; } else { plongin->val = (long) ((signed short) pdrly->u.inrly[0].data); } break; case 'Y': if (uword) { plongin->val = (long) pdrly->u.outrly[0].data; } else { plongin->val = (long) ((signed short) pdrly->u.outrly[0].data); } break; case 'r': case 'W': case 'R': if (BCD) { plongin->val = dataFromBCD; } else if (uword) { plongin->val = (long) wdata[0]; } else if (lng) { plongin->val = (long) ((wdata[1] << 16) & 0xffff0000 | wdata[0] & 0x0000ffff); } else { plongin->val = (long) ((signed short) wdata[0]); } break; default: /* For device 'A'*/ if (lng) { plongin->val = (long) ((signed long) ldata); } else if (BCD) { plongin->val = dataFromBCD; } else if (uword) { plongin->val = (long) wdata[0]; } else { plongin->val = (long) ((signed short) wdata[0]); } } return(0); }
static long read_mbbiDirect(mbbiDirectRecord *pmbbiDirect) { F3RP61_MBBIDIRECT_DPVT *dpvt = (F3RP61_MBBIDIRECT_DPVT *) pmbbiDirect->dpvt; M3IO_ACCESS_COM *pacom = &dpvt->u.acom; M3IO_ACCESS_REG *pdrly = &dpvt->u.drly; char device = dpvt->device; int command; unsigned short wdata; void *p = (void *) pdrly; switch (device) { case 'X': command = M3IO_READ_INRELAY; break; case 'Y': command = M3IO_READ_OUTRELAY; break; case 'r': command = M3IO_READ_COM; pacom->pdata = &wdata; p = (void *) pacom; break; case 'W': case 'R': case 'L': case 'E': break; case 'M': /* need to use old style */ command = M3IO_READ_MODE; break; default: command = M3IO_READ_REG; pdrly->u.pwdata = &wdata; } if (device != 'W' && device != 'L' && device != 'R' && device != 'E') { if (ioctl(f3rp61_fd, command, p) < 0) { errlogPrintf("devMbbiDirectF3RP61: ioctl failed [%d] for %s\n", errno, pmbbiDirect->name); return (-1); } } else if (device == 'W') { if (readM3LinkRegister(pacom->start, 1, &wdata) < 0) { errlogPrintf("devMbbiDirectF3RP61: readM3LinkRegister failed [%d] for %s\n", errno, pmbbiDirect->name); return (-1); } } else if (device == 'R') { if (readM3ComRegister(pacom->start, 1, &wdata) < 0) { errlogPrintf("devMbbiDirectF3RP61: readM3ComRegister failed [%d] for %s\n", errno, pmbbiDirect->name); return (-1); } } else if (device == 'L') { if (readM3LinkRelay(pacom->start, 1, &wdata) < 0) { errlogPrintf("devMbbiDirectF3RP61: readM3LinkRelay failed [%d] for %s\n", errno, pmbbiDirect->name); return (-1); } } else { if (readM3ComRelay(pacom->start, 1, &wdata) < 0) { errlogPrintf("devMbbiDirectF3RP61: readM3ComRelay failed [%d] for %s\n", errno, pmbbiDirect->name); return (-1); } } pmbbiDirect->udf=FALSE; switch (device) { case 'X': pmbbiDirect->rval = (long) pdrly->u.inrly[0].data; break; case 'Y': pmbbiDirect->rval = (long) pdrly->u.outrly[0].data; break; case 'M': /* need to use old style */ pmbbiDirect->rval = (long) pdrly->u.wdata[0]; break; case 'r': case 'W': case 'R': case 'L': case 'E': default: pmbbiDirect->rval = (long) wdata; } /* convert */ return(0); }
static long read_longin(longinRecord *plongin) { F3RP61_LI_DPVT *dpvt = (F3RP61_LI_DPVT *) plongin->dpvt; M3IO_ACCESS_COM *pacom = &dpvt->u.acom; M3IO_ACCESS_REG *pdrly = &dpvt->u.drly; char device = dpvt->device; char option = dpvt->option; int uword = dpvt->uword; int command = M3IO_READ_REG; unsigned short wdata[2]; unsigned long ldata; void *p = (void *) pdrly; switch (device) { case 'X': command = M3IO_READ_INRELAY; break; case 'Y': command = M3IO_READ_OUTRELAY; break; case 'r': command = M3IO_READ_COM; pacom->pdata = &wdata[0]; p = (void *) pacom; break; case 'W': case 'R': break; default: switch (option) { case 'L': command = M3IO_READ_REG_L; pdrly->u.pldata = &ldata; break; default: pdrly->u.pwdata = &wdata[0]; } } if (device != 'W' && device != 'R') { if (ioctl(f3rp61_fd, command, p) < 0) { errlogPrintf("devLiF3RP61: ioctl failed [%d] for %s\n", errno, plongin->name); return (-1); } } else if (device == 'W') { if (readM3LinkRegister(pacom->start, pacom->count, &wdata[0]) < 0) { errlogPrintf("devLiF3RP61: readM3LinkRegister failed [%d] for %s\n", errno, plongin->name); return (-1); } } else { if (readM3ComRegister(pacom->start, pacom->count, &wdata[0]) < 0) { errlogPrintf("devLiF3RP61: readM3ComRegister failed [%d] for %s\n", errno, plongin->name); return (-1); } } plongin->udf=FALSE; switch (device) { case 'X': if (uword) { plongin->val = (long) pdrly->u.inrly[0].data; } else { plongin->val = (long) ((signed short) pdrly->u.inrly[0].data); } break; case 'Y': if (uword) { plongin->val = (long) pdrly->u.outrly[0].data; } else { plongin->val = (long) ((signed short) pdrly->u.outrly[0].data); } break; case 'r': case 'W': case 'R': if (uword) { plongin->val = (long) wdata[0]; } else { switch (option) { case 'L': plongin->val = (long) ((wdata[1] << 16) & 0xffff0000 | wdata[0] & 0x0000ffff); break; default: plongin->val = (long) ((signed short) wdata[0]); } } break; default: switch (option) { case 'L': plongin->val = (long) ((signed long) ldata); break; default: if (uword) { plongin->val = (long) wdata[0]; } else { plongin->val = (long) ((signed short) wdata[0]); } } } return(0); }