Changeset 264 for hvcontrol/src/HV.cc
- Timestamp:
- 07/27/10 07:27:04 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
hvcontrol/src/HV.cc
r230 r264 96 96 97 97 unsigned char rbuf; 98 int ret;98 int N, Ret = 0; 99 99 fd_set SelectDescriptor; 100 100 struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)}; 101 102 // === Lock file descriptor === 103 if (lockf(fDescriptor, F_LOCK, 0) == -1) { 104 m->Message(m->ERROR, "Failed to lock file descriptor (%s)", strerror(errno)); 105 return 0; 106 } 107 101 108 // === Write data === 102 if (( ret=write(fDescriptor, wbuf, Bytes)) < Bytes) {103 if ( ret== -1) m->Message(m->ERROR, "Could not write data to HV board (%s)", strerror(errno));104 else m->Message(m->ERROR, "Could write only %d of %d bytes to HV board", ret, Bytes);109 if ((N = write(fDescriptor, wbuf, Bytes)) < Bytes) { 110 if (N == -1) m->Message(m->ERROR, "Could not write data to HV board (%s)", strerror(errno)); 111 else m->Message(m->ERROR, "Could write only %d of %d bytes to HV board", N, Bytes); 105 112 ErrorCount++; 106 return 0;113 goto ExitCommunicate; 107 114 } 108 115 109 116 // === Try to read until time-out === 110 117 FD_ZERO(&SelectDescriptor); FD_SET(fDescriptor, &SelectDescriptor); 111 struct timeval WaitTime = {(long) fTimeOut, (long) ((fTimeOut-(long) fTimeOut)*1e6)};112 118 if (select(fDescriptor+1, &SelectDescriptor, NULL, NULL, &WaitTime)==-1) { 113 119 m->Message(m->ERROR, "Error with select() (%s)", strerror(errno)); 114 return 0;120 goto ExitCommunicate; 115 121 } 116 122 // Time-out expired? 117 if (!FD_ISSET(fDescriptor, &SelectDescriptor)) return -1; 123 if (!FD_ISSET(fDescriptor, &SelectDescriptor)) { 124 Ret = -1; 125 goto ExitCommunicate; 126 } 118 127 119 128 // Read error? 120 if ( (ret = read(fDescriptor, &rbuf, 1)) == -1) {129 if (read(fDescriptor, &rbuf, 1) == -1) { 121 130 m->Message(m->ERROR, "Read error (%s)", strerror(errno)); 122 131 ErrorCount++; 123 return 0;132 goto ExitCommunicate; 124 133 } 125 134 … … 132 141 for (int i=0; i<NUM_CHAINS; i++) Overcurrent[i] = (rbuf & (0X08 << i)); 133 142 ResetButton = (bool) (rbuf & 0X80); 134 135 return 1; 136 } 137 138 139 /* Reset HV board - uses TRead() and has same return values */ 143 Ret = 1; 144 145 // === UnLock file descriptor === 146 ExitCommunicate: 147 if (lockf(fDescriptor, F_LOCK, 0) == -1) { 148 m->Message(m->ERROR, "Failed to lock file descriptor (%s)", strerror(errno)); 149 return 0; 150 } 151 152 return Ret; 153 } 154 155 156 // Reset HV board 140 157 int HVBoard::Reset() { 141 158 … … 151 168 152 169 153 / * Read status register - uses TRead() and has same return values */170 // Read status register 154 171 int HVBoard::GetStatus() { 155 172 … … 160 177 161 178 162 / * Set high voltage - uses TRead() and has same return values */179 // Set high voltage 163 180 int HVBoard::SetHV(int chain, unsigned int channel, int hv) { 164 181
Note:
See TracChangeset
for help on using the changeset viewer.