D3DKMTOpenAdapterFromDeviceName and DeviceName - c

I'm looking for the way to communicate with display driver, and found this function, its a bit poorly documented in msdn. I need to use this, because it will return me the handle which later i can use to display the gpu load in my application. But there is a problem, what i did is i looked in my Device Manager, and copied the value of the "the path to the device instance" in my gpu properties. it looks like so:
PCI\VEN_1002&DEV_6798&SUBSYS_04481043&REV_00\4&72ACCB3&0&0008
Here is the example of D3DKMTOpenAdapterFromDeviceName which i found:
D3DKMT_OPENADAPTERFROMDEVICENAME name = { _T("\\\\?\\pci#ven_10de&dev_0a2b&subsys_9072104d&rev_a2#4&12796cb&0&0008#{1ca05180-a699-450a-9a0c-de4fbe3ddd89}") };
HMODULE hGdi32 = LoadLibrary(_T("gdi32.dll"));
PD3DKMTOpenAdapterFromDeviceName D3DKMTOpenAdapterFromDeviceName = (PD3DKMTOpenAdapterFromDeviceName)GetProcAddress(hGdi32, "D3DKMTOpenAdapterFromDeviceName");
NTSTATUS status = D3DKMTOpenAdapterFromDeviceName(&name);
In this example they have some GUID at the end of the device #{1ca05180-a699-450a-9a0c-de4fbe3ddd89}. So which GUID from the device manager properties of my GPU i should use? I tried to use like half of the GUIDS from my VideoCard properties in Device Manager and always get - "STATUS_INVALID_PARAMETER"

{1ca05180-a699-450a-9a0c-de4fbe3ddd89} is the identifier of GUID_DISPLAY_DEVICE_ARRIVAL
So you can compose your name like:
"\\\\?\\" + deviceName + "#{1ca05180-a699-450a-9a0c-de4fbe3ddd89}"
replacing your "\" for #; example with yours:
"\\\\?\\" + "PCI#VEN_1002&DEV_6798&SUBSYS_04481043&REV_00#4&72ACCB3&0&0008"+"#{1ca05180-a699-450a-9a0c-de4fbe3ddd89}"
And then to find this programatically you can do a COM search like this:
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_VideoController"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
And taking PNPDeviceID which is the string you've found at your Device Manager; take in account of being sure it's your currently in use graphic card, as it's possible to have more than one.

Related

how to loop over multiple registers in linux device tree node?

I implemented a generic driver, in the driver I just want to go over each registered device and do something.
my driver is generic so I don't want to know anything in advance about the devices.
I have some device tree nodes:
uart0: uart#1000000 {
compatible = "generic-driver";
reg = <0x1000000 0x1000>,<0x1001000 0x1000>,<0x1002000 0x1000>;
};
uart1: uart#2000000 {
compatible = "generic-driver";
reg = <0x2000000 0x1000>,<0x2001000 0x1000>,<0x2002000 0x1000>;
};
in the driver I know how to get first offset and size with platform_get_resource, but what if I have multiple ranges?
I saw an option to get it by add reg-names:
reg = <0x2000000 0x1000>,<0x2001000 0x1000>,<0x2002000 0x1000>;
reg-names = "uart0_0","urat0_1","uart0_2";
so in the driver I can use platform_get_resource_byname, but there I need to know in the driver the regs names in advance - but it'll be no more generic - unwanted!!
so my question is, is there a way to loop over these regs without early information in the driver?
Thanks in advance!!
If you go through the definition for platform_get_resource you will find that the last parameter is the resource number. So, for the example you gave resource numbers will range from 0 to 2.
In case you don't know the number of resource then you can run an loop till you get a NULL as response to platform_get_resource.

Could not find the reference to GUID_DEVINTERFACE_NET class

I am using MS VS2008 to build my application. I need to use "GUID_DEVINTERFACE_NET " class to get the device interface list. But i could not find the reference to this class. I have even tried in MS VS2015 but could not the reference.
Below is the code snippet.
ULONG DeviceListLength = 0;
cr = CM_Get_Device_Interface_List_SizeW(&DeviceListLength,
(LPGUID)&GUID_DEVINTERFACE_NET,
NULL,
CM_GET_DEVICE_INTERFACE_LIST_PRESENT);
The Microsoft online documentation is not very detailed, but it does mention the header file Ndisguid.h. The filename might use a different case, but the Windows file system is not case-sensitive anyway:
#include <ndisguid.h>
references:
https://msdn.microsoft.com/en-us/library/windows/hardware/ff545922(v=vs.85).aspx
https://msdn.microsoft.com/en-us/library/windows/hardware/ff538471(v=vs.85).aspx

How can i achieve dictionary type data access in Chromium embedded CEF1

I would like to achieve dictionary like data pattern that can be accessed from the
java script. Something like this:
pseudo Code:
for all records:
{
rec = //Get the Record
rec["Name"]
rec["Address"]
}
I am trying to achieve with CefV8Accessor, but i am not getting near to the solution.
Kindly provide few links for the reference, as i see the documentation is very less from chromium embedded.
If I understand correctly, you're trying to create a JS "dictionary" object for CEF using C++. If so, here's a code snippet that does that:
CefRefPtr<CefV8Value> GetDictionary(__in const wstring& sName, __in const wstring& sAddress)
{
CefRefPtr<CefV8Value> objectJS = CefV8Value::CreateObject(NULL);
objectJS->SetValue(L"Name", sName, V8_PROPERTY_ATTRIBUTE_NONE);
objectJS->SetValue(L"Address", sAddress, V8_PROPERTY_ATTRIBUTE_NONE);
return objectJS;
}
The CefV8Accessor can also be used for that matter, but that's only if you want specific control over the set & get methods, to create a new type of object.
In that case you should create a class that inherits CefV8Accessor, implement the Set and Get methods (in a similar way to what appears in the code above), and pass it to the CreateObject method. The return value would be an instance of that new type of object.
I strongly suggest to browse through this link, if you haven't already.

Play Scala: How to access multiple databases with anorm and Magic[T]

I want to access two databases in Play Scala with anorm and Magic[T], (one is H2 and another is PostgreSQL). I just don't know how to config it...
I noticed that we can set another database connection in conf/application.conf
db_other.url=jdbc:mysql://localhost/test
db_other.driver=com.mysql.jdbc.Driver
db_other.user=root
db_other.pass=
However, how can I use it with Magic?
(I read the source code of Magic but don't understand it... my am a freshman of Scala)
Anyhow, if multiple database access is impossible with Magic[T] , I wish to do it with anorm, then how can I config it?
var sqlQuery = SQL( //I guess some config params should be set here, but how?
"""
select * from Country
"""
)
In play.api.db.DB it appears you can pass in a string of the name you defined in application.conf.
Then use one of the methods specified here: http://www.playframework.org/documentation/2.0/ScalaDatabase
# play.api.db.DB.class
def withConnection[A](name : scala.Predef.String)(block : scala.Function1[java.sql.Connection, A])(implicit app : play.api.Application) : A = { /* compiled code */ }

How to find which device is attached to a USB-serial port in Linux using C?

We are making a device and it has 8 serial ports. It runs on the Monta Vista Pro5 kernel. And we are working in C.
Suppose: A device gets attached to ttyUSB0, ttyUSB1 and ttyUSB2. The next device gets connected to ttyUSB3 and another to ttyUSB4. How can I know which device gets attached to which port ?? ie ttyUSB0 or ttyUSB1 or so on. Is there a way to directly query the device and find which port it is attached to. Or, in C, open ttyUSB0, query it somehow and get some reply as to which device it is ??
A rather complicated way: do a stat of, say /dev/ttyUSB0. Get the device number. And search for this in /proc/bus/usb/devices and find the vendor id or something to identify the device.
Or: Is there some way to reserve ttyUSB0,ttyUSB1 and ttyUSB2 for one device, ttyUSB3 for another and so on when they are plugged in ? This way I will know which device is connected to which port.
Help please..... :)
Thanks in advance.
Nubin Stanley
You can use udev rules to create symbolic links just to your device:
(these rules go in /etc/udev/rules.d/-name.rules -- look at your udev documentation
KERNEL=="ttyUSB*", ATTRS{idVendor}=="<vendorid>", MODE="0666", SYMLINK+="mydev"
You have to specify your vendor id and/or product id for your device. Then those devices will be available at /dev/mydev in the above example.
You can also use various other parameters to create appropriate unique symbolic links for your use. Check udev man page.
Here's my code, based on Alex Robinson's, but without global "except":
import os
from os.path import join
def find_tty_usb(idVendor, idProduct):
"""find_tty_usb('067b', '2302') -> '/dev/ttyUSB0'"""
# Note: if searching for a lot of pairs, it would be much faster to search
# for the enitre lot at once instead of going over all the usb devices
# each time.
for dnbase in os.listdir('/sys/bus/usb/devices'):
dn = join('/sys/bus/usb/devices', dnbase)
if not os.path.exists(join(dn, 'idVendor')):
continue
idv = open(join(dn, 'idVendor')).read().strip()
if idv != idVendor:
continue
idp = open(join(dn, 'idProduct')).read().strip()
if idp != idProduct:
continue
for subdir in os.listdir(dn):
if subdir.startswith(dnbase+':'):
for subsubdir in os.listdir(join(dn, subdir)):
if subsubdir.startswith('ttyUSB'):
return join('/dev', subsubdir)
This Python code seems to find the /dev/ttyUSB number for the given vendor ID and product ID. Not hard to translate it to C. Parsing the output from hwinfo --usb can do the trick, too. The regx is:
"\s\sVendor:\susb\s0x([0-9a-f]{4}).*?\s\sDevice:\susb\s0x([0-9a-f]{4}).*?\s\sDevice\sFile:\s/dev/ttyUSB([0-9]+)"
import glob
import os
import re
def find_usb_tty(vendor_id = None, product_id = None) :
tty_devs = []
for dn in glob.glob('/sys/bus/usb/devices/*') :
try :
vid = int(open(os.path.join(dn, "idVendor" )).read().strip(), 16)
pid = int(open(os.path.join(dn, "idProduct")).read().strip(), 16)
if ((vendor_id is None) or (vid == vendor_id)) and ((product_id is None) or (pid == product_id)) :
dns = glob.glob(os.path.join(dn, os.path.basename(dn) + "*"))
for sdn in dns :
for fn in glob.glob(os.path.join(sdn, "*")) :
if re.search(r"\/ttyUSB[0-9]+$", fn) :
#tty_devs.append("/dev" + os.path.basename(fn))
tty_devs.append(os.path.join("/dev", os.path.basename(fn)))
pass
pass
pass
pass
except ( ValueError, TypeError, AttributeError, OSError, IOError ) :
pass
pass
return tty_devs
print find_usb_tty()
The best way to do this is would be to use libusb, but if that doesn't give you enough information about your devices (which it may not), then you'll have to use the /proc filesystem which the kernel makes available, specifically /proc/bus/usb/.
Have a read of this information on /proc/bus/usb: in particular on /proc/bus/usb/devices. But as you say, this is all a bit hacky!

Resources