win32_USBDevice is missging from Win32 Classes - c#-4.0

I am trying to retrieve PID and VID of a connected USB device. Starting with this line of C# code:
System.Management.ManagementClass USBClass = new ManagementClass("Win32_USBDevice");
Then I got exception "ManagementException not found", Later I run into this link:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394084(v=vs.85).aspx
It turned out Win32_USBDevice was not on the list at all. Tried Win32_USBController but didn't get what I wanted. Could anyone let me know if there is any substitute class on the list to extract PID and VID of a connected USB device?
Thanks in advance!

Try this:
System.Management.ManagementClass USBClass = new ManagementClass("Win32_USBHub");

Use Win32_PnPEntity. You can get the both the PID and VID of connected USB devices from Win32_PnPEntity by parsing the "PNPDeviceID".
Start with this example: Get List of connected USB Devices

Related

libusb node usb get device instance path

Using Device Manager in windows on a USB device I get this in the device instance path property:
USB\VID_0403&PID_E868\02302692
I'm trying to get this info from the Node USB library which is based on libusb. When I query I get these values:
idVendor: 1027,
idProduct: 59496,
bcdDevice: 1536,
iSerialNumber: 3,
Which when converted are those values in the device manager.
//E868 = 59496
//1027 = 403
//1536 = 600
HOWEVER, I can't seem to find the \02302692. When I run lsusb -v that value is also not there.
Where is Windows getting the \02302692. If using libusb what is the property that retrieves that value? I thought it was the iSerialNumber??
To get what I have I'm calling
var lxdevice = usb.findByIds(1027, 59496);
console.log(lxdevice.deviceDescriptor);
in the node usb library. https://github.com/tessel/node-usb

Bluetoothctl or gatttool for BLE notifications from multiple devices

I have read many questions on the topic but found no information on how to best (or if it is even possible) to receive notifications from more than 1 device at a time using any library or API (preferably command line or Python library).
After connecting to different devices e.g. Heart Rate monitor and Phone, or two HR monitors, is there a way to receive data from 1 service from each device at the same time?
EDIT:
I have managed to connect different devices of the same characteristics and been able to get notifications from them using Bluetoothctl (part of Bluez) so long as I don't request the same service, which answers my question partially; still, does anyone know of a better way to do this?
1) First of all there is a github python project that does just that in Linux on Raspberry Pi: https://github.com/IanHarvey/bluepy
2) Second this snipet from Anthony Chiu uses that API to communicate with multiple devices using notifications:
from bluepy.btle import Scanner, DefaultDelegate, Peripheral
import threading
class NotificationDelegate(DefaultDelegate):
def __init__(self, number):
DefaultDelegate.__init__(self)
self.number = number
def handleNotification(self, cHandle, data):
print 'Notification:\nConnection:'+str(self.number)+ \nHandler:'+str(cHandle)+'\nMsg:'+data
bt_addrs = ['00:15:83:00:45:98', '00:15:83:00:86:72']
connections = []
connection_threads = []
scanner = Scanner(0)
class ConnectionHandlerThread (threading.Thread):
def __init__(self, connection_index):
threading.Thread.__init__(self)
self.connection_index = connection_index
def run(self):
connection = connections[self.connection_index]
connection.setDelegate(NotificationDelegate(self.connection_index))
while True:
if connection.waitForNotifications(1):
connection.writeCharacteristic(37, 'Thank you for the notification!')
while True:
print'Connected: '+str(len(connection_threads))
print 'Scanning...'
devices = scanner.scan(2)
for d in devices:
print(d.addr)
if d.addr in bt_addrs:
p = Peripheral(d)
connections.append(p)
t = ConnectionHandlerThread(len(connections)-1)
t.start()
connection_threads.append(t)
3) I will just write the manual connection option with bluetoothctl that you probably tried. Since it wasn't listed here, I will add that too:
**Manual connection with bluetoothctl: ** To get the list of characteristics you can use the “list-attributes” command after establing connection and entering Generic Attribute Submenu through menu gatt in bluetoothctl, which should print the same list as above:
list-attributes 00:61:61:15:8D:60
To read an attribute you first select it, with the -you guessed it- “select-attribute” command:
select-attribute /org/bluez/hci0/dev_00_61_61_15_8D_60/service000a/char000b
After that you can issue the “read” command, without any parameters.
To read a characteristic continuously (if characteristic supports it) , use the “notify” command:
notify on
PS: This is my first answer on stackoverflow :)
I am also new to BLE, so bear with me. Am interested in your project, any links / contact are appreciated :)
You can find me on alexandrudancu.com

Get /dev path of USB device from VID and PID in node.js

I'm writing a node.js JavaScript app to run on a Mac (macOS server) that will communicate with USB devices that are plugged in. The library I need to use to interact with the device takes a path in the form /dev/pathToDevice - e.g. lib.connect('/dev/pathToDevice'); - whereas the only way I have to identify the USB device from within my code is by the vendorId (VID) and productId (PID) obtained via the usb-detection library from NPM on insertion.
How can I, in JavaScript, identify or derive the path to the device from the VID and PID of the inserted USB device, so I can pass that to the library?
You could write a small C++ program that uses libusbp_generic_interface_get_os_filename function from libusbp. You would then call the C program from node.js. Let me know if you need help writing the C++ program. I would probably start with the port_name example form libusbp's source tree.
Or, you could use the lsusb example from libusbp as is. It returns a path like /sys/devices/pci0000:00/0000:00:06.0/usb1/1-1 for each device. That is a directory with a bunch of special files; one of them is busnum and one of them is devnum, which are the two numbers you need to construct a path like /dev/bus/usb/DEVNUM/BUSNUM.
If that works, you might prefer to write a binding for libusbp from node.js instead of using a C executable.
Try drivelist , It gives you the mountpaths and its cross platform and you can combine this with usb-detection easily.
var drivelist = require("drivelist")
drivelist.list((error, devices)=> { console.log(devices) })
//Output
[ {
//stuff...
device: '/dev/disk0',
raw: '/dev/rdisk0',
mountpoints: [
{"path":"/","label":"Macintosh HD"},
{"path":"/private/var/vm","label":"VM"}
],
isRemovable: false,
//stuff....
]

JavaME RaspBerryPi UART can't receive data from RS485

I try to connect my raspberry pi (with raspbian weezy) with a strip LED module. To do this, I use the UART connection of RBPi in order to communicate with RS485 strip connection.
My trouble : I can (yes I can) send data but I don't received ACK or anything else. However my strip LED module send data frame to the RBPi (I can see it on oscilloscope).
EDIT :
I think it's due to the following error that appears when the program opened UART connection. NO : The following error is due to an non-user permission
[ERROR] [DAAPI] iso=-1:cannot open /dev/mem
Well, But I don't receive message...
END EDIT
I write the following javaME code to do this :
UARTConfig config = new UARTConfig((int)Integer.valueOf(this.getPortCom()),(int)Integer.valueOf(this.getPortCom()), this.getBaudrate(),
this.getBitsperchar(), this.getUARTParity(), getStopBits(), UARTConfig.FLOWCONTROL_NONE);
this.uart = (UART)DeviceManager.open(config);
InputStream serialInputStream = Channels.newInputStream(uart);
BufferedReader serialBufferedReader = new BufferedReader(new InputStreamReader(serialInputStream));
this.tSerialOutput = new Thread( new SerialWriter( Channels.newOutputStream(uart) ) );
this.tSerialOutput.start();
this.tSerialInput = new Thread( new SerialReader( serialBufferedReader ));
this.tSerialInput.start();
"this" is my class which manage serial communication.
The error message is getting after the "DeviceManager.open"
I have follow the recommendation of the following ticket :
https://community.oracle.com/message/12513726
But it's not really the answer of my issue (I think...)
I have no idea.... So please, help me ^^
First, you must be sure Serial Port is not already used by Linux Console. Here is how to disable this:
Edit /etc/inittab and disable the following line by adding a # character in front of it
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
then reboot.
If this is still not working, then you may try to execute JavaME runtime with elevated privileges:
sudo ./runSuite.sh <yourapp>
If this is working, there is a permission problem somewhere.
Finally, you should try to get latest version of JavaME (currently, it is 8.1).

How can I select an audio output device in directshow

I was wondering how I can select the output device for audio in directshow. I am able to get available audio output devices in directshow. But how can I make one of these to be audio output device. Its always going for the default audio device. I want to be able to output audio on my choice of device. I have been struggling through google but couldn't find anything useful. All I could get was this link but it doesn't really solve my problem.
Any help will be really helpful for me.
First off, if you're not using DirectShow .NET (DirectShowLib), get that here: It serves as a (very complete) interface between unmanaged DirectShow and C#
What follows is a pretty simple example of how to play an audio file, to the desired audio device
using DirectShowLib;
private IGraphBuilder m_objFilterGraph = null;
private IBasicAudio m_objBasicAudio = null;
private IMediaControl m_objMediaControl = null;
private void playAudioToDevice(string fName, int devIndex)
{
object source = null;
DsDevice[] devices;
devices = DsDevice.GetDevicesOfCat(FilterCategory.AudioRendererCategory);
DsDevice device = (DsDevice)devices[devIndex];
Guid iid = typeof(IBaseFilter).GUID;
device.Mon.BindToObject(null, null, ref iid, out source);
m_objFilterGraph = (IGraphBuilder)new FilterGraph();
m_objFilterGraph.AddFilter((IBaseFilter)source, "Audio Render");
m_objFilterGraph.RenderFile(fName, "");
m_objBasicAudio = m_objFilterGraph as IBasicAudio;
m_objMediaControl = m_objFilterGraph as IMediaControl;
m_objMediaControl.Run();
}
It is up to user to manage audio devices and choose a primary device (such as via Control Panel applet). You can find ways to switch devices programmatically in Windows XP, however in Vista+ it is impossible without interactive user action by design.
See also Larry's answer here: How to change default sound playback device programmatically?
UPDATE: The mentioned above refers to modifying system configuration trying to alter default audio output device. An application is however not limited to default device only. Instead, it can enumerate available devices (see Using the System Device Enumerator + CLSID_AudioRendererCategory) and then create an instance of renderer for specific device with BindToObject call. From there on, it is a regular filter, just bound internally to device of interest.

Resources