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


Python ctypes.c_ushort方法代码示例

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


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

示例1: getChannelData_Firmware

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def getChannelData_Firmware(self, channel):
        """Get device firmware version
        Retrieves the firmvare version numbers for the device connected to
        channel.
        Args:
            channel (int): The channel you are interested in
        Returns:
            major (int): The major version number
            minor (int): The minor version number
            build (int): The build number
        """
        self.fn = inspect.currentframe().f_code.co_name
        buf_type = ct.c_ushort * 4
        buf = buf_type()
        self.dll.canGetChannelData(channel,
                                   canCHANNELDATA_CARD_FIRMWARE_REV,
                                   ct.byref(buf), ct.sizeof(buf))
        (build, release, minor, major) = struct.unpack('HHHH', buf)
        return (major, minor, build) 
开发者ID:diyjac,项目名称:Udacity-SDC-Radar-Driver-Micro-Challenge,代码行数:21,代码来源:canlib.py

示例2: MessageClass

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def MessageClass(length=DMX_LENGTH):
    assert 0 <= length <= DMX_LENGTH
    assert length % 2 == 0, 'artnet only takes messages of even length'

    Char, Int8, Int16 = ctypes.c_char, ctypes.c_ubyte, ctypes.c_ushort

    class DMXMessage(ctypes.Structure):
        # http://artisticlicence.com/WebSiteMaster/User%20Guides/art-net.pdf p47
        _fields_ = [
            ('id', Char * 8),
            ('opCode', Int16),
            ('protVerHi', Int8),
            ('protVerLo', Int8),
            ('sequence', Int8),
            ('physical', Int8),
            ('subUni', Int8),
            ('net', Int8),
            ('lengthHi', Int8),
            ('length', Int8),
            ('data', Int8 * length),  # At position 18
        ]

    return DMXMessage 
开发者ID:ManiacalLabs,项目名称:BiblioPixel,代码行数:25,代码来源:artnet_message.py

示例3: wrap

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def wrap(self, gammaramp):
        '''
        Wraps a nested python sequence.
        '''
        red, green, blue = gammaramp
        size = min(len(red), len(green), len(blue))
        array_type = ctypes.c_ushort*size
        self.size = ctypes.c_uint(size)
        self.red_array = array_type()
        self.green_array = array_type()
        self.blue_array = array_type()
        for i in range(self.size):
            self.red_array[i] = int(red[i]*65535)
            self.green_array[i] = int(green[i]*65535)
            self.blue_array[i] = int(blue[i]*65535)
        pointer_type = ctypes.POINTER(ctypes.c_ushort)
        self.red = ctypes.cast(self.red_array, pointer_type)
        self.green = ctypes.cast(self.green_array, pointer_type)
        self.blue = ctypes.cast(self.blue_array, pointer_type) 
开发者ID:fogleman,项目名称:pg,代码行数:21,代码来源:glfw.py

示例4: win_create_mdb

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def win_create_mdb(mdb_path, sort_order = "General\0\0"):
    if sys.platform not in ('win32','cli'):
        raise Exception('This function is available for use in Windows only.')
    
    mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
    if mdb_driver == []:
        raise Exception('Access Driver is not found.')
    else:
        driver_name = mdb_driver[0].encode('mbcs')


    #CREATE_DB=<path name> <sort order>
    ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]

    if py_v3:
        c_Path =  bytes("CREATE_DB=" + mdb_path + " " + sort_order,'mbcs')
    else:
        c_Path =  "CREATE_DB=" + mdb_path + " " + sort_order
    ODBC_ADD_SYS_DSN = 1
    
    
    ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
    if not ret:
        raise Exception('Failed to create Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %mdb_path) 
开发者ID:harryliu,项目名称:edwin,代码行数:26,代码来源:pypyodbc.py

示例5: win_compact_mdb

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def win_compact_mdb(mdb_path, compacted_mdb_path, sort_order = "General\0\0"):
    if sys.platform not in ('win32','cli'):
        raise Exception('This function is available for use in Windows only.')
    
    
    mdb_driver = [d for d in drivers() if 'Microsoft Access Driver (*.mdb' in d]
    if mdb_driver == []:
        raise Exception('Access Driver is not found.')
    else:
        driver_name = mdb_driver[0].encode('mbcs')
    
    #COMPACT_DB=<source path> <destination path> <sort order>
    ctypes.windll.ODBCCP32.SQLConfigDataSource.argtypes = [ctypes.c_void_p,ctypes.c_ushort,ctypes.c_char_p,ctypes.c_char_p]
    #driver_name = "Microsoft Access Driver (*.mdb)"
    if py_v3:
        c_Path = bytes("COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order,'mbcs')
        #driver_name = bytes(driver_name,'mbcs')
    else:
        c_Path = "COMPACT_DB=" + mdb_path + " " + compacted_mdb_path + " " + sort_order

    ODBC_ADD_SYS_DSN = 1
    ret = ctypes.windll.ODBCCP32.SQLConfigDataSource(None,ODBC_ADD_SYS_DSN,driver_name, c_Path)
    if not ret:
        raise Exception('Failed to compact Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %compacted_mdb_path) 
开发者ID:harryliu,项目名称:edwin,代码行数:26,代码来源:pypyodbc.py

示例6: crc16

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def crc16(telegram):
        crc16_tab = []

        for i in range(0, 256):
            crc = c_ushort(i).value
            for j in range(0, 8):
                if (crc & 0x0001):
                    crc = c_ushort(crc >> 1).value ^ 0xA001
                else:
                    crc = c_ushort(crc >> 1).value
            crc16_tab.append(hex(crc))

        crcValue = 0x0000

        for c in telegram:
            d = ord(c)
            tmp = crcValue ^ d
            rotated = c_ushort(crcValue >> 8).value
            crcValue = rotated ^ int(crc16_tab[(tmp & 0x00ff)], 0)

        return crcValue 
开发者ID:ndokter,项目名称:dsmr_parser,代码行数:23,代码来源:parsers.py

示例7: get_ramp

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def get_ramp(self):
        display = self._display
        screen_num = self._screen_num

        ramp_size = self.ramp_size
        ramp = (c_ushort * ramp_size * 3)()

        gamma_r = byref(ramp, 0 * ramp_size * C_USHORT_SIZE)
        gamma_g = byref(ramp, 1 * ramp_size * C_USHORT_SIZE)
        gamma_b = byref(ramp, 2 * ramp_size * C_USHORT_SIZE)

        if not XF86VidModeGetGammaRamp(display, screen_num, ramp_size,
                                       gamma_r, gamma_g, gamma_b):
            raise ContextError('Unable to get gamma ramp')

        return [[ramp[i][j] / C_USHORT_MAX for j in range(ramp_size)]
                for i in range(3)] 
开发者ID:dev7355608,项目名称:csgo_dont_blind_me,代码行数:19,代码来源:context_vidmode.py

示例8: set_ramp

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def set_ramp(self, ramp):
        display = self._display
        screen_num = self._screen_num

        ramp_size = self.ramp_size
        _ramp = (c_ushort * ramp_size * 3)()

        for i in range(3):
            for j in range(ramp_size):
                _ramp[i][j] = int(C_USHORT_MAX * ramp[i][j])

        gamma_r = byref(_ramp, 0 * ramp_size * C_USHORT_SIZE)
        gamma_g = byref(_ramp, 1 * ramp_size * C_USHORT_SIZE)
        gamma_b = byref(_ramp, 2 * ramp_size * C_USHORT_SIZE)

        if not XF86VidModeSetGammaRamp(display, screen_num, ramp_size,
                                       gamma_r, gamma_g, gamma_b):
            raise ContextError('Unable to set gamma ramp') 
开发者ID:dev7355608,项目名称:csgo_dont_blind_me,代码行数:20,代码来源:context_vidmode.py

示例9: shmem_as_ndarray

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def shmem_as_ndarray(raw_array):
    _ctypes_to_numpy = {
        ctypes.c_char: np.int8,
        ctypes.c_wchar: np.int16,
        ctypes.c_byte: np.int8,
        ctypes.c_ubyte: np.uint8,
        ctypes.c_short: np.int16,
        ctypes.c_ushort: np.uint16,
        ctypes.c_int: np.int32,
        ctypes.c_uint: np.int32,
        ctypes.c_long: np.int32,
        ctypes.c_ulong: np.int32,
        ctypes.c_float: np.float32,
        ctypes.c_double: np.float64
    }
    dtype = _ctypes_to_numpy[raw_array._type_]

    # The following works too, but occasionally raises
    # RuntimeWarning: Item size computed from the PEP 3118 buffer format string does not match the actual item size.
    # and appears to be slower.
    # return np.ctypeslib.as_array(raw_array)

    return np.frombuffer(raw_array, dtype=dtype) 
开发者ID:pytroll,项目名称:pyresample,代码行数:25,代码来源:_multi_proc.py

示例10: is_ipv6

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def is_ipv6(ip):
    try:
        if os.name == "nt":
            class sockaddr(ctypes.Structure):
                _fields_ = [("sa_family", ctypes.c_short),
                            ("__pad1", ctypes.c_ushort),
                            ("ipv4_addr", ctypes.c_byte * 4),
                            ("ipv6_addr", ctypes.c_byte * 16),
                            ("__pad2", ctypes.c_ulong)]

            WSAStringToAddressA = ctypes.windll.ws2_32.WSAStringToAddressA
            addr = sockaddr()
            addr.sa_family = socket.AF_INET6
            addr_size = ctypes.c_int(ctypes.sizeof(addr))
            if WSAStringToAddressA(ip, socket.AF_INET6, None, ctypes.byref(addr), ctypes.byref(addr_size)) != 0:
                raise socket.error(ctypes.FormatError())
            return ctypes.string_at(addr.ipv6_addr, 16)
        else:
            return socket.inet_pton(socket.AF_INET6, ip)
    except:
        return False 
开发者ID:bwall,项目名称:ircsnapshot,代码行数:23,代码来源:ircsnapshot.py

示例11: adjust_rate

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def adjust_rate(ctrl_iface, rate=1e6):
    log.info(f"Setting rate to {rate}")
    bw_lib = ctypes.CDLL(f"{FILE_DIR}/dc_gym/control/libbw_control.so")
    bw_lib.init_ring.argtypes = [
        ctypes.c_char_p, ctypes.c_ushort, ctypes.c_uint]
    bw_lib.init_ring.restype = ctypes.POINTER(Ring)
    bw_lib.send_bw.argtypes = [
        ctypes.c_uint32, ctypes.POINTER(Ring), ctypes.c_ushort]
    bw_lib.send_bw.restype = ctypes.c_int
    bw_lib.wait_for_reply.argtypes = [ctypes.POINTER(Ring)]
    rx_ring = bw_lib.init_ring(
        ctrl_iface.encode("ascii"), SRC_PORT,
        PACKET_RX_RING)
    tx_ring = bw_lib.init_ring(
        ctrl_iface.encode("ascii"), SRC_PORT,
        PACKET_TX_RING)
    bw_lib.send_bw(int(rate), tx_ring, DST_PORT)
    bw_lib.wait_for_reply(rx_ring) 
开发者ID:dcgym,项目名称:iroko,代码行数:20,代码来源:control_test.py

示例12: calculate

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def calculate(self, input_data=None):
        try:
            is_string = isinstance(input_data, str)
            is_bytes = isinstance(input_data, bytes)

            if not is_string and not is_bytes:
                raise Exception("Please provide a string or a byte sequence \
                    as argument for calculation.")

            crcValue = self.starting_value

            for c in input_data:
                d = ord(c) if is_string else c
                tmp = (c_ushort(crcValue >> 8).value) ^ d
                crcValue = (c_ushort(crcValue << 8).value) ^ int(
                    self.crc_ccitt_tab[tmp], 0)

            return crcValue
        except Exception as e:
            print("EXCEPTION(calculate): {}".format(e)) 
开发者ID:alexbutirskiy,项目名称:PyCRC,代码行数:22,代码来源:CRCCCITT.py

示例13: calculate

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def calculate(self, input_data=None):
        try:
            is_string = isinstance(input_data, str)
            is_bytes = isinstance(input_data, bytes)

            if not is_string and not is_bytes:
                raise Exception("Please provide a string or a byte sequence "
                                "as argument for calculation.")

            crcValue = 0x0000 if not self.mdflag else 0xffff

            for c in input_data:
                d = ord(c) if is_string else c
                tmp = crcValue ^ d
                rotated = c_ushort(crcValue >> 8).value
                crcValue = rotated ^ int(self.crc16_tab[(tmp & 0x00ff)], 0)

            return crcValue
        except Exception as e:
            print("EXCEPTION(calculate): {}".format(e)) 
开发者ID:alexbutirskiy,项目名称:PyCRC,代码行数:22,代码来源:CRC16.py

示例14: LOWORD

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def LOWORD(a): return (ctypes.c_ushort)(a) 
开发者ID:Wyliodrin,项目名称:pybass,代码行数:3,代码来源:pybass.py

示例15: HIWORD

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_ushort [as 别名]
def HIWORD(a): return (ctypes.c_ushort)((a)>>16) 
开发者ID:Wyliodrin,项目名称:pybass,代码行数:3,代码来源:pybass.py


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