Build request PDU to write single register.

        :return: Byte array of 5 bytes with PDU.
764307
def request_pdu(self):
        
        if None in [self.address, self.value]:
            # TODO Raise proper exception.
            raise Exception

        return struct.pack('>BH' + conf.TYPE_CHAR, self.function_code,
                           self.address, self.value)
134303
def write_core_registers_raw(self, reg_list, data_list):
        
        assert len(reg_list) == len(data_list)
        # convert to index only
        reg_list = [register_name_to_index(reg) for reg in reg_list]

        # Sanity check register values
        for reg in reg_list:
            if reg not in CORE_REGISTER.values():
                raise ValueError("unknown reg: %d" % reg)
            elif is_fpu_register(reg) and (not self.has_fpu):
                raise ValueError("attempt to write FPU register without FPU")

        # Read special register if it is present in the list and
        # convert doubles to single float register writes.
        cfbpValue = None
        xpsrValue = None
        reg_data_list = []
        for reg, data in zip(reg_list, data_list):
            if is_double_float_register(reg):
                # Replace double with two single float register writes. For instance,
                # a write of D2 gets converted to writes to S4 and S5.
                singleLow = data & 0xffffffff
                singleHigh = (data >> 32) & 0xffffffff
                reg_data_list += [(-reg, singleLow), (-reg + 1, singleHigh)]
            elif is_cfbp_subregister(reg) and cfbpValue is None:
                cfbpValue = self.read_core_register_raw(CORE_REGISTER['cfbp'])
            elif is_psr_subregister(reg) and xpsrValue is None:
                xpsrValue = self.read_core_register_raw(CORE_REGISTER['xpsr'])
            else:
                # Other register, just copy directly.
                reg_data_list.append((reg, data))
        
        # Write out registers
        dhcsr_cb_list = []
        for reg, data in reg_data_list:
            if is_cfbp_subregister(reg):
                # Mask in the new special register value so we don't modify the other register
                # values that share the same DCRSR number.
                shift = (-reg - 1) * 8
                mask = 0xffffffff ^ (0xff << shift)
                data = (cfbpValue & mask) | ((data & 0xff) << shift)
                cfbpValue = data # update special register for other writes that might be in the list
                reg = CORE_REGISTER['cfbp']
            elif is_psr_subregister(reg):
                mask = sysm_to_psr_mask(reg)
                data = (xpsrValue & (0xffffffff ^ mask)) | (data & mask)
                xpsrValue = data
                reg = CORE_REGISTER['xpsr']

            # write DCRDR
            self.write_memory(CortexM.DCRDR, data)

            # write id in DCRSR and flag to start write transfer
            self.write_memory(CortexM.DCRSR, reg | CortexM.DCRSR_REGWnR)

            # Technically, we need to poll S_REGRDY in DHCSR here to ensure the
            # register write has completed.
            # Read it and assert that S_REGRDY is set
            dhcsr_cb = self.read_memory(CortexM.DHCSR, now=False)
            dhcsr_cb_list.append(dhcsr_cb)

        # Make sure S_REGRDY was set for all register
        # writes
        for dhcsr_cb in dhcsr_cb_list:
            dhcsr_val = dhcsr_cb()
            assert dhcsr_val & CortexM.S_REGRDY
1172185
def to_bytes(self):
        '''
        
        '''
        # Verify that properties make sense
        self.sanitize()

        # Start with the type
        bitstream = BitArray('uint:4=%d' % self.message_type)

        # Add padding
        bitstream += self._reserved1

        # Add the record count
        bitstream += BitArray('uint:8=%d' % len(self.records))

        # Add the nonce
        bitstream += BitArray(bytes=self.nonce)

        # Add the records
        for record in self.records:
            bitstream += record.to_bitstream()

        return bitstream.bytes
284855
def write(self, address, size, value):
        
        for i in range(0, size):
            self.__write_byte(address + i, (value >> (i * 8)) & 0xff)
217325
def record(self):
        # type: () -> bytes
        '''
        
        '''
        if not self._initialized:
            raise pycdlibexception.PyCdlibInternalError('PD record not yet initialized!')

        return b'PD' + struct.pack('=BB', RRPDRecord.length(self.padding),
                                   SU_ENTRY_VERSION) + self.padding
958668
def to_bytes(self):
        '''
        
        '''
        # Verify that properties make sense
        self.sanitize()

        # Start with the type
        bitstream = BitArray('uint:4=%d' % self.message_type)

        # Add the flags
        bitstream += BitArray('bool=%d' % self.is_reply)

        # Add reserved bits
        bitstream += self._reserved1

        # Add the nonce
        bitstream += BitArray(bytes=self.nonce)

        # Add the key-id and authentication data
        bitstream += BitArray('uint:16=%d, uint:16=%d, hex=%s'
                              % (self.key_id,
                                 len(self.authentication_data),
                                 self.authentication_data.encode('hex')))

        # Add the TTL
        bitstream += BitArray('uint:32=%d' % self.ttl)

        # Add reserved bits
        bitstream += self._reserved2

        # Add the EID prefix mask length
        bitstream += BitArray('uint:8=%d' % self.eid_prefix.prefixlen)

        # Add the EID prefix
        bitstream += get_bitstream_for_afi_address(self.eid_prefix)

        # Add the reply
        bitstream += get_bitstream_for_afi_address(self.reply)

        return bitstream.bytes
1172096
def _record(self):
        # type: () -> bytes
        '''
        
        '''
        return struct.pack(self.FMT, 1, self.platform_id, 0, self.id_string,
                           self.checksum, 0x55, 0xaa)
799513
def get_pdu_length(self):
        
        logger.info("getting PDU length")
        requested_ = c_uint16()
        negotiated_ = c_uint16()
        code = self.library.Cli_GetPduLength(self.pointer, byref(requested_), byref(negotiated_))
        check_error(code)

        return negotiated_.value
1080715
def push_irq_registers(self):
        
        self.cycles += 1
        self.push_word(self.system_stack_pointer, self.program_counter.value) # PC
        self.push_word(self.system_stack_pointer, self.user_stack_pointer.value) # U
        self.push_word(self.system_stack_pointer, self.index_y.value) # Y
        self.push_word(self.system_stack_pointer, self.index_x.value) # X
        self.push_byte(self.system_stack_pointer, self.direct_page.value) # DP
        self.push_byte(self.system_stack_pointer, self.accu_b.value) # B
        self.push_byte(self.system_stack_pointer, self.accu_a.value) # A
        self.push_byte(self.system_stack_pointer, self.get_cc_value())
785467
def write(self, pkt):
		
		self.setRTS(self.DD_WRITE)
		self.flushInput()
		# prep data array for transmition
		pkt = bytearray(pkt)
		pkt = bytes(pkt)

		num = self.serial.write(pkt)
		# self.serial.flush()
		# print('wrote {} of len(pkt) = {}'.format(num, len(pkt)))
		return num
1354975
def read_holding_registers(slave_id, starting_address, quantity):
    
    function = ReadHoldingRegisters()
    function.starting_address = starting_address
    function.quantity = quantity

    return _create_request_adu(slave_id, function.request_pdu)
687399
def build_single(mode):
    """"""
    if mode == 'force':
        amode = ['-a']
    else:
        amode = []
    if executable.endswith('uwsgi'):
        # hack, might fail in some environments!
        _executable = executable[:-5] + 'python'
    else:
        _executable = executable
    p = subprocess.Popen([_executable, '-m', 'nikola', 'build'] + amode,
                         stderr=subprocess.PIPE)
    p.wait()
    rl = p.stderr.readlines()
    try:
        out = ''.join(rl)
    except TypeError:
        out = ''.join(l.decode('utf-8') for l in rl)
    return (p.returncode == 0), out
1296921
def _create_mbap_header(slave_id, pdu):
    
    # 65535 = (2**16)-1 aka maximum number that fits in 2 bytes.
    transaction_id = randint(0, 65535)
    length = len(pdu) + 1

    return struct.pack('>HHHB', transaction_id, 0, length, slave_id)
165757
def write_byte(self, address, value):
        
        LOGGER.debug("Writing byte %s to device %s!", bin(value), hex(address))
        return self.driver.write_byte(address, value)
1265905
def single_registers(op):
    
    result = set()
    if isinstance(op, str):
        op = [op]

    for x in op:
        if is_8bit_register(x):
            result = result.union([x])
        elif x == 'sp':
            result.add(x)
        elif x == 'af':
            result = result.union(['a', 'f'])
        elif x == "af'":
            result = result.union(["a'", "f'"])
        elif is_16bit_register(x):  # Must be a 16bit reg or we have an internal error!
            result = result.union([LO16(x), HI16(x)])

    return list(result)
1183284
def write_core_register(self, reg, data):
        
        regIndex = register_name_to_index(reg)
        # Convert float to int.
        if is_single_float_register(regIndex) and type(data) is float:
            data = conversion.float32_to_u32(data)
        elif is_double_float_register(regIndex) and type(data) is float:
            data = conversion.float64_to_u64(data)
        self.write_core_register_raw(regIndex, data)
1312765
private void createImpl()
  {
    _systemSegment = allocateSegment(new byte[32], 1);
    
    _segmentList.add(_systemSegment);
    
    TempBuffer tBuf = TempBuffer.createLarge();
    byte []buffer = tBuf.buffer();
    
    Arrays.fill(buffer, (byte) 0);
    
    int offset = 0;
    
    BitsUtil.writeLong(buffer, offset, JOURNAL_MAGIC);
    offset += 8;
    
    BitsUtil.writeLong(buffer, offset, _segmentSize);
    offset += 8;
    
    BitsUtil.writeLong(buffer, offset, _tailAddress);
    offset += 8;
    
    BitsUtil.writeInt(buffer, offset, KEY_LENGTH);
    offset += 4;
    
    try (OutStore os = _store.openWrite(0, buffer.length)) {
      os.write(0, buffer, 0, buffer.length);
    }
    
    tBuf.free();
  }