• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

All Samples(4622)  |  Call(4188)  |  Derive(0)  |  Import(434)
byref(C instance[, offset=0]) -> byref-object
Return a pointer lookalike to a C instance, only usable
as function argument

src/p/y/python-cookbook-HEAD/cb2_examples/cb2_17_4_sol_1.py   python-cookbook(Download)
from ctypes import windll, c_int, c_string, byref
# load 'Ehllapi.dll' (from current dir), and function 'hllapi' from the DLL
Ehllap32 = windll.ehllapi
hllapi = Ehllap32.hllapi
# prepare the arguments with types and initial values
h_func = c_int(1)
h_text = c_string('A')
h_len = c_int(1)
h_ret = c_int(999)
# call the function
hllapi(byref(h_func), h_text, byref(h_len), byref(h_ret))

src/p/y/py_examples-HEAD/opencv/CVtypes.py   py_examples(Download)
# --- Importe ----------------------------------------------------------------
 
import ctypes, os
from ctypes import Structure, Union, POINTER, SetPointerType, CFUNCTYPE, cdll, byref
from ctypes import c_char_p, c_double, c_float, c_byte, c_ubyte, c_int, c_void_p, c_ulong
from ctypes import c_uint32, c_short, c_char, c_longlong
 
    def from_param(self, param):
        return byref(param)
 
class CallableToFunc(object):
    '''Make the callable argument into a C callback'''
    def __init__(self, cbacktype):
        self.cbacktype = cbacktype

src/e/v/eventghost-HEAD/trunk/plugins/PS3/__init__.py   eventghost(Download)
import wx.lib.mixins.listctrl as listmix
 
from ctypes import Structure, Union, c_byte, c_ubyte, c_char, c_int, c_long, c_ulong, c_ushort, c_wchar
from ctypes import pointer, byref, sizeof, POINTER
from ctypes.wintypes import ULONG, BOOLEAN, BOOL
 
class Ps3Remote:
    def read_link_mode(bd_addr):
        mode = c_ubyte(0)
        result = ReadLinkMode(bd_addr, byref(mode))
 
        if result:
            return mode.value
 
 
        #get guid for HID device class
        g = GUID()
        hidDLL.HidD_GetHidGuid(byref(g))
 
        #get handle to the device information set
        hinfo = setupapiDLL.SetupDiGetClassDevsA(byref(g), None, None,
            DIGCF_PRESENT + DIGCF_DEVICEINTERFACE)
 
        #enumerate devices
        i = 0
        while setupapiDLL.SetupDiEnumDeviceInterfaces(hinfo,
            None, byref(g), i, byref(interfaceInfo)):
            #get the required size
            requiredSize = c_ulong()
            setupapiDLL.SetupDiGetDeviceInterfaceDetailA(hinfo,
                byref(interfaceInfo), None, 0, byref(requiredSize), None)
            if requiredSize.value > 250:
                eg.PrintError(self.text.errorRetrieval)
                continue #prevent a buffer overflow
 
            #get the actual info
            setupapiDLL.SetupDiGetDeviceInterfaceDetailA(
                hinfo,
                byref(interfaceInfo),
                byref(interfaceDetailData),
                continue
 
            #getting additional info
            hidDLL.HidD_GetAttributes(int(hidHandle), byref(hiddAttributes))
            device[VENDOR_ID] = hiddAttributes.VendorID
            device[PRODUCT_ID] = hiddAttributes.ProductID
            device[VERSION_NUMBER] = hiddAttributes.VersionNumber
 
            #getting manufacturer
            result = hidDLL.HidD_GetManufacturerString(
                int(hidHandle), byref(infoStr), ctypes.sizeof(infoStr))
            if not result or len(infoStr.value) == 0:
                #build a generic ManufacturerString with the vendor ID
                device[VENDOR_STRING] = self.text.vendorID + str(hiddAttributes.VendorID)
            else:
                device[VENDOR_STRING] = infoStr.value
 
            #getting device name
            result = hidDLL.HidD_GetProductString(
                int(hidHandle), byref(infoStr), ctypes.sizeof(infoStr))
        preparsedData = c_ulong()
        result = hidDLL.HidD_GetPreparsedData(
            int(handle),
            ctypes.byref(preparsedData)
        )
 
        #getCaps
        hidpCaps = HIDP_CAPS()
        result = hidDLL.HidP_GetCaps(preparsedData, ctypes.byref(hidpCaps))
 
        hidDLL.HidP_GetButtonCaps(
            rt,
            ctypes.byref(bCapsArr),
            ctypes.byref(bCapsArrL),
            preparsedData
        )
 
        hidDLL.HidP_GetValueCaps(
            rt,
            ctypes.byref(vCapsArr),
            ctypes.byref(vCapsArrL),
            preparsedData
        )
                    dataL = c_ulong(maxDataL)
                    result = hidDLL.HidP_GetData(
                        rt,
                        ctypes.byref(data),
                        ctypes.byref(dataL),
                        preparsedData,
                        ctypes.c_char_p(str(buf)),
        win32file.CloseHandle(handle)
 
        #free references
        hidDLL.HidD_FreePreparsedData(ctypes.byref(preparsedData))
 
        #HID thread finished
 

src/e/v/eventghost-HEAD/trunk/plugins/HID/__init__.py   eventghost(Download)
import wx.lib.mixins.listctrl as listmix
 
from ctypes import Structure, Union, c_byte, c_char, c_int, c_long, c_ulong, c_ushort, c_wchar
from ctypes import pointer, byref, sizeof, POINTER
from ctypes.wintypes import ULONG, BOOLEAN
 
class Text:
 
        #get guid for HID device class
        g = GUID()
        hidDLL.HidD_GetHidGuid(byref(g))
 
        #get handle to the device information set
        hinfo = setupapiDLL.SetupDiGetClassDevsA(byref(g), None, None,
            DIGCF_PRESENT + DIGCF_DEVICEINTERFACE)
 
        #enumerate devices
        i = 0
        while setupapiDLL.SetupDiEnumDeviceInterfaces(hinfo,
            None, byref(g), i, byref(interfaceInfo)):
            #get the required size
            requiredSize = c_ulong()
            setupapiDLL.SetupDiGetDeviceInterfaceDetailA(hinfo,
                byref(interfaceInfo), None, 0, byref(requiredSize), None)
            if requiredSize.value > 250:
                eg.PrintError(self.text.errorRetrieval)
                continue #prevent a buffer overflow
 
            #get the actual info
            setupapiDLL.SetupDiGetDeviceInterfaceDetailA(
                hinfo,
                byref(interfaceInfo),
                byref(interfaceDetailData),
                continue
 
            #getting additional info
            hidDLL.HidD_GetAttributes(int(hidHandle), byref(hiddAttributes))
            device[VENDOR_ID] = hiddAttributes.VendorID
            device[PRODUCT_ID] = hiddAttributes.ProductID
            device[VERSION_NUMBER] = hiddAttributes.VersionNumber
 
            #getting manufacturer
            result = hidDLL.HidD_GetManufacturerString(
                int(hidHandle), byref(infoStr), ctypes.sizeof(infoStr))
            if not result or len(infoStr.value) == 0:
                #build a generic ManufacturerString with the vendor ID
                device[VENDOR_STRING] = self.text.vendorID + str(hiddAttributes.VendorID)
            else:
                device[VENDOR_STRING] = infoStr.value
 
            #getting device name
            result = hidDLL.HidD_GetProductString(
                int(hidHandle), byref(infoStr), ctypes.sizeof(infoStr))
        preparsedData = c_ulong()
        result = hidDLL.HidD_GetPreparsedData(
            int(handle),
            ctypes.byref(preparsedData)
        )
 
        #getCaps
        hidpCaps = HIDP_CAPS()
        result = hidDLL.HidP_GetCaps(preparsedData, ctypes.byref(hidpCaps))
 
        hidDLL.HidP_GetButtonCaps(
            rt,
            ctypes.byref(bCapsArr),
            ctypes.byref(bCapsArrL),
            preparsedData
        )
 
        hidDLL.HidP_GetValueCaps(
            rt,
            ctypes.byref(vCapsArr),
            ctypes.byref(vCapsArrL),
            preparsedData
        )
                    dataL = c_ulong(maxDataL)
                    result = hidDLL.HidP_GetData(
                        rt,
                        ctypes.byref(data),
                        ctypes.byref(dataL),
                        preparsedData,
                        ctypes.c_char_p(str(buf)),
        win32file.CloseHandle(handle)
 
        #free references
        hidDLL.HidD_FreePreparsedData(ctypes.byref(preparsedData))
 
        #HID thread finished
 

src/e/v/eventghost-HEAD/plugins/PS3/__init__.py   eventghost(Download)
import wx.lib.mixins.listctrl as listmix
 
from ctypes import Structure, Union, c_byte, c_ubyte, c_char, c_int, c_long, c_ulong, c_ushort, c_wchar
from ctypes import pointer, byref, sizeof, POINTER
from ctypes.wintypes import ULONG, BOOLEAN, BOOL
 
class Ps3Remote:
    def read_link_mode(bd_addr):
        mode = c_ubyte(0)
        result = ReadLinkMode(bd_addr, byref(mode))
 
        if result:
            return mode.value
 
 
        #get guid for HID device class
        g = GUID()
        hidDLL.HidD_GetHidGuid(byref(g))
 
        #get handle to the device information set
        hinfo = setupapiDLL.SetupDiGetClassDevsA(byref(g), None, None,
            DIGCF_PRESENT + DIGCF_DEVICEINTERFACE)
 
        #enumerate devices
        i = 0
        while setupapiDLL.SetupDiEnumDeviceInterfaces(hinfo,
            None, byref(g), i, byref(interfaceInfo)):
            #get the required size
            requiredSize = c_ulong()
            setupapiDLL.SetupDiGetDeviceInterfaceDetailA(hinfo,
                byref(interfaceInfo), None, 0, byref(requiredSize), None)
            if requiredSize.value > 250:
                eg.PrintError(self.text.errorRetrieval)
                continue #prevent a buffer overflow
 
            #get the actual info
            setupapiDLL.SetupDiGetDeviceInterfaceDetailA(
                hinfo,
                byref(interfaceInfo),
                byref(interfaceDetailData),
                continue
 
            #getting additional info
            hidDLL.HidD_GetAttributes(int(hidHandle), byref(hiddAttributes))
            device[VENDOR_ID] = hiddAttributes.VendorID
            device[PRODUCT_ID] = hiddAttributes.ProductID
            device[VERSION_NUMBER] = hiddAttributes.VersionNumber
 
            #getting manufacturer
            result = hidDLL.HidD_GetManufacturerString(
                int(hidHandle), byref(infoStr), ctypes.sizeof(infoStr))
            if not result or len(infoStr.value) == 0:
                #build a generic ManufacturerString with the vendor ID
                device[VENDOR_STRING] = self.text.vendorID + str(hiddAttributes.VendorID)
            else:
                device[VENDOR_STRING] = infoStr.value
 
            #getting device name
            result = hidDLL.HidD_GetProductString(
                int(hidHandle), byref(infoStr), ctypes.sizeof(infoStr))
        preparsedData = c_ulong()
        result = hidDLL.HidD_GetPreparsedData(
            int(handle),
            ctypes.byref(preparsedData)
        )
 
        #getCaps
        hidpCaps = HIDP_CAPS()
        result = hidDLL.HidP_GetCaps(preparsedData, ctypes.byref(hidpCaps))
 
        hidDLL.HidP_GetButtonCaps(
            rt,
            ctypes.byref(bCapsArr),
            ctypes.byref(bCapsArrL),
            preparsedData
        )
 
        hidDLL.HidP_GetValueCaps(
            rt,
            ctypes.byref(vCapsArr),
            ctypes.byref(vCapsArrL),
            preparsedData
        )
                    dataL = c_ulong(maxDataL)
                    result = hidDLL.HidP_GetData(
                        rt,
                        ctypes.byref(data),
                        ctypes.byref(dataL),
                        preparsedData,
                        ctypes.c_char_p(str(buf)),
        win32file.CloseHandle(handle)
 
        #free references
        hidDLL.HidD_FreePreparsedData(ctypes.byref(preparsedData))
 
        #HID thread finished
 

src/e/v/eventghost-HEAD/trunk/plugins/XBCDRC/__init__.py   eventghost(Download)
import wx.lib.mixins.listctrl as listmix
 
from ctypes import Structure, Union, c_byte, c_char, c_int, c_long, c_ulong, c_ushort, c_wchar
from ctypes import pointer, byref, sizeof, POINTER
from ctypes.wintypes import ULONG, BOOLEAN
 
class Text:
 
        #get guid for HID device class
        g = GUID()
        hidDLL.HidD_GetHidGuid(byref(g))
 
        #get handle to the device information set
        hinfo = setupapiDLL.SetupDiGetClassDevsA(byref(g), None, None,
            DIGCF_PRESENT + DIGCF_DEVICEINTERFACE)
 
        #enumerate devices
        i = 0
        while setupapiDLL.SetupDiEnumDeviceInterfaces(hinfo,
            None, byref(g), i, byref(interfaceInfo)):
            #get the required size
            requiredSize = c_ulong()
            setupapiDLL.SetupDiGetDeviceInterfaceDetailA(hinfo,
                byref(interfaceInfo), None, 0, byref(requiredSize), None)
            if requiredSize.value > 250:
                eg.PrintError(self.text.errorRetrieval)
                continue #prevent a buffer overflow
 
            #get the actual info
            setupapiDLL.SetupDiGetDeviceInterfaceDetailA(
                hinfo,
                byref(interfaceInfo),
                byref(interfaceDetailData),
                continue
 
            #getting additional info
            hidDLL.HidD_GetAttributes(int(hidHandle), byref(hiddAttributes))
            device[VENDOR_ID] = hiddAttributes.VendorID
            device[PRODUCT_ID] = hiddAttributes.ProductID
            device[VERSION_NUMBER] = hiddAttributes.VersionNumber
 
            #getting manufacturer
            result = hidDLL.HidD_GetManufacturerString(
                int(hidHandle), byref(infoStr), ctypes.sizeof(infoStr))
            if not result or len(infoStr.value) == 0:
                #build a generic ManufacturerString with the vendor ID
                device[VENDOR_STRING] = self.text.vendorID + str(hiddAttributes.VendorID)
            else:
                device[VENDOR_STRING] = infoStr.value
 
            #getting device name
            result = hidDLL.HidD_GetProductString(
                int(hidHandle), byref(infoStr), ctypes.sizeof(infoStr))
        preparsedData = c_ulong()
        result = hidDLL.HidD_GetPreparsedData(
            int(handle),
            ctypes.byref(preparsedData)
        )
 
        #getCaps
        hidpCaps = HIDP_CAPS()
        result = hidDLL.HidP_GetCaps(preparsedData, ctypes.byref(hidpCaps))
 
        hidDLL.HidP_GetButtonCaps(
            rt,
            ctypes.byref(bCapsArr),
            ctypes.byref(bCapsArrL),
            preparsedData
        )
 
        hidDLL.HidP_GetValueCaps(
            rt,
            ctypes.byref(vCapsArr),
            ctypes.byref(vCapsArrL),
            preparsedData
        )
        win32file.CloseHandle(handle)
 
        #free references
        hidDLL.HidD_FreePreparsedData(ctypes.byref(preparsedData))
 
        #HID thread finished
 

src/e/v/eventghost-HEAD/plugins/HID/__init__.py   eventghost(Download)
import wx.lib.mixins.listctrl as listmix
 
from ctypes import Structure, Union, c_byte, c_char, c_int, c_long, c_ulong, c_ushort, c_wchar
from ctypes import pointer, byref, sizeof, POINTER
from ctypes.wintypes import ULONG, BOOLEAN
 
class Text:
 
        #get guid for HID device class
        g = GUID()
        hidDLL.HidD_GetHidGuid(byref(g))
 
        #get handle to the device information set
        hinfo = setupapiDLL.SetupDiGetClassDevsA(byref(g), None, None,
            DIGCF_PRESENT + DIGCF_DEVICEINTERFACE)
 
        #enumerate devices
        i = 0
        while setupapiDLL.SetupDiEnumDeviceInterfaces(hinfo,
            None, byref(g), i, byref(interfaceInfo)):
            #get the required size
            requiredSize = c_ulong()
            setupapiDLL.SetupDiGetDeviceInterfaceDetailA(hinfo,
                byref(interfaceInfo), None, 0, byref(requiredSize), None)
            if requiredSize.value > 250:
                eg.PrintError(self.text.errorRetrieval)
                continue #prevent a buffer overflow
 
            #get the actual info
            setupapiDLL.SetupDiGetDeviceInterfaceDetailA(
                hinfo,
                byref(interfaceInfo),
                byref(interfaceDetailData),
                continue
 
            #getting additional info
            hidDLL.HidD_GetAttributes(int(hidHandle), byref(hiddAttributes))
            device[VENDOR_ID] = hiddAttributes.VendorID
            device[PRODUCT_ID] = hiddAttributes.ProductID
            device[VERSION_NUMBER] = hiddAttributes.VersionNumber
 
            #getting manufacturer
            result = hidDLL.HidD_GetManufacturerString(
                int(hidHandle), byref(infoStr), ctypes.sizeof(infoStr))
            if not result or len(infoStr.value) == 0:
                #build a generic ManufacturerString with the vendor ID
                device[VENDOR_STRING] = self.text.vendorID + str(hiddAttributes.VendorID)
            else:
                device[VENDOR_STRING] = infoStr.value
 
            #getting device name
            result = hidDLL.HidD_GetProductString(
                int(hidHandle), byref(infoStr), ctypes.sizeof(infoStr))
        preparsedData = c_ulong()
        result = hidDLL.HidD_GetPreparsedData(
            int(handle),
            ctypes.byref(preparsedData)
        )
 
        #getCaps
        hidpCaps = HIDP_CAPS()
        result = hidDLL.HidP_GetCaps(preparsedData, ctypes.byref(hidpCaps))
 
        hidDLL.HidP_GetButtonCaps(
            rt,
            ctypes.byref(bCapsArr),
            ctypes.byref(bCapsArrL),
            preparsedData
        )
 
        hidDLL.HidP_GetValueCaps(
            rt,
            ctypes.byref(vCapsArr),
            ctypes.byref(vCapsArrL),
            preparsedData
        )
                    dataL = c_ulong(maxDataL)
                    result = hidDLL.HidP_GetData(
                        rt,
                        ctypes.byref(data),
                        ctypes.byref(dataL),
                        preparsedData,
                        ctypes.c_char_p(str(buf)),
        win32file.CloseHandle(handle)
 
        #free references
        hidDLL.HidD_FreePreparsedData(ctypes.byref(preparsedData))
 
        #HID thread finished
 

src/e/v/eventghost-HEAD/plugins/XBCDRC/__init__.py   eventghost(Download)
import wx.lib.mixins.listctrl as listmix
 
from ctypes import Structure, Union, c_byte, c_char, c_int, c_long, c_ulong, c_ushort, c_wchar
from ctypes import pointer, byref, sizeof, POINTER
from ctypes.wintypes import ULONG, BOOLEAN
 
class Text:
 
        #get guid for HID device class
        g = GUID()
        hidDLL.HidD_GetHidGuid(byref(g))
 
        #get handle to the device information set
        hinfo = setupapiDLL.SetupDiGetClassDevsA(byref(g), None, None,
            DIGCF_PRESENT + DIGCF_DEVICEINTERFACE)
 
        #enumerate devices
        i = 0
        while setupapiDLL.SetupDiEnumDeviceInterfaces(hinfo,
            None, byref(g), i, byref(interfaceInfo)):
            #get the required size
            requiredSize = c_ulong()
            setupapiDLL.SetupDiGetDeviceInterfaceDetailA(hinfo,
                byref(interfaceInfo), None, 0, byref(requiredSize), None)
            if requiredSize.value > 250:
                eg.PrintError(self.text.errorRetrieval)
                continue #prevent a buffer overflow
 
            #get the actual info
            setupapiDLL.SetupDiGetDeviceInterfaceDetailA(
                hinfo,
                byref(interfaceInfo),
                byref(interfaceDetailData),
                continue
 
            #getting additional info
            hidDLL.HidD_GetAttributes(int(hidHandle), byref(hiddAttributes))
            device[VENDOR_ID] = hiddAttributes.VendorID
            device[PRODUCT_ID] = hiddAttributes.ProductID
            device[VERSION_NUMBER] = hiddAttributes.VersionNumber
 
            #getting manufacturer
            result = hidDLL.HidD_GetManufacturerString(
                int(hidHandle), byref(infoStr), ctypes.sizeof(infoStr))
            if not result or len(infoStr.value) == 0:
                #build a generic ManufacturerString with the vendor ID
                device[VENDOR_STRING] = self.text.vendorID + str(hiddAttributes.VendorID)
            else:
                device[VENDOR_STRING] = infoStr.value
 
            #getting device name
            result = hidDLL.HidD_GetProductString(
                int(hidHandle), byref(infoStr), ctypes.sizeof(infoStr))
        preparsedData = c_ulong()
        result = hidDLL.HidD_GetPreparsedData(
            int(handle),
            ctypes.byref(preparsedData)
        )
 
        #getCaps
        hidpCaps = HIDP_CAPS()
        result = hidDLL.HidP_GetCaps(preparsedData, ctypes.byref(hidpCaps))
 
        hidDLL.HidP_GetButtonCaps(
            rt,
            ctypes.byref(bCapsArr),
            ctypes.byref(bCapsArrL),
            preparsedData
        )
 
        hidDLL.HidP_GetValueCaps(
            rt,
            ctypes.byref(vCapsArr),
            ctypes.byref(vCapsArrL),
            preparsedData
        )
        win32file.CloseHandle(handle)
 
        #free references
        hidDLL.HidD_FreePreparsedData(ctypes.byref(preparsedData))
 
        #HID thread finished
 

src/p/y/pywinusb-0.2.4/pywinusb/hid/core.py   pywinusb(Download)
import threading
import time
 
from ctypes import c_ubyte, c_ulong, c_ushort, c_wchar, byref, sizeof
 
#local modules
from winapi import *
def hid_device_path_exists(device_path, hid_guid = GetHidGuid()):
    """Test if required device_path is still valid (HID device connected 
    to host)"""
    # get HID device class guid
 
    # handle to an opaque device information set
    h_info = SetupDiGetClassDevs(byref(hid_guid), None, None, (DIGCF_PRESENT \
        dev_index = 0
        required_size = c_ulong()
        while setup_api.SetupDiEnumDeviceInterfaces(h_info, None, 
                byref(hid_guid), dev_index, byref(device_interface)):
            dev_index += 1
 
            # validate if hid path would fit
            required_size.value = 0
            SetupDiGetDeviceInterfaceDetail(h_info, byref(device_interface), 
                None, 0, byref(required_size), None)
                continue
 
            # it's ok to get the details
            SetupDiGetDeviceInterfaceDetail(h_info, byref(device_interface), 
                    byref(dev_inter_detail_data), required_size, None, None)
 
            if dev_inter_detail_data.device_path == device_path:
    hid_guid = GetHidGuid()
 
    # handle to an opaque device information set
    h_info = SetupDiGetClassDevs(byref(hid_guid), None, None, 
            (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE) )
 
    if h_info == INVALID_HANDLE_VALUE:
        parent_device = c_ulong()
        results = []
        while setup_api.SetupDiEnumDeviceInterfaces(h_info, None, 
                byref(hid_guid), i, byref(dev_interface_data) ):
            i += 1
 
            # validate if hid path would fit
            required_size.value = 0
            SetupDiGetDeviceInterfaceDetail(h_info, byref(dev_interface_data), 
                    None, 0, byref(required_size), None)
                continue
 
            # it's ok to get the details
            SetupDiGetDeviceInterfaceDetail(h_info, byref(dev_interface_data), 
                    byref(dev_inter_detail_data), required_size, None, 
                    byref(dev_info_data))
 
            #get parent instance id (so we can discriminate on port)
            if setup_api.CM_Get_Parent(byref(parent_device), 
 
            #get unique instance id str
            required_size.value = 0
            SetupDiGetDeviceInstanceId(h_info, byref(dev_info_data), None, 
                0, byref(required_size) )
            if required_size.value > 0:
                device_instance_id_type = c_tchar * required_size.value
                deviceinstance_id = device_instance_id_type()
                SetupDiGetDeviceInstanceId(h_info, byref(dev_info_data), 
                        byref(deviceinstance_id), required_size, 
                        byref(required_size) )
    def get_parent_device(self):
        if not self.parent_instance_id:
            return ""
        dev_buffer_type = c_tchar * MAX_DEVICE_ID_LEN
        dev_buffer = dev_buffer_type()
        if CM_Get_Device_ID(self.parent_instance_id, byref(dev_buffer), 
                MAX_DEVICE_ID_LEN, 0) == 0: #success
            hidd_attributes = HIDD_ATTRIBUTES()
            hidd_attributes.cb_size = sizeof(hidd_attributes)
            if not hid_dll.HidD_GetAttributes(int(h_hid), 
                    byref(hidd_attributes) ):
                return #can't read attributes
 
            #set local references
            vendor_string_type = c_wchar * self.MAX_MANUFACTURER_STRING_LEN
            vendor_name = vendor_string_type()
            if not hid_dll.HidD_GetManufacturerString(int(h_hid), 
                    byref(vendor_name), 
                    sizeof(vendor_name)) or not len(vendor_name.value):
                # would be any possibility to get a vendor id table?, 
                # maybe not worth it
            product_name_type = c_wchar * self.MAX_PRODUCT_STRING_LEN
            product_name = product_name_type()
            if not hid_dll.HidD_GetProductString(int(h_hid), 
                        byref(product_name), 
                        sizeof(product_name)) or not len(product_name.value):
                # alternate methode, refer to windows registry for product 
                # information
        #get preparsed data
        ptr_preparsed_data = c_ulong()
        if not hid_dll.HidD_GetPreparsedData(int(hid_handle), 
                byref(ptr_preparsed_data)):
            self.close()
            raise HIDError("Failure to get HID preparsed data")
        self.ptr_preparsed_data = ptr_preparsed_data
 
        #get top level capabilities
        hid_caps = HIDP_CAPS()
        HidStatus( hid_dll.HidP_GetCaps(ptr_preparsed_data, byref(hid_caps)) )
            caps_length.value = max_items
            HidStatus( get_control_caps(\
                report_kind,
                byref(ctrl_array),
                byref(caps_length),
                ptr_preparsed_data) )
            #keep reference of usages
        over_write.h_event = CreateEvent(None, 0, 0, None)
        if over_write.h_event:
            overlapped_write = over_write
            WriteFile(int(self.hid_handle), byref(raw_data), len(raw_data),
                None, byref(overlapped_write)) #none overlaped
            result = WaitForSingleObject(overlapped_write.h_event, 10000 )
            CloseHandle(overlapped_write.h_event)
            if result != WAIT_OBJECT_0: #success
                return False #device has being disconnected
        else:
            return WriteFile(int(self.hid_handle), byref(raw_data), 
        else:
            raw_data = data
 
        return hid_dll.HidD_SetFeature(int(self.hid_handle), byref(raw_data),
                len(raw_data))
 
    def __reset_vars(self):
                if self.__abort:
                    break
                result = ReadFile(int(hid_object.hid_handle), 
                    byref(buf_report), int(n), byref(bytes_read), 
                    byref(self.__overlapped_read_obj) )
                if not result:
                    error = ctypes.GetLastError()
            abuffer = usage_string_type()
            hid_dll.HidD_GetIndexedString(self.hid_report.get_hid_object().hid_handle, 
                self.string_index,
                byref(abuffer), MAX_HID_STRING_LENGTH-1 )
            return abuffer.value
        return ""
 
                item.value = 0
        #ready, parse raw data
        HidStatus( hid_dll.HidP_GetData(self.__report_kind, 
            byref(data_list), byref(data_len), 
            self.__hid_object.ptr_preparsed_data,
            byref(self.__raw_data), len(self.__raw_data)) )
 
                item.page_id,
                0, #link collection
                item.usage_id, #short usage
                byref(item.value_array), #output data (c_ubyte storage)
                len(item.value_array), self.__hid_object.ptr_preparsed_data, 
                byref(self.__raw_data), len(self.__raw_data)) )
            #
        try:
            HidStatus( hid_dll.HidP_InitializeReportForID(self.__report_kind,
                self.__report_id, self.__hid_object.ptr_preparsed_data,
                byref(self.__raw_data), self.__raw_report_size) )
            #
        except HIDError:
            self.__raw_data[0] = self.__report_id
                    single_usage_len.value = 1
                    HidStatus( hid_dll.HidP_SetUsages(self.__report_kind, 
                        report_item.page_id, 0,
                        byref(single_usage), byref(single_usage_len), 
                        self.__hid_object.ptr_preparsed_data,
                        byref(self.__raw_data), self.__raw_report_size) )
                    continue
            #some usages set
            usage_len = c_ulong(n_total_usages)
            HidStatus( hid_dll.HidP_SetData(self.__report_kind, 
                byref(data_list), byref(usage_len), 
                self.__hid_object.ptr_preparsed_data,
                byref(self.__raw_data), self.__raw_report_size) )
        #set values based on value arrays
        for report_item in self.__value_array_items:
            HidStatus( hid_dll.HidP_SetUsageValueArray(self.__report_kind, 
                report_item.page_id,
                0, #all link collections
                report_item.usage_id,
                byref(report_item.value_array),
                report_item.usage_id,
                byref(report_item.value_array),
                len(report_item.value_array),
                self.__hid_object.ptr_preparsed_data, byref(self.__raw_data), 
                len(self.__raw_data)) )
 
    def get_raw_data(self):
            read_function = hid_dll.HidD_GetInputReport
        if read_function and read_function( \
                int(self.__hid_object.hid_handle),
                byref(raw_data), len(raw_data) ):
            #success
            if do_process_raw_report:
                self.__hid_object._process_raw_report(raw_data)

src/g/e/gefira-HEAD/trunk/mq/code/python/gefira/mq/ai.py   gefira(Download)
"""
 
import warnings
from ctypes import c_long, byref, create_string_buffer, POINTER, c_int
 
from gefira.mq.common import lib, MQException, Connection, TREAT_WARNINGS_AS_ERRORS
from gefira.mq.cmqc import (MQCA_Q_NAME, MQHO_NONE, MQIA_CURRENT_Q_DEPTH, 
 
            with MQAICall("mqInquireBag") as (cc, rc):
                lib.mqInquireBag(self.response_bag, MQHA_BAG_HANDLE, 0, 
                                    byref(error_bag), byref(cc), 
                                    byref(rc))
 
            integer = c_int()
            with MQAICall("mqInquireInteger") as (cc, rc):
                # Get the completion and reason code
                lib.mqInquireInteger(error_bag, MQIASY_COMP_CODE, MQIND_NONE, 
                                        byref(integer), byref(cc), 
                                        byref(rc))
            integer = c_int()
            with MQAICall("mqInquireInteger") as (cc, rc):
                lib.mqInquireInteger(error_bag, MQIASY_REASON, MQIND_NONE, 
                                        byref(integer), byref(cc), 
                                        byref(rc))
                nested_rc = integer
 
        attrs_bag = c_long(MQHB_UNUSABLE_HBAG)
 
        with MQAICall("mqCreateBag") as (cc, rc):
            lib.mqCreateBag(MQCBO_ADMIN_BAG, byref(admin_bag), byref(cc), 
                byref(rc))
        with MQAICall("mqCreateBag") as (cc, rc):
            lib.mqCreateBag(MQCBO_ADMIN_BAG, byref(response_bag), byref(cc), 
                 byref(rc))
 
        if timeout:
            options_bag = c_long(MQHB_UNUSABLE_HBAG)
            with MQAICall("mqCreateBag") as (cc, rc):
                lib.mqCreateBag(MQCBO_ADMIN_BAG, byref(options_bag), byref(cc), 
                    byref(rc))
                    byref(rc))
            with MQAICall("mqAddInteger") as (cc, rc):
                lib.mqAddInteger(options_bag, MQIACF_WAIT_INTERVAL, timeout, 
                    byref(cc), byref(rc))
        else:
            options_bag = MQHB_NONE
 
        for param, value in filter.items():
 
            # MQCA_* - character attribute
            if param >= MQCA_FIRST and param <= MQCA_LAST:
                with MQAICall("mqAddString") as (cc, rc):
                    lib.mqAddString(admin_bag, param, MQBL_NULL_TERMINATED, value, byref(cc), byref(rc))
            # MQCA_* - integer attribute
            elif param >= MQIA_FIRST and param <= MQIA_LAST:
                with MQAICall("mqAddInteger") as (cc, rc):
                    lib.mqAddInteger(admin_bag, param, value, byref(cc), byref(rc))
 
        # Narrow the range of attributes to be returned
        for attr in query:
            with MQAICall("mqAddInquiry") as (cc, rc):
                lib.mqAddInquiry(admin_bag, attr, byref(cc), byref(rc))
        # TODO: Admin/response queues
        with _MQAIExecute("mqExecute", response_bag) as (cc, rc):
            lib.mqExecute(self.conn.hconn, command, options_bag, admin_bag, 
                            response_bag, MQHO_NONE, MQHO_NONE, byref(cc), 
                            byref(rc))
 
        number_of_bags = c_long()
        with MQAICall("mqCountItems") as (cc,rc):
            lib.mqCountItems(response_bag, MQHA_BAG_HANDLE, 
                                byref(number_of_bags), byref(cc), byref(rc))
 
            with MQAICall("mqInquireBag") as (cc,rc):
                lib.mqInquireBag(response_bag, MQHA_BAG_HANDLE, bag_number, 
                                    byref(attrs_bag), byref(cc), byref(rc))
            for attr in query:
 
                # MQCA_* - character attribute
                    # and we explicitly ignore that warning.
                    with MQAICall("mqInquireString", [MQRC_STRING_TRUNCATED]) as (cc,rc):
                        lib.mqInquireString(attrs_bag, attr, MQIND_NONE, 0, null,
                            byref(string_length), null, byref(cc), byref(rc))
 
                    # Now get the string itself
                    if string_length.value != 0:
                        string = create_string_buffer(string_length.value)
                        with MQAICall("mqInquireString") as (cc,rc):
                            lib.mqInquireString(attrs_bag, attr, MQIND_NONE, string_length, 
                                byref(string), byref(string_length), null, 
                                byref(cc), byref(rc))
 
                    with MQAICall("mqInquireInteger") as (cc,rc):
                        lib.mqInquireInteger(attrs_bag, attr, MQIND_NONE, 
                            byref(integer), byref(cc), byref(rc))
 
                    attr_bag.append(integer.value)
 

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next