The project is as follows;
I would like to create an application that will be able to see packets going to a USB device. When a certain bit of data that is known is sent to the device, the returning data will be intercepted and modified before the application requesting it, gets it. I have used a USB sniffer to see the packets being sent and I know exactly what bits need to be changed. My two questions are;
Is this a possible software solution?
Will this have to be a hardware solution?
Additional Information –
The USB device uses a FTDI245R chip for communication. I know the VID and PID of the device.
I have experience programming in vb.net and C# but I have never done anything with USB
I would like the application to be able to have a number entered and changed to hex data and that is what would be sent to the device. The number being entered would be changed frequently.
Any input is appreciated.
It sounds to me like you want an upper filter driver to the FTDI driver. I don't know what class or type of device you are using or if it has a vendor specific driver or not, but here is a sample that shows how to create an upper filter to a vendor specific driver. This example uses the OSRUSBFX2 device and sample driver in the WDK, you'll want to change the code to work and interface with the FTDI driver instead.
Related
I need to read with C# UWP App, a DHT11/DHT22 sensor to get temperature and the arduino is conected to an Arduino UNO.
Can I use "digitalRead" at sensor PIN and converte the values using C# library
'sensors.dht'? Or I need to change the FirmataStandard sketch to include dht library and receive the values "cleaned"?
Thanks very much!
In theory, your plan is possible utilizing Windows Remote Arduino.
But currently, there is no official solution for your user case.
So you may need do some work by yourself. You need modify GPIO OneWire DHT11 library to fit your solution, such as, replace Windows::Devices::Gpio::GpioPin::Read() with Microsoft::Maker::RemoteWiring::RemoteDevice::digitalRead() and so on. Also note the time sequence due to DHT11/22 datasheet.
Finally, you may need sufficient test to ensure this solution works as expected.
I am currently iterating through a list of USB Cameras connected to my computer that I retrieved with the following code:
DsDevice[] cams = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
I then determine the HardwareID and InstanceID values from the DevicePath for each device, and I look up the following registry key for all devices:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB{HardwareID}{InstanceID}\
I then read the LocationInformation subkey value. Here are some examples of what I'm receiving based on which USB port the device is plugged in to:
0000.001a.0000.001.003.000.000.000.000
0000.001a.0000.001.004.000.000.000.000
0000.001d.0000.001.008.000.000.000.000
0000.001d.0000.001.007.000.000.000.000
0000.001d.0000.001.005.000.000.000.000
0000.001d.0000.001.006.000.000.000.000
It appears that the second block (index 1 of the returned Split('.') array) is a distinction between the internal USB hub that the USB port is connected to. Is this correct?
I have deduced that the fifth block (index 4) is the USB port number, but on a separate computer I'm using (an Intel Compute Stick), the port number differentiation actually occurs in the fourth block (index 3). Is there a way to know which block I need to check based on the computer? (Third-party libraries are acceptable though I'd much rather use built-in functionality of .NET or straight Windows APIs that I can hook into, if possible.)
Is there any documentation on what each section of the LocationInformation is? I have Googled for information, but I've come up short of what I'm looking for. Perhaps I just don't know the best search terms to find this information. In any case, I'd bet that this documentation could be extremely useful to other StackOverflow users as well.
Thanks!
By plugging in a PNP device to a Windows PC I want to know if the device supports a feature of data transferring. I am majoraly interested in pushing some content to device.
So, for example when I am plugging in a Windows Phone I can see over windows managment query that 5 new devices are added
Name: Windows Phone
CompartibleId: USB\MS_COMP_MTP,
USB\Class_06&SubClass_01&Prot_01, USB\Class_06&SubClass_01,
USB\Class_06
Name: WinUsb Device
CompartibleId: USB\MS_COMP_WINUSB,
USB\Class_ff&SubClass_ff&Prot_ff, USB\Class_ff&SubClass_ff,
USB\Class_ff
Name: WinUsb Device
CompartibleId: USB\MS_COMP_WINUSB,
USB\Class_ff&SubClass_ff&Prot_ff, USB\Class_ff&SubClass_ff,
USB\Class_ff
Name: WinUsb Device
CompartibleId: USB\MS_COMP_WINUSB,
USB\Class_ff&SubClass_ff&Prot_ff, USB\Class_ff&SubClass_ff,
USB\Class_ff
Name: USB Composite Device
CompartibleId:
USB\DevClass_00&SubClass_00&Prot_00, USB\DevClass_00&SubClass_00,
USB\DevClass_00, USB\COMPOSITE
How can I now get a glue that:
All the devices are parts of a single device
The device allows me to save a file on it
Find an indicator that certainly tells me about the suppoted file transfer protocol
In case if there are more than a sigle possiblility for file trasfer select the more fastest(or modern)
I will appreaciate any help even if you could just tell me a focused direction where I should continue my study/investigation.
I am looking at a generic way to work with devices. Desired implementation language is C#.
Firstly You can consult this codeproject it gives you details of Windows Device Drivers.
SharpUSBLib and HidLibrary are two widely used libraries you can even get a tutorial project with implementation here.
SharpUsbLib earlier version used to screw up systems.
Would prefer libusbdotnet.
If you have to work with an USB device (send requests, process responses), this library was the best solution I could find.
Pros:
Has all methods you need to work in synch or asynch mode.
Source code provided
Enough samples to start using it straight away.
Cons:
Poor documentation (it's common problem for open source projects). Basically, you can find just common description of methods in the CHM help file and that's it. But I still find provided samples and source code is enough for coding. Just sometimes I see a strange behaviour and want to know why it was implemented in this way and can't get even a hint...
Seems unsupported any more. Last version was issued in Oct 2010. And it's hard to get answers sometimes.
I have a USB mass storage device that I encrypt with TrueCrypt. When I connect it to Windows, it asks to format. Using TrueCrypt reveals its contents, as expected.
How can I read the first 100 bytes of that device?
I know the bytes will not make sense because they're encrypted but I want to read them in order to create a checksum.
Did this on the top of my head. But is should work.
public static long getBytes(string letter)
{
ManagementObject disk = new ManagementObject(String.Format("win32_logicaldisk.deviceid=\"{0}:\"", letter));
disk.Get();
return long.Parse(disk["Size"].ToString());
}
EDIT: Tested it and changed int to long. It works.
What solutions have you considered so far? Does your application figure out when the USB device is plugged in or unplugged?
As far as I know, there's no native support in .Net for directly accessing USB devices. I had to use libraries such as LibUsbDotNet (http://sourceforge.net/projects/libusbdotnet/) or SharpUSBLib (http://www.icsharpcode.net/OpenSource/SharpUSBLib/) There were pros and cons to both in terms of samples, documentation etc. I am sure you will be able to find what suits you best.
In one case I was able to connect to the device using WMDC, once the connection was established I used OpenNETCF RAPI library to read from / write to the device.
Here's another excellent resource that I had found useful when I wrote an application that needed to interact with a USB device (a barcode scanner).
http://www.developerfusion.com/article/84338/making-usb-c-friendly/
There was a good resourceful discussion to a similar question here on Stackoverflow : Working with USB devices in .NET
I have to make a program which monitor usb ports and when an usb device is plugged (joypad, flash drives, mouse, ecc...) I get a unique identifier (a deviceid or something else would be good).
At first I tried with C# using the system.management classes and querying the cim_logicaldevice class each second to get the new device plugged.
Some device returned more rows with DeviceID, but this isn't a problem. The problem is that the memory occupied by the program (in task manager) grows up constantly.
This is the source code:
http://pastebin.com/dQv3cMQC
Is there a way to avoid the growing of the memory usege?
I have to do this program in C++ or C# and it has to be the most efficient possible (because it has to be opened forever).
I would recommend looking at the USBView sample in the WDK. If you are unfamiliar with this, simply run it - this tool walks the entire USB tree on the system and prints out information and descriptor listings for each device.
In your case, I'd start at the RefreshTree() function in this sample, you can then follow the code to see how it enumerates the host controllers, hubs and finally devices. For each device that you find you can look at the bInterfaceClass in the interface descriptors to find out what types of interfaces it is advertising.
The easiest way to get the source to this sample is to install the 7.1.0 WDK which is currently available here: http://www.microsoft.com/en-us/download/details.aspx?id=11800