|
|
1.1 ! root 1: /* ! 2: * This software is provided solely for use with ! 3: * the National Instruments GPIB11-series interfaces. ! 4: * ! 5: * Copyright 1980, 1983 National Instruments ! 6: * ! 7: * Jeffrey Kodosky ! 8: * REV D: 10/09/83 ! 9: */ ! 10: ! 11: ! 12: #define DCL 024 ! 13: #define GET 010 ! 14: #define GTL 001 ! 15: #define LLO 021 ! 16: #define PPC 005 ! 17: #define PPD 0160 ! 18: #define PPE0 0140 ! 19: #define PPU 025 ! 20: #define SDC 004 ! 21: #define SPD 031 ! 22: #define SPE 030 ! 23: #define TCT 011 ! 24: #define UNL 077 ! 25: #define UNT 0137 ! 26: ! 27: #define OK 1 ! 28: #define ENOTSAC (-4) ! 29: #define ENOFUN (-20) ! 30: #define ENODEV (-21) ! 31: #define ENOLAD (-22) ! 32: #define ENOTAD (-23) ! 33: ! 34: #define CO 0 ! 35: #define WT 1 ! 36: #define RD 2 ! 37: #define TR 3 ! 38: #define CL 4 ! 39: #define RM 5 ! 40: #define LO 6 ! 41: #define PP 7 ! 42: #define PC 8 ! 43: #define SS 9 ! 44: #define MN 10 ! 45: #define RC 11 ! 46: #define SP 12 ! 47: #define TS 13 ! 48: #define FI 14 ! 49: ! 50: ! 51: #define Try(f) if((x=(f))<0) return x ! 52: ! 53: static int open= 0; ! 54: ! 55: struct device { ! 56: char tad, lad, sad; /* GPIB addresses */ ! 57: char rmd, eod, wmd; /* read write modes */ ! 58: }; ! 59: ! 60: struct device devtbl[]= { ! 61: { 0125, 065, 0, 0, 0, 0 }, /* GPIB interface */ ! 62: { 0103, 043, 0143, 0, 0, 0 }, /* QCR camera */ ! 63: { 0102, 042, 0142, 0, 0, 0 }, /* QCR camera data */ ! 64: { 0 }, /* empty slot */ ! 65: { 0 }, /* empty slot */ ! 66: { 0 } /* empty slot */ ! 67: }; ! 68: ! 69: #define NDEV ((sizeof devtbl)/(sizeof devtbl[0]) -1) ! 70: ! 71: static char cbf[7+2*NDEV]; ! 72: ! 73: ! 74: ibup(f,dev,a2,a3,a4,a5,a6,a7){ ! 75: register int x, d; ! 76: register char *s; ! 77: char *ltns(); ! 78: ! 79: if(!open) Try(init()); ! 80: d= dev; ! 81: s= &cbf[0]; ! 82: switch(f){ ! 83: default: return ENOFUN; ! 84: case 0: if(d<=0 || d>NDEV) return ENODEV; /* write */ ! 85: *s++= UNL; *s++= UNT; ! 86: *s++= devtbl[0].tad; ! 87: if(*s= devtbl[0].sad) s++; ! 88: if((s= ltns(s,d))==0) return ENOLAD; ! 89: Try(cmd(s)); ! 90: Try(d=gpib(WT,a2,a3,devtbl[d].wmd)); ! 91: Try(gtsun()); ! 92: return d; ! 93: case 1: if(d<=0 || d>NDEV) return ENODEV; /* read */ ! 94: *s++= UNL; *s++= UNT; ! 95: if((*s++= devtbl[d].tad)==0) return ENOTAD; ! 96: if(*s= devtbl[d].sad) s++; ! 97: *s++= devtbl[0].lad; ! 98: if(*s= devtbl[0].sad) s++; ! 99: Try(cmd(s)); ! 100: Try(d=gpib(RD,a2,a3,devtbl[d].rmd,devtbl[d].eod)); ! 101: Try(gtsun()); ! 102: return d; ! 103: case 2: if(d<0) return gpib(CL); /* clear */ ! 104: else if(d>NDEV) return ENODEV; ! 105: if(d){ *s++= UNL; *s++= UNT; ! 106: if((s= ltns(s,d))==0) return ENOLAD; ! 107: *s++= SDC; } ! 108: else *s++= DCL; ! 109: return cmd(s); ! 110: case 3: if(d<0 || d>NDEV) return ENODEV; /* trigger */ ! 111: *s++= UNL; *s++= UNT; ! 112: if((s= ltns(s,d))==0) return ENOLAD; ! 113: *s++= GET; ! 114: return cmd(s); ! 115: case 4: Try(gpib(RM)); /* remote */ ! 116: if(d<0){ *s++= LLO; d= 0; } ! 117: else if(d>NDEV) return ENODEV; ! 118: if((s= ltns(s,d))==0) return ENOLAD; ! 119: return cmd(s); ! 120: case 5: if(d<0) return gpib(LO); /* local */ ! 121: if(d>NDEV) return ENODEV; ! 122: *s++= UNL; *s++= UNT; ! 123: if((s= ltns(s,d))==0) return ENOLAD; ! 124: *s++= GTL; ! 125: return cmd(s); ! 126: case 6: if(d<0) return gpib(TS); /* poll */ ! 127: if(d>NDEV) return ENODEV; ! 128: if(d==0) return gpib(PP); ! 129: *s++= UNL; *s++= UNT; ! 130: *s++= SPE; ! 131: if((*s++= devtbl[d].tad)==0) return ENOTAD; ! 132: if(*s= devtbl[d].sad) s++; ! 133: *s++= devtbl[0].lad; ! 134: if(*s= devtbl[0].sad) s++; ! 135: Try(cmd(s)); ! 136: Try(gpib(RD, cbf, 1,0,0)); ! 137: d= cbf[0]&0377; ! 138: cbf[0]= SPD; ! 139: Try(cmd(&cbf[1])); ! 140: return d; ! 141: case 7: if(d<0 || d>NDEV) return ENODEV; /* configure */ ! 142: if(d){ *s++= UNL; *s++= UNT; ! 143: if((s= ltns(s,d))==0) return ENOLAD; ! 144: *s++= PPC; ! 145: if(a2>=0) *s++= PPE0 | (a3-1)&7 | (a2? 010:0); ! 146: else *s++= PPD; ! 147: } ! 148: else *s++= PPU; ! 149: return cmd(s); ! 150: case 8: if(d<=0 || d>NDEV) return ENODEV; /* passctrl */ ! 151: *s++= UNL; *s++= UNT; ! 152: if((*s++= devtbl[d].tad)==0) return ENOTAD; ! 153: if(*s= devtbl[d].sad) s++; ! 154: *s++= TCT; ! 155: Try(cmd(s)); ! 156: return gpib(PC); ! 157: case 9: if(d<0 || d>NDEV) return ENODEV; /* define */ ! 158: if(a2 && (a2<0100 || a2>=0137)) return ENOTAD; ! 159: if(a3 && (a3<040 || a3>=077)) return ENOLAD; ! 160: if(a4 && (a4<0140 || a4>=0177)) return ENOTAD; ! 161: devtbl[d].tad= a2; ! 162: devtbl[d].lad= a3; ! 163: devtbl[d].sad= a4; ! 164: devtbl[d].rmd= a5; ! 165: devtbl[d].eod= a6; ! 166: devtbl[d].wmd= a7; ! 167: return OK; ! 168: case 10: /* finish */ ! 169: open= 0; ! 170: return gpib(FI); ! 171: } } ! 172: ! 173: static char *ltns(s,d) char *s;{ ! 174: register int n; ! 175: if(d){ if((*s++= devtbl[d].lad)==0) ! 176: return 0; ! 177: if(*s= devtbl[d].sad) s++; ! 178: } ! 179: else for(d++, n=NDEV; n-->0; d++) ! 180: if(*s= devtbl[d].lad){ ! 181: s++; ! 182: if(*s= devtbl[d].sad) s++; ! 183: } ! 184: return s; } ! 185: ! 186: static cmd(s) char *s;{ ! 187: return gpib(CO, &cbf[0], s- &cbf[0]); } ! 188: ! 189: static init(){ ! 190: register int x; ! 191: if((x=gpib(CL))>=0) ! 192: x= gpib(RM); ! 193: if(x==ENOTSAC) x= OK; ! 194: open++; ! 195: return x; } ! 196: ! 197: static gtsun(){ ! 198: register int x; ! 199: register char *s; ! 200: ! 201: s= &cbf[0]; ! 202: *s++= UNL; *s++= UNT; ! 203: Try(cmd(s)); ! 204: return gpib(TR); }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.