本文整理匯總了Python中ctypes.c_uint16方法的典型用法代碼示例。如果您正苦於以下問題:Python ctypes.c_uint16方法的具體用法?Python ctypes.c_uint16怎麽用?Python ctypes.c_uint16使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ctypes
的用法示例。
在下文中一共展示了ctypes.c_uint16方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _ar_arsdk_encode_type_info
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [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]
示例2: test_padded_union
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [as 別名]
def test_padded_union(self):
dt = np.dtype(dict(
names=['a', 'b'],
offsets=[0, 0],
formats=[np.uint16, np.uint32],
itemsize=5,
))
ct = np.ctypeslib.as_ctypes_type(dt)
assert_(issubclass(ct, ctypes.Union))
assert_equal(ctypes.sizeof(ct), dt.itemsize)
assert_equal(ct._fields_, [
('a', ctypes.c_uint16),
('b', ctypes.c_uint32),
('', ctypes.c_char * 5), # padding
])
示例3: test_union_with_struct_packed
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [as 別名]
def test_union_with_struct_packed(self):
class Struct(ctypes.Structure):
_pack_ = 1
_fields_ = [
('one', ctypes.c_uint8),
('two', ctypes.c_uint32)
]
class Union(ctypes.Union):
_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)
示例4: test_union_packed
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [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)
示例5: test_large_packed_structure
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [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)
示例6: unpack
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [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
示例7: adapt_int_width
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [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
示例8: test_zz_encode_errors
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [as 別名]
def test_zz_encode_errors():
with pytest.raises(TypeError):
encode()
with pytest.raises(TypeError):
encode(None, None, 0, 0)
src_array = (c_uint16 * ARRAY_SIZE)()
src_array_addr = addressof(src_array)
dst_len = 9 * ARRAY_SIZE
# negative length
with pytest.raises(ValueError):
encode(src_array_addr, -1, sizeof(c_uint16), 0, dst_len)
# dest length too small
with pytest.raises(ValueError):
encode(src_array_addr, ARRAY_SIZE, 4, 0, 4)
# invalid word size
with pytest.raises(ValueError):
encode(src_array_addr, ARRAY_SIZE, 3, 0, 0)
# Null dest ptr
with pytest.raises(ValueError):
encode(src_array_addr, ARRAY_SIZE, 4, 0, dst_len)
示例9: __bind_socket
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [as 別名]
def __bind_socket(self, sock, iface, sid, did):
socket_id = ctypes.c_int(sock.fileno())
ifr = self.__get_sock_ifreq(sock, iface)
if sid > 0x7ff:
sid = sid | socket.CAN_EFF_FLAG
if did > 0x7ff:
did = did | socket.CAN_EFF_FLAG
# select the CAN interface and bind the socket to it
addr = SOCKADDR_CAN(ctypes.c_uint16(socket.PF_CAN),
ifr.ifr_ifindex,
ADDR_INFO(TP(ctypes.c_uint32(did),
ctypes.c_uint32(sid))))
error = LIBC.bind(socket_id, ctypes.byref(addr),
ctypes.sizeof(addr))
if error < 0:
warning("Couldn't bind socket")
示例10: __SetDLLReturnTypes
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [as 別名]
def __SetDLLReturnTypes(self):
self.nnotesdll.NotesInitExtended.restype = ctypes.c_uint16
self.nnotesdll.NotesTerm.restype = ctypes.c_uint16
self.nnotesdll.NSFDbOpen.restype = ctypes.c_uint16
self.nnotesdll.NSFDbClose.restype = ctypes.c_uint16
self.nnotesdll.NSFNoteOpenExt.restype = ctypes.c_uint16
self.nnotesdll.NSFNoteOpenByUNID.restype = ctypes.c_uint16
self.nnotesdll.NSFNoteClose.restype = ctypes.c_uint16
self.nnotesdll.NSFNoteCopy.restype = ctypes.c_uint16
self.nnotesdll.NSFNoteGetInfo.restype = None
self.nnotesdll.NSFNoteIsSignedOrSealed.restype = ctypes.c_bool
self.nnotesdll.NSFNoteDecrypt.restype = ctypes.c_uint16
self.nnotesdll.NSFItemDelete.restype = ctypes.c_uint16
self.nnotesdll.NSFNoteHasMIMEPart.restype = ctypes.c_bool
self.nnotesdll.NSFNoteHasMIME.restype = ctypes.c_bool
self.nnotesdll.NSFNoteHasComposite.restype = ctypes.c_bool
self.nnotesdll.MMCreateConvControls.restype = ctypes.c_uint16
self.nnotesdll.MMDestroyConvControls.restype = ctypes.c_uint16
self.nnotesdll.MMSetMessageContentEncoding.restype = None
self.nnotesdll.MIMEConvertCDParts.restype = ctypes.c_uint16
self.nnotesdll.MIMEConvertMIMEPartCC.restype = ctypes.c_uint16
self.nnotesdll.NSFNoteUpdate.restype = ctypes.c_uint16
示例11: as_arsdk_discovery_device_info
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [as 別名]
def as_arsdk_discovery_device_info(self):
return od.struct_arsdk_discovery_device_info(
od.char_pointer_cast(self.name),
od.arsdk_device_type(self.type),
od.char_pointer_cast(self.ip_addr),
ctypes.c_uint16(self.port),
od.char_pointer_cast(self.serial),
ctypes.c_uint32(self.proto_v),
)
示例12: read_word_data
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [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
示例13: process_call
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [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
示例14: test_scalar
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [as 別名]
def test_scalar(self):
dt = np.dtype('<u2')
ct = np.ctypeslib.as_ctypes_type(dt)
assert_equal(ct, ctypes.c_uint16.__ctype_le__)
dt = np.dtype('>u2')
ct = np.ctypeslib.as_ctypes_type(dt)
assert_equal(ct, ctypes.c_uint16.__ctype_be__)
dt = np.dtype('u2')
ct = np.ctypeslib.as_ctypes_type(dt)
assert_equal(ct, ctypes.c_uint16)
示例15: test_structure
# 需要導入模塊: import ctypes [as 別名]
# 或者: from ctypes import c_uint16 [as 別名]
def test_structure(self):
dt = np.dtype([
('a', np.uint16),
('b', np.uint32),
])
ct = np.ctypeslib.as_ctypes_type(dt)
assert_(issubclass(ct, ctypes.Structure))
assert_equal(ctypes.sizeof(ct), dt.itemsize)
assert_equal(ct._fields_, [
('a', ctypes.c_uint16),
('b', ctypes.c_uint32),
])