本文整理汇总了Python中ctypes.c_int16方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.c_int16方法的具体用法?Python ctypes.c_int16怎么用?Python ctypes.c_int16使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes
的用法示例。
在下文中一共展示了ctypes.c_int16方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _ar_arsdk_encode_type_info
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [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: _python_open_any_unit
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def _python_open_any_unit(self, resolution):
status = None
if len(self._open_unit.argtypes) == 3:
if resolution is None:
resolution = self.DEFAULT_RESOLUTION
chandle = c_int16()
cresolution = c_int32()
cresolution.value = resolution
status = self._open_unit(byref(chandle), None, cresolution)
handle = chandle.value
elif len(self._open_unit.argtypes) == 2:
chandle = c_int16()
status = self._open_unit(byref(chandle), None)
handle = chandle.value
else:
handle = self._open_unit()
return handle, status
示例3: _python_get_unit_info
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def _python_get_unit_info(self, handle, info_type):
string_size = 255
info = self._create_empty_string_buffer()
if len(self._get_unit_info.argtypes) == 4:
info_len = self._get_unit_info(c_int16(handle), info, c_int16(string_size), c_int16(info_type))
if info_len > 0:
return info.value[:info_len]
elif len(self._get_unit_info.argtypes) == 5:
required_size = c_int16(0)
status = self._get_unit_info(c_int16(handle),
info,
c_int16(string_size),
byref(required_size),
c_uint32(info_type))
if status == self.PICO_STATUS['PICO_OK']:
if required_size.value < string_size:
return info.value[:required_size.value]
return ""
示例4: set_null_trigger
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def set_null_trigger(self, device):
auto_trigger_after_millis = 1
if hasattr(self, '_set_trigger') and len(self._set_trigger.argtypes) == 6:
PS2000_NONE = 5
return_code = self._set_trigger(c_int16(device.handle),
c_int16(PS2000_NONE),
c_int16(0),
c_int16(0),
c_int16(0),
c_int16(auto_trigger_after_millis))
if return_code == 0:
raise InvalidTriggerParameters()
elif hasattr(self, '_set_simple_trigger') and len(self._set_simple_trigger.argtypes) == 7:
enabled = False
status = self._set_simple_trigger(c_int16(device.handle),
c_int16(int(enabled)),
c_int32(self.PICO_CHANNEL['A']),
c_int16(0),
c_int32(self.PICO_THRESHOLD_DIRECTION['NONE']),
c_uint32(0),
c_int16(auto_trigger_after_millis))
if status != self.PICO_STATUS['PICO_OK']:
raise InvalidTriggerParameters("set_simple_trigger failed (%s)" % constants.pico_tag(status))
else:
raise NotImplementedError("not done other driver types yet")
示例5: adapt_int_width
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [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
示例6: test_simple_concrete
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def test_simple_concrete():
s = SimState(arch="AMD64")
addr = 0xba5e0
def check_read(val):
nose.tools.assert_equal(s.solver.eval(s.memory.load(addr, 8, endness=Endness.LE), cast_to=int), val)
nose.tools.assert_equal(s.mem[addr].char.concrete, chr(val & 0xFF).encode())
nose.tools.assert_equal(s.mem[addr].byte.concrete, val & 0xFF)
nose.tools.assert_equal(s.mem[addr].int16_t.concrete, ctypes.c_int16(val & 0xFFFF).value)
nose.tools.assert_equal(s.mem[addr].uint16_t.concrete, val & 0xFFFF)
nose.tools.assert_equal(s.mem[addr].qword.concrete, val)
s.memory.store(addr, claripy.BVV(0x11223344aabbcc7d, 64), endness=Endness.LE)
check_read(0x11223344aabbcc7d)
# test storing
s.mem[addr].uint16_t = 0xef6d
check_read(0x11223344aabbef6d)
示例7: zone_write_int16_values
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def zone_write_int16_values(file_handle, zone, var, values):
tecio.tecZoneVarWriteInt16Values.restype=ctypes.c_int32
tecio.tecZoneVarWriteInt16Values.argtypes=(
ctypes.c_void_p, #file_handle
ctypes.c_int32, #zone
ctypes.c_int32, #var
ctypes.c_int32, #partition
ctypes.c_int64, #count
ctypes.POINTER(ctypes.c_int16)) #values
values_ptr = (ctypes.c_int16*len(values))(*values)
ret = tecio.tecZoneVarWriteInt16Values(file_handle,
zone,
var,
0,
len(values),
values_ptr)
if ret != 0:
raise Exception("zone_write_int16_values Error")
示例8: _return_ctype
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def _return_ctype(self):
""" Returns the associated ctype of a given datatype. """
_datatype_ctype = {
DataType.Bool: ctypes.c_uint8,
DataType.I8: ctypes.c_int8,
DataType.U8: ctypes.c_uint8,
DataType.I16: ctypes.c_int16,
DataType.U16: ctypes.c_uint16,
DataType.I32: ctypes.c_int32,
DataType.U32: ctypes.c_uint32,
DataType.I64: ctypes.c_int64,
DataType.U64: ctypes.c_uint64,
DataType.Sgl: ctypes.c_float,
DataType.Dbl: ctypes.c_double,
DataType.Fxp: ctypes.c_uint32,
DataType.Cluster: ctypes.c_uint32,
}
return _datatype_ctype[self]
示例9: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def __init__(self):
self.__dll__ = ctypes.windll.LoadLibrary('tests/demo_dll.dll')
self.__square_int_array_with_struct__ = self.__dll__.square_int_array_with_struct
self.__square_int_array_with_struct__.argtypes = (
ctypes.POINTER(int_array_data),
ctypes.POINTER(int_array_data)
)
self.__square_int_array_with_struct__.memsync = [
{
'p': [0, 'data'],
'l': [0, 'len'],
't': 'c_int16'
},
{
'p': [1, 'data'],
'l': [1, 'len'],
't': 'c_int16'
}
]
示例10: square_int_array_with_struct
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def square_int_array_with_struct(self, in_array):
in_array_obj = int_array_data()
out_array_obj = int_array_data()
in_array_obj.data = ctypes.cast(
ctypes.pointer((ctypes.c_int16 * len(in_array))(*in_array)),
ctypes.POINTER(ctypes.c_int16)
)
in_array_obj.len = len(in_array)
self.__square_int_array_with_struct__(
in_array_obj,
out_array_obj
)
return ctypes.cast(
out_array_obj.data,
ctypes.POINTER(ctypes.c_int16 * len(in_array))
).contents[:]
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# TEST(s)
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
示例11: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def __init__(self):
self.__dll__ = ctypes.windll.LoadLibrary('tests/demo_dll.dll')
self.__sum_elements_from_callback_in_struct__ = self.__dll__.sum_elements_from_callback_in_struct
self.__sum_elements_from_callback_in_struct__.argtypes = (ctypes.POINTER(conveyor_belt_data),)
self.__sum_elements_from_callback_in_struct__.restype = ctypes.c_int16
self.DATA = [1, 6, 8, 4, 9, 7, 4, 2, 5, 2]
@conveyor_belt
def get_data(index):
print((index, self.DATA[index]))
return self.DATA[index]
self.__get_data__ = get_data
示例12: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def __init__(self):
self.__dll__ = ctypes.windll.LoadLibrary('tests/demo_dll.dll')
self.__square_int_array__ = self.__dll__.square_int_array
self.__square_int_array__.argtypes = (
ctypes.POINTER(ctypes.c_int16),
ctypes.c_void_p,
ctypes.c_int16
)
self.__square_int_array__.memsync = [
{
'p': [0],
'l': [2],
't': 'c_int16'
},
{
'p': [1, -1],
'l': [2],
't': 'c_int16'
}
]
示例13: square_int_array
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def square_int_array(self, in_array):
in_array_p = ctypes.cast(
ctypes.pointer((ctypes.c_int16 * len(in_array))(*in_array)),
ctypes.POINTER(ctypes.c_int16)
)
out_array_p = ctypes.pointer(ctypes.c_void_p())
self.__square_int_array__(
in_array_p,
out_array_p,
ctypes.c_int16(len(in_array))
)
return ctypes.cast(
out_array_p.contents,
ctypes.POINTER(ctypes.c_int16 * len(in_array))
).contents[:]
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# TEST(s)
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
示例14: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def __init__(self):
self.__dll__ = ctypes.windll.LoadLibrary('tests/demo_dll.dll')
conveyor_belt = ctypes.WINFUNCTYPE(ctypes.c_int16, ctypes.c_int16)
self.__sum_elements_from_callback__ = self.__dll__.sum_elements_from_callback
self.__sum_elements_from_callback__.argtypes = (ctypes.c_int16, conveyor_belt)
self.__sum_elements_from_callback__.restype = ctypes.c_int16
self.DATA = [1, 6, 8, 4, 9, 7, 4, 2, 5, 2]
@conveyor_belt
def get_data(index):
print((index, self.DATA[index]))
return self.DATA[index]
self.__get_data__ = get_data
示例15: test_struct_array_pointer
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_int16 [as 别名]
def test_struct_array_pointer(self):
from ctypes import c_int16, Structure, pointer
class Struct(Structure):
_fields_ = [('a', c_int16)]
Struct3 = 3 * Struct
c_array = (2 * Struct3)(
Struct3(Struct(a=1), Struct(a=2), Struct(a=3)),
Struct3(Struct(a=4), Struct(a=5), Struct(a=6))
)
expected = np.array([
[(1,), (2,), (3,)],
[(4,), (5,), (6,)],
], dtype=[('a', np.int16)])
def check(x):
assert_equal(x.dtype, expected.dtype)
assert_equal(x, expected)
# all of these should be equivalent
check(as_array(c_array))
check(as_array(pointer(c_array), shape=()))
check(as_array(pointer(c_array[0]), shape=(2,)))
check(as_array(pointer(c_array[0][0]), shape=(2, 3)))