当前位置: 首页>>代码示例>>Python>>正文


Python ctypes.c_uint8方法代码示例

本文整理汇总了Python中ctypes.c_uint8方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.c_uint8方法的具体用法?Python ctypes.c_uint8怎么用?Python ctypes.c_uint8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ctypes的用法示例。


在下文中一共展示了ctypes.c_uint8方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_byte_data

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def read_byte_data(self, addr, cmd):
        """Read a single byte from the specified cmd register of the device."""
        assert (
            self._device is not None
        ), "Bus must be opened before operations are made against it!"
        # Build ctypes values to marshall between ioctl and Python.
        reg = c_uint8(cmd)
        result = c_uint8()
        # Build ioctl request.
        request = make_i2c_rdwr_data(
            [
                (addr, 0, 1, pointer(reg)),  # Write cmd register.
                (addr, I2C_M_RD, 1, pointer(result)),  # Read 1 byte as result.
            ]
        )
        # Make ioctl call and return result data.
        ioctl(self._device.fileno(), I2C_RDWR, request)
        return result.value 
开发者ID:adafruit,项目名称:Adafruit_Python_PureIO,代码行数:20,代码来源:smbus.py

示例2: _ar_arsdk_encode_type_info

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def _ar_arsdk_encode_type_info(cls, ar_argtype):
        arsdk_encode_type_info_map = {
            arsdkparser.ArArgType.I8: (od.ARSDK_ARG_TYPE_I8, "i8", ctypes.c_int8),
            arsdkparser.ArArgType.U8: (od.ARSDK_ARG_TYPE_U8, "u8", ctypes.c_uint8),
            arsdkparser.ArArgType.I16: (od.ARSDK_ARG_TYPE_I16, "i16", ctypes.c_int16),
            arsdkparser.ArArgType.U16: (od.ARSDK_ARG_TYPE_U16, "u16", ctypes.c_uint16),
            arsdkparser.ArArgType.I32: (od.ARSDK_ARG_TYPE_I32, "i32", ctypes.c_int32),
            arsdkparser.ArArgType.U32: (od.ARSDK_ARG_TYPE_U32, "u32", ctypes.c_uint32),
            arsdkparser.ArArgType.I64: (od.ARSDK_ARG_TYPE_I64, "i64", ctypes.c_int64),
            arsdkparser.ArArgType.U64: (od.ARSDK_ARG_TYPE_U64, "u64", ctypes.c_uint64),
            arsdkparser.ArArgType.FLOAT: (od.ARSDK_ARG_TYPE_FLOAT, "f32", ctypes.c_float),
            arsdkparser.ArArgType.DOUBLE: (od.ARSDK_ARG_TYPE_DOUBLE, "f64", ctypes.c_double),
            arsdkparser.ArArgType.STRING: (od.ARSDK_ARG_TYPE_STRING, "cstr", od.char_pointer_cast),
            arsdkparser.ArArgType.ENUM: (od.ARSDK_ARG_TYPE_ENUM, "i32", ctypes.c_int32),
        }
        return arsdk_encode_type_info_map[ar_argtype] 
开发者ID:Parrot-Developers,项目名称:olympe,代码行数:18,代码来源:messages.py

示例3: make_i2c_rdwr_data

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def make_i2c_rdwr_data(messages):
    """Utility function to create and return an i2c_rdwr_ioctl_data structure
    populated with a list of specified I2C messages.  The messages parameter
    should be a list of tuples which represent the individual I2C messages to
    send in this transaction.  Tuples should contain 4 elements: address value,
    flags value, buffer length, ctypes c_uint8 pointer to buffer.
    """
    # Create message array and populate with provided data.
    msg_data_type = i2c_msg * len(messages)
    msg_data = msg_data_type()
    for i, message in enumerate(messages):
        msg_data[i].addr = message[0] & 0x7F
        msg_data[i].flags = message[1]
        msg_data[i].len = message[2]
        msg_data[i].buf = message[3]
    # Now build the data structure.
    data = i2c_rdwr_ioctl_data()
    data.msgs = msg_data
    data.nmsgs = len(messages)
    return data


# Create an interface that mimics the Python SMBus API. 
开发者ID:adafruit,项目名称:Adafruit_Python_PureIO,代码行数:25,代码来源:smbus.py

示例4: test_union_packed

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def test_union_packed(self):
        class Struct(ctypes.Structure):
            _fields_ = [
                ('one', ctypes.c_uint8),
                ('two', ctypes.c_uint32)
            ]
            _pack_ = 1
        class Union(ctypes.Union):
            _pack_ = 1
            _fields_ = [
                ('a', ctypes.c_uint8),
                ('b', ctypes.c_uint16),
                ('c', ctypes.c_uint32),
                ('d', Struct),
            ]
        expected = np.dtype(dict(
            names=['a', 'b', 'c', 'd'],
            formats=['u1', np.uint16, np.uint32, [('one', 'u1'), ('two', np.uint32)]],
            offsets=[0, 0, 0, 0],
            itemsize=ctypes.sizeof(Union)
        ))
        self.check(Union, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:test_dtype.py

示例5: test_large_packed_structure

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def test_large_packed_structure(self):
        class PackedStructure(ctypes.Structure):
            _pack_ = 2
            _fields_ = [
                ('a', ctypes.c_uint8),
                ('b', ctypes.c_uint16),
                ('c', ctypes.c_uint8),
                ('d', ctypes.c_uint16),
                ('e', ctypes.c_uint32),
                ('f', ctypes.c_uint32),
                ('g', ctypes.c_uint8)
                ]
        expected = np.dtype(dict(
            formats=[np.uint8, np.uint16, np.uint8, np.uint16, np.uint32, np.uint32, np.uint8 ],
            offsets=[0, 2, 4, 6, 8, 12, 16],
            names=['a', 'b', 'c', 'd', 'e', 'f', 'g'],
            itemsize=18))
        self.check(PackedStructure, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_dtype.py

示例6: mutate_seq_8_bit_arithmetic_array

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def mutate_seq_8_bit_arithmetic_array(data, func, default_info, skip_null=False, effector_map=None, set_arith_max=None):
    if not set_arith_max:
        set_arith_max = AFL_ARITH_MAX

    for i in range(0, len(data)):
        if effector_map:
            if not effector_map[i]:
                continue
        if skip_null and data[i] == 0x00:
            continue

        for j in range(1, set_arith_max + 1):
            r = data[i] ^ (data[i] + j)
            if is_not_bitflip(ctypes.c_uint8(r).value):
                data[i] = (data[i] + j) & 0xff
                func(data.tostring(), default_info)
                data[i] = (data[i] - j) & 0xff

            r = data[i] ^ (data[i] - j)
            if is_not_bitflip(ctypes.c_uint8(r).value):
                data[i] = (data[i] - j) & 0xff
                func(data.tostring(), default_info)
                data[i] = (data[i] + j) & 0xff 
开发者ID:RUB-SysSec,项目名称:grimoire,代码行数:25,代码来源:arithmetic.py

示例7: is_valid

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def is_valid(self, msg):
        """Count and verify the checksum of a ubx message. msg is a list of hex values"""

        to_check = msg[2:-2]

        ck_a = ctypes.c_uint8(0)
        ck_b = ctypes.c_uint8(0)

        for num in to_check:
            byte = ctypes.c_uint8(num)
            ck_a.value = ck_a.value + byte.value
            ck_b.value = ck_b.value + ck_a.value

        if (ck_a.value, ck_b.value) == (ctypes.c_uint8(msg[-2]).value, ctypes.c_uint8(msg[-1]).value):
            return True
        else:
            return False 
开发者ID:Stefal,项目名称:rtkbase,代码行数:19,代码来源:gps_time.py

示例8: unpack

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def unpack(self, msg):
        """Extract the actual time from the message"""
        datetime = []

        # unpack year
        byte1 = ctypes.c_uint8(msg[18])
        byte2 = ctypes.c_uint8(msg[19])

        year = ctypes.c_uint16(byte2.value << 8 | byte1.value).value
        datetime.append(year)
        # unpack month, day, hour, minute, second
        for i in range(20, 25):
            datetime.append(msg[i])

        date = datetime[:3]
        time = datetime[3:]

        return date, time 
开发者ID:Stefal,项目名称:rtkbase,代码行数:20,代码来源:gps_time.py

示例9: adapt_int_width

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def adapt_int_width(n, width, signed=True):
    n = int(n)

    if width == 1:
        result = n
    elif width == 2:
        result = n
    elif width == 4:
        result = ctypes.c_int8(n).value if signed else ctypes.c_uint8(n).value
    elif width == 8:
        result = ctypes.c_int8(n).value if signed else ctypes.c_uint8(n).value
    elif width == 16:
        result = ctypes.c_int16(n).value if signed else ctypes.c_uint16(n).value
    elif width == 32:
        result = ctypes.c_int32(n).value if signed else ctypes.c_uint32(n).value
    elif width == 64:
        result = ctypes.c_int64(n).value if signed else ctypes.c_uint64(n).value
    else:
        result = n
    return result 
开发者ID:eth-sri,项目名称:debin,代码行数:22,代码来源:utils.py

示例10: _init_library

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def _init_library(self):
        self.dest_buffer = np.zeros((720, 1280, 4), np.uint8)

        libavf_dll = os.path.join('lib', 'libavf_ctypes.so')
        ctypes.cdll.LoadLibrary(libavf_dll)

        self.dll = ctypes.CDLL(libavf_dll)
        self.dll.initialize.argtypes = None
        self.dll.initialize.restype = None
        self.dll.deinitialize.argtypes = None
        self.dll.deinitialize.restype = None
        self.dll.read_frame.argtypes = [
            ndpointer(ctypes.c_uint8, flags="C_CONTIGUOUS")]
        self.dll.read_frame.restype = None
        self.dll.select_capture_source.argtypes = [ctypes.c_int]
        self.dll.select_capture_source.restype = None
        self.dll.get_source_count.argtypes = None
        self.dll.get_source_count.restype = ctypes.c_int
        self.dll.get_source_name.argtypes = [ctypes.c_int]
        self.dll.get_source_name.restype = ctypes.c_char_p 
开发者ID:hasegaw,项目名称:IkaLog,代码行数:22,代码来源:avfoundation_capture.py

示例11: check_zz_identity

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def check_zz_identity(src_array, int_type, min_nz_index, max_nz_index, total_count, offset):
    dst_len = (sizeof(int_type) + 1) * ARRAY_SIZE
    dst = (c_uint8 * (offset + dst_len))()

    varint_len = encode(addressof(src_array), ARRAY_SIZE, sizeof(int_type),
                        addressof(dst) + offset, dst_len)
    varint_string = string_at(dst, varint_len + offset)

    dst_array = (int_type * ARRAY_SIZE)()
    res = decode(varint_string, offset, addressof(dst_array), ARRAY_SIZE, sizeof(int_type))
    assert res['total'] == total_count
    if total_count:
        assert res['min_nonzero_index'] == min_nz_index
        assert res['max_nonzero_index'] == max_nz_index
    for index in range(ARRAY_SIZE):
        assert dst_array[index] == src_array[index]


# A large positive value that can fit 16-bit signed 
开发者ID:HdrHistogram,项目名称:HdrHistogram_py,代码行数:21,代码来源:test_hdrhistogram.py

示例12: _create_shared_arr

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def _create_shared_arr(self):
        TYPE = {
            np.float32: ctypes.c_float,
            np.float64: ctypes.c_double,
            np.uint8: ctypes.c_uint8,
            np.int8: ctypes.c_int8,
            np.int32: ctypes.c_int32,
        }
        ctype = TYPE[self.output_dtype]
        arr = mp.RawArray(ctype, int(np.prod(self.output_shape)))
        return arr 
开发者ID:tensorpack,项目名称:dataflow,代码行数:13,代码来源:parallel_map.py

示例13: read_word_data

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def read_word_data(self, addr, cmd):
        """Read a word (2 bytes) from the specified cmd register of the device.
        Note that this will interpret data using the endianness of the processor
        running Python (typically little endian)!
        """
        assert (
            self._device is not None
        ), "Bus must be opened before operations are made against it!"
        # Build ctypes values to marshall between ioctl and Python.
        reg = c_uint8(cmd)
        result = c_uint16()
        # Build ioctl request.
        request = make_i2c_rdwr_data(
            [
                (addr, 0, 1, pointer(reg)),  # Write cmd register.
                (
                    addr,
                    I2C_M_RD,
                    2,
                    cast(pointer(result), POINTER(c_uint8)),
                ),  # Read word (2 bytes).
            ]
        )
        # Make ioctl call and return result data.
        ioctl(self._device.fileno(), I2C_RDWR, request)
        return result.value 
开发者ID:adafruit,项目名称:Adafruit_Python_PureIO,代码行数:28,代码来源:smbus.py

示例14: read_i2c_block_data

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def read_i2c_block_data(self, addr, cmd, length=32):
        """Perform a read from the specified cmd register of device.  Length number
        of bytes (default of 32) will be read and returned as a bytearray.
        """
        assert (
            self._device is not None
        ), "Bus must be opened before operations are made against it!"
        # Build ctypes values to marshall between ioctl and Python.

        # convert register into bytearray
        if not isinstance(cmd, (bytes, bytearray)):
            reg = cmd  # backup
            cmd = bytearray(1)
            cmd[0] = reg

        cmdstring = create_string_buffer(len(cmd))
        for i, val in enumerate(cmd):
            cmdstring[i] = val

        result = create_string_buffer(length)

        # Build ioctl request.
        request = make_i2c_rdwr_data(
            [
                (
                    addr,
                    0,
                    len(cmd),
                    cast(cmdstring, POINTER(c_uint8)),
                ),  # Write cmd register.
                (addr, I2C_M_RD, length, cast(result, POINTER(c_uint8))),  # Read data.
            ]
        )

        # Make ioctl call and return result data.
        ioctl(self._device.fileno(), I2C_RDWR, request)
        return bytearray(
            result.raw
        )  # Use .raw instead of .value which will stop at a null byte! 
开发者ID:adafruit,项目名称:Adafruit_Python_PureIO,代码行数:41,代码来源:smbus.py

示例15: process_call

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_uint8 [as 别名]
def process_call(self, addr, cmd, val):
        """Perform a smbus process call by writing a word (2 byte) value to
        the specified register of the device, and then reading a word of response
        data (which is returned).
        """
        assert (
            self._device is not None
        ), "Bus must be opened before operations are made against it!"
        # Build ctypes values to marshall between ioctl and Python.
        data = create_string_buffer(struct.pack("=BH", cmd, val))
        result = c_uint16()
        # Build ioctl request.
        request = make_i2c_rdwr_data(
            [
                (addr, 0, 3, cast(pointer(data), POINTER(c_uint8))),  # Write data.
                (
                    addr,
                    I2C_M_RD,
                    2,
                    cast(pointer(result), POINTER(c_uint8)),
                ),  # Read word (2 bytes).
            ]
        )
        # Make ioctl call and return result data.
        ioctl(self._device.fileno(), I2C_RDWR, request)
        # Note the python-smbus code appears to have a rather serious bug and
        # does not return the result value!  This is fixed below by returning it.
        return result.value 
开发者ID:adafruit,项目名称:Adafruit_Python_PureIO,代码行数:30,代码来源:smbus.py


注:本文中的ctypes.c_uint8方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。