Read single ADC Channel
976823
def get(self, channel):
        """"""
        checked_channel = self._check_channel_no(channel)
        self.i2c.write_raw8(checked_channel  | self._dac_enabled)
        reading = self.i2c.read_raw8() 
        reading = self.i2c.read_raw8() 
        return reading / 255.0
613463
def readiter(d):
    

    da = ms.getdata([d['datacol'],'axis_info','u','v','w','flag','data_desc_id'], ifraxis=True)
    good = n.where((da['data_desc_id']) == d['spwlist'][0])[0]   # take first spw                                                
    time0 = da['axis_info']['time_axis']['MJDseconds'][good]
    data0 = n.transpose(da[d['datacol']], axes=[3,2,1,0])[good]
    flag0 = n.transpose(da['flag'], axes=[3,2,1,0])[good]
    u0 = da['u'].transpose()[good] * d['freq_orig'][0] * (1e9/3e8)    # uvw are in m, so divide by wavelength of first chan to set in lambda
    v0 = da['v'].transpose()[good] * d['freq_orig'][0] * (1e9/3e8)
    w0 = da['w'].transpose()[good] * d['freq_orig'][0] * (1e9/3e8)

    if len(d['spwlist']) > 1:
        for spw in d['spwlist'][1:]:
            good = n.where((da['data_desc_id']) == spw)[0]
            data1 = n.transpose(da[d['datacol']], axes=[3,2,1,0])[good]
            data0 = n.concatenate( (data0, data1), axis=2 )
            flag0 = n.concatenate( (flag0, n.transpose(da['flag'], axes=[3,2,1,0])[good]), axis=2 )

    del da
    data0 = data0[:,:,d['chans'],:] * n.invert(flag0[:,:,d['chans'],:])   # flag==1 means bad data (for vla)                     
    iterstatus = ms.iternext() 

    return data0.astype('complex64'), u0.astype('float32'), v0.astype('float32'), w0.astype('float32'), time0.astype('float32')
1082882
def single_read(self, register):
        '''
         
        '''
        
        comm_reg = (0b00010 << 3) + register

        if register == self.AD7730_STATUS_REG:
            bytes_num = 1
        elif register == self.AD7730_DATA_REG:
            bytes_num = 3
        elif register == self.AD7730_MODE_REG:
            bytes_num = 2
        elif register == self.AD7730_FILTER_REG:
            bytes_num = 3
        elif register == self.AD7730_DAC_REG:
            bytes_num = 1
        elif register == self.AD7730_OFFSET_REG:
            bytes_num = 3
        elif register == self.AD7730_GAIN_REG:
            bytes_num = 3
        elif register == self.AD7730_TEST_REG:
            bytes_num = 3

        command = [comm_reg] + ([0x00] * bytes_num)
        spi.SPI_write(self.CS, command)
        data = spi.SPI_read(bytes_num + 1)        
        return data[1:]
1306416
def ReadUntil(self, *expected_cmds):
        """"""
        cmd, remote_id, local_id, data = AdbMessage.Read(
            self.usb, expected_cmds, self.timeout_ms)
        if local_id != 0 and self.local_id != local_id:
            raise InterleavedDataError("We don't support multiple streams...")
        if remote_id != 0 and self.remote_id != remote_id:
            raise InvalidResponseError(
                'Incorrect remote id, expected %s got %s' % (
                    self.remote_id, remote_id))
        # Ack write packets.
        if cmd == b'WRTE':
            self.Okay()
        return cmd, data
408817
def _read_channel(stream, num, name, ctype, epoch, start, end,
                  scaled=True, series_class=TimeSeries):
    
    data = _get_frdata(stream, num, name, ctype=ctype)
    return read_frdata(data, epoch, start, end,
                       scaled=scaled, series_class=series_class)
161344
InputStream readChannel(int channel)
        throws IOException
    {
        while (!isClosed) {
            if (inputReady[channel]) {
                inputReady[channel] = false;
                return is;
            }

            boolean canRead = false;
            synchronized (READ_LOCK) {
                if (!isReadLocked) {
                    isReadLocked = true;
                    canRead = true;
                }
                else {
                    try {
                        READ_LOCK.wait(5000);
                    } catch (Exception e) {
                    }
                }
            }

            if (canRead) {
                try {
                    readData();
                } catch (IOException e) {
                    close();
                }
            }
        }

        return null;
    }
1313553
def _read_mac_addr(self):
        """"""
        _byte = self._read_fileng(6)
        _addr = '-'.join(textwrap.wrap(_byte.hex(), 2))
        return _addr
1331317
def set_current(self, channel, value, unit='A'):
        '''
        '''
        dac_offset = self._ch_cal[channel]['DAC']['offset']
        dac_gain = self._ch_cal[channel]['DAC']['gain']
        if unit == 'raw':
            value = value
        elif unit == 'A':
            value = int((-value * 1000000 - dac_offset) / dac_gain)  # fix sign of output
        elif unit == 'mA':
            value = int((-value * 1000 - dac_offset) / dac_gain)  # fix sign of output
        elif unit == 'uA':
            value = int((-value - dac_offset) / dac_gain)  # fix sign of output
        else:
            raise TypeError("Invalid unit type.")

        self._set_dac_value(channel=channel, value=value)
207372
def read_eeprom_calibration(self, temperature=False):  # use default values for temperature, EEPROM values are usually not calibrated and random
        '''
        '''
        header = self.get_format()
        if header == self.HEADER_V2:
            data = self._read_eeprom(self.CAL_DATA_ADDR, size=calcsize(self.CAL_DATA_V2_FORMAT))
            for idx, channel in enumerate(self._ch_cal.iterkeys()):
                ch_data = data[idx * calcsize(self.CAL_DATA_CH_V2_FORMAT):(idx + 1) * calcsize(self.CAL_DATA_CH_V2_FORMAT)]
                values = unpack_from(self.CAL_DATA_CH_V2_FORMAT, ch_data)
                self._ch_cal[channel]['name'] = "".join([c for c in values[0] if (c in string.printable)])  # values[0].strip()
                self._ch_cal[channel]['default'] = values[1]
                self._ch_cal[channel]['ADCI']['gain'] = values[2]
                self._ch_cal[channel]['ADCI']['offset'] = values[3]
                self._ch_cal[channel]['ADCI']['iq_gain'] = values[4]
                self._ch_cal[channel]['ADCI']['iq_offset'] = values[5]
                self._ch_cal[channel]['ADCV']['gain'] = values[6]
                self._ch_cal[channel]['ADCV']['offset'] = values[7]
                self._ch_cal[channel]['DACV']['gain'] = values[8]
                self._ch_cal[channel]['DACV']['offset'] = values[9]
                if temperature:
                    self._ch_cal[channel]['NTC']['B_NTC'] = values[10]
                    self._ch_cal[channel]['NTC']['R1'] = values[11]
                    self._ch_cal[channel]['NTC']['R2'] = values[12]
                    self._ch_cal[channel]['NTC']['R4'] = values[13]
                    self._ch_cal[channel]['NTC']['R_NTC_25'] = values[14]
                    self._ch_cal[channel]['NTC']['VREF'] = values[15]
        else:
            raise ValueError('EEPROM data format not supported (header: %s)' % header)
588021
def segwit_addr_decode(addr, hrp=bech32_prefix):
    
    hrpgot, data = bech32_decode(addr)
    if hrpgot != hrp:
        return (None, None)
    decoded = convertbits(data[1:], 5, 8, False)
    if decoded is None or len(decoded) < 2 or len(decoded) > 40:
        return (None, None)
    if data[0] > 16:
        return (None, None)
    if data[0] == 0 and len(decoded) != 20 and len(decoded) != 32:
        return (None, None)
    return (data[0], ''.join([chr(x) for x in decoded]))
1190511
def read_eeprom_calibration(self):  # use default values for temperature, EEPROM values are usually not calibrated and random
        '''
        '''
        header = self.get_format()
        if header == self.HEADER_GPAC:
            data = self._read_eeprom(self.CAL_DATA_ADDR, size=calcsize(self.CAL_DATA_GPAC_FORMAT))
            for idx, channel in enumerate(self._ch_cal.iterkeys()):
                ch_data = data[idx * calcsize(self.CAL_DATA_CH_GPAC_FORMAT):(idx + 1) * calcsize(self.CAL_DATA_CH_GPAC_FORMAT)]
                values = unpack_from(self.CAL_DATA_CH_GPAC_FORMAT, ch_data)
                self._ch_cal[channel]['name'] = "".join([c for c in values[0] if (c in string.printable)])  # values[0].strip()
                self._ch_cal[channel]['default'] = values[1]
                self._ch_cal[channel]['min'] = values[2]
                self._ch_cal[channel]['max'] = values[3]
                self._ch_cal[channel]['ADCI']['gain'] = -values[4]  # fix gain sign
                self._ch_cal[channel]['ADCI']['offset'] = values[5]
                self._ch_cal[channel]['ADCV']['gain'] = values[6]
                self._ch_cal[channel]['ADCV']['offset'] = values[7]
                self._ch_cal[channel]['DAC']['gain'] = values[8]
                self._ch_cal[channel]['DAC']['offset'] = values[9]
                self._ch_cal[channel]['limit'] = values[10]
        else:
            raise ValueError('EEPROM data format not supported (header: %s)' % header)
444788
def adc(self, other : 'BitVector', carry : Bit) -> tp.Tuple['BitVector', Bit]:
        
        T = type(self)
        other = _coerce(T, other)
        carry = _coerce(T.unsized_t[1], carry)

        a = self.zext(1)
        b = other.zext(1)
        c = carry.zext(T.size)

        res = a + b + c
        return res[0:-1], res[-1]
464161
def _read_channel(channel, stream, start, duration):
    
    channel_type = lalframe.FrStreamGetTimeSeriesType(channel, stream)
    read_func = _fr_type_map[channel_type][0]
    d_type = _fr_type_map[channel_type][1]
    data = read_func(stream, channel, start, duration, 0)
    return TimeSeries(data.data.data, delta_t=data.deltaT, epoch=start,
                      dtype=d_type)
536926
def _perform_read(self, addr, size):
        """"""
        return self._machine_controller.read(addr, size, self._x, self._y, 0)
855255
def decode_imod(packet, channel=1):
    """"""
    val = str(packet.get(QSDATA, ''))
    if len(val) == 8 and val.startswith('4e'):
        try:
            _map = ((5, 1), (5, 2), (5, 4), (4, 1), (5, 1), (5, 2))[
                channel - 1]
            return (int(val[_map[0]], 16) & _map[1]) == 0
        except IndexError:
            return None
    return None
528632
public int read(ReadableByteChannel channel) throws IOException {
        // Header: segId (4), lastForcedTime (8), size (4)
        ByteBuffer header = ByteBuffer.allocate(HEADER_LENGTH);
        read(channel, header, HEADER_LENGTH, "Invalid Header");
        
        int segmentId = header.getInt(0);
        long lastForcedTime = header.getLong(4);
        int size = header.getInt(12);
        
        // Data
        int dataLength = size << 3;
        ByteBuffer data = ByteBuffer.allocate(dataLength);
        read(channel, data, dataLength, "Invalid Data");
        
        // Footer - MD5Digest (16)
        ByteBuffer md5 = ByteBuffer.allocate(MD5_LENGTH);
        read(channel, md5, MD5_LENGTH, "Invalid MD5");
        
        try {
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.reset();
            m.update(header.array());
            m.update(data.array());
            byte[] digest = ensure128BitMD5(m.digest());
            
            if(Arrays.equals(md5.array(), digest)) {
                setSegmentId(segmentId);
                setSegmentLastForcedTime(lastForcedTime);
                data.flip();
                put(data);
            }
        } catch (NoSuchAlgorithmException e) {
            throw new IOException(e);
        }
        
        return (dataLength + HEADER_FOOTER_LENGTH);
    }
898798
def _pulse_data(self, value):
        """"""
        if self._i2c_expander == 'PCF8574':
            self.bus.write_byte(self._address, ((value & ~PCF8574_E) | self._backlight))
            c.usleep(1)
            self.bus.write_byte(self._address, value | PCF8574_E | self._backlight)
            c.usleep(1)
            self.bus.write_byte(self._address, ((value & ~PCF8574_E) | self._backlight))
            c.usleep(100)
        elif self._i2c_expander in ['MCP23008', 'MCP23017']:
            self._mcp_data &= ~MCP230XX_DATAMASK
            self._mcp_data |= value << MCP230XX_DATASHIFT
            self._mcp_data &= ~MCP230XX_E
            self.bus.write_byte_data(self._address, self._mcp_gpio, self._mcp_data)
            c.usleep(1)
            self._mcp_data |= MCP230XX_E
            self.bus.write_byte_data(self._address, self._mcp_gpio, self._mcp_data)
            c.usleep(1)
            self._mcp_data &= ~MCP230XX_E
            self.bus.write_byte_data(self._address, self._mcp_gpio, self._mcp_data)
            c.usleep(100)