python uint8怎么定义_Python ctypes.c_uint8方法代码示例

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

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

示例1: _ar_arsdk_encode_type_info

​点赞 6

# 需要导入模块: 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,

示例2: make_i2c_rdwr_data

​点赞 6

# 需要导入模块: 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,

示例3: read_byte_data

​点赞 6

# 需要导入模块: 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,

示例4: test_union_packed

​点赞 6

# 需要导入模块: 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,

示例5: test_large_packed_structure

​点赞 6

# 需要导入模块: 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,

示例6: mutate_seq_8_bit_arithmetic_array

​点赞 6

# 需要导入模块: 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,

示例7: is_valid

​点赞 6

# 需要导入模块: 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,

示例8: unpack

​点赞 6

# 需要导入模块: 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,

示例9: adapt_int_width

​点赞 6

# 需要导入模块: 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,

示例10: _init_library

​点赞 6

# 需要导入模块: 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,

示例11: check_zz_identity

​点赞 6

# 需要导入模块: 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,

示例12: _create_shared_arr

​点赞 5

# 需要导入模块: 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,

示例13: read_word_data

​点赞 5

# 需要导入模块: 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,

示例14: read_i2c_block_data

​点赞 5

# 需要导入模块: 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,

示例15: process_call

​点赞 5

# 需要导入模块: 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,

示例16: test_array

​点赞 5

# 需要导入模块: import ctypes [as 别名]

# 或者: from ctypes import c_uint8 [as 别名]

def test_array(self):

c8 = ctypes.c_uint8

self.check( 3 * c8, (np.uint8, (3,)))

self.check( 1 * c8, (np.uint8, (1,)))

self.check( 0 * c8, (np.uint8, (0,)))

self.check(1 * (3 * c8), ((np.uint8, (3,)), (1,)))

self.check(3 * (1 * c8), ((np.uint8, (1,)), (3,)))

开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,

示例17: test_padded_structure

​点赞 5

# 需要导入模块: import ctypes [as 别名]

# 或者: from ctypes import c_uint8 [as 别名]

def test_padded_structure(self):

class PaddedStruct(ctypes.Structure):

_fields_ = [

('a', ctypes.c_uint8),

('b', ctypes.c_uint16)

]

expected = np.dtype([

('a', np.uint8),

('b', np.uint16)

], align=True)

self.check(PaddedStruct, expected)

开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,

示例18: test_bit_fields

​点赞 5

# 需要导入模块: import ctypes [as 别名]

# 或者: from ctypes import c_uint8 [as 别名]

def test_bit_fields(self):

class BitfieldStruct(ctypes.Structure):

_fields_ = [

('a', ctypes.c_uint8, 7),

('b', ctypes.c_uint8, 1)

]

assert_raises(TypeError, np.dtype, BitfieldStruct)

assert_raises(TypeError, np.dtype, BitfieldStruct())

开发者ID:Frank-qlu,项目名称:recruit,代码行数:10,

示例19: test_pointer

​点赞 5

# 需要导入模块: import ctypes [as 别名]

# 或者: from ctypes import c_uint8 [as 别名]

def test_pointer(self):

p_uint8 = ctypes.POINTER(ctypes.c_uint8)

assert_raises(TypeError, np.dtype, p_uint8)

开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,

示例20: test_union

​点赞 5

# 需要导入模块: import ctypes [as 别名]

# 或者: from ctypes import c_uint8 [as 别名]

def test_union(self):

class Union(ctypes.Union):

_fields_ = [

('a', ctypes.c_uint8),

('b', ctypes.c_uint16),

]

expected = np.dtype(dict(

names=['a', 'b'],

formats=[np.uint8, np.uint16],

offsets=[0, 0],

itemsize=2

))

self.check(Union, expected)

开发者ID:Frank-qlu,项目名称:recruit,代码行数:15,

示例21: test_packed_structure

​点赞 5

# 需要导入模块: import ctypes [as 别名]

# 或者: from ctypes import c_uint8 [as 别名]

def test_packed_structure(self):

class PackedStructure(ctypes.Structure):

_pack_ = 1

_fields_ = [

('a', ctypes.c_uint8),

('b', ctypes.c_uint16)

]

expected = np.dtype([

('a', np.uint8),

('b', np.uint16)

])

self.check(PackedStructure, expected)

开发者ID:Frank-qlu,项目名称:recruit,代码行数:14,

示例22: test_big_endian_structure_packed

​点赞 5

# 需要导入模块: import ctypes [as 别名]

# 或者: from ctypes import c_uint8 [as 别名]

def test_big_endian_structure_packed(self):

class BigEndStruct(ctypes.BigEndianStructure):

_fields_ = [

('one', ctypes.c_uint8),

('two', ctypes.c_uint32)

]

_pack_ = 1

expected = np.dtype([('one', 'u1'), ('two', '>u4')])

self.check(BigEndStruct, expected)

开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,

示例23: test_little_endian_structure_packed

​点赞 5

# 需要导入模块: import ctypes [as 别名]

# 或者: from ctypes import c_uint8 [as 别名]

def test_little_endian_structure_packed(self):

class LittleEndStruct(ctypes.LittleEndianStructure):

_fields_ = [

('one', ctypes.c_uint8),

('two', ctypes.c_uint32)

]

_pack_ = 1

expected = np.dtype([('one', 'u1'), ('two', '

self.check(LittleEndStruct, expected)

开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,

示例24: test_big_endian_structure

​点赞 5

# 需要导入模块: import ctypes [as 别名]

# 或者: from ctypes import c_uint8 [as 别名]

def test_big_endian_structure(self):

class PaddedStruct(ctypes.BigEndianStructure):

_fields_ = [

('a', ctypes.c_uint8),

('b', ctypes.c_uint16)

]

expected = np.dtype([

('a', '>B'),

('b', '>H')

], align=True)

self.check(PaddedStruct, expected)

开发者ID:Frank-qlu,项目名称:recruit,代码行数:13,

示例25: test_simple_endian_types

​点赞 5

# 需要导入模块: import ctypes [as 别名]

# 或者: from ctypes import c_uint8 [as 别名]

def test_simple_endian_types(self):

self.check(ctypes.c_uint16.__ctype_le__, np.dtype('

self.check(ctypes.c_uint16.__ctype_be__, np.dtype('>u2'))

self.check(ctypes.c_uint8.__ctype_le__, np.dtype('u1'))

self.check(ctypes.c_uint8.__ctype_be__, np.dtype('u1'))

开发者ID:Frank-qlu,项目名称:recruit,代码行数:7,

示例26: __init__

​点赞 5

# 需要导入模块: import ctypes [as 别名]

# 或者: from ctypes import c_uint8 [as 别名]

def __init__(self, floating=None, shared_memory=False, numpy_dtype=None):

if numpy_dtype:

log.debug('Using numpy')

if numpy_dtype in NUMPY_DEFAULTS:

numpy_dtype = 'float32'

if numpy_dtype not in numpy.sctypeDict:

raise ValueError(BAD_NUMPY_TYPE_ERROR % numpy_dtype)

if shared_memory and numpy_dtype:

log.error('Shared memory for numpy arrays is not yet supported.')

numpy_dtype = None

if floating is None:

floating = not shared_memory

c_type = c_float if floating else c_uint8

if shared_memory:

self.bytes = lambda size: RawArray(c_uint8, size)

self.color_list = lambda size: RawArray(3 * c_type, size)

# Note https://stackoverflow.com/questions/37705974/

elif numpy_dtype:

self.bytes = bytearray

self.color_list = lambda size: numpy.zeros((size, 3), numpy_dtype)

else:

self.bytes = bytearray

self.color_list = lambda size: [(0, 0, 0)] * size

开发者ID:ManiacalLabs,项目名称:BiblioPixel,代码行数:31,

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值