當前位置: 首頁>>代碼示例>>Python>>正文


Python ctypes.c_uint16方法代碼示例

本文整理匯總了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] 
開發者ID:Parrot-Developers,項目名稱:olympe,代碼行數:18,代碼來源:messages.py

示例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
        ]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_ctypeslib.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:24,代碼來源:test_dtype.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:24,代碼來源:test_dtype.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:20,代碼來源:test_dtype.py

示例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 
開發者ID:Stefal,項目名稱:rtkbase,代碼行數:20,代碼來源:gps_time.py

示例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 
開發者ID:eth-sri,項目名稱:debin,代碼行數:22,代碼來源:utils.py

示例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) 
開發者ID:HdrHistogram,項目名稱:HdrHistogram_py,代碼行數:23,代碼來源:test_hdrhistogram.py

示例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") 
開發者ID:secdev,項目名稱:scapy,代碼行數:22,代碼來源:isotp.py

示例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 
開發者ID:adb014,項目名稱:nsf2x,代碼行數:24,代碼來源:nsf2x.py

示例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),
        ) 
開發者ID:Parrot-Developers,項目名稱:olympe,代碼行數:11,代碼來源:discovery.py

示例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 
開發者ID:adafruit,項目名稱:Adafruit_Python_PureIO,代碼行數:28,代碼來源:smbus.py

示例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 
開發者ID:adafruit,項目名稱:Adafruit_Python_PureIO,代碼行數:30,代碼來源:smbus.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:14,代碼來源:test_ctypeslib.py

示例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),
        ]) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:15,代碼來源:test_ctypeslib.py


注:本文中的ctypes.c_uint16方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。