Write file to a PNP device connected to a Windows PC - c#

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.

Related

c# create media at runtime

I want to add a backup functionality to my app in the sense that the app will allow users to create a self-contained environment (data + executable + autorun.inf file) on an external device (CD, CD-ROM or USB key) so that users can retrieve (in read only mode) their stored environment at a given point in time.
I've read here about making an auto-bootable USB (which I suspect will be the same for a CD or DVD).
edit I meant "auto-executing", not "auto-bootable"!
I know about IMAPI or other approaches that are now several years old. Is there any alternative/standard approach to create media this way? I'd like a generic way to create either CD/DVD or USB devices (non-bootable).
You need to make sure to not confuse Booting and Windows Autorun.
auto-bootable USB
refers to an external USB drive from which you can boot your computer.
I doubt that's what you are looking for, given the linked Stackexchange question. The information you already found is actually what you are looking for, and the advice given there seems pretty accurate.
What you need to do is:
Create the media with your data. In case of USB sticks this is as easy as copying the data to the stick. Optical media (CD/DVD) need to be burned, and that can only be done using the Windows API, which has already be discussed here.
If you want to use the Windows autorun feature (which I would ignore*), you'll need to create a file called Autorun.ini in the root directory of your media. You already have found the required content of that file here.
* Why I would skip the autorun feature.
First of all, there's no real alternative to the Windows autorun feature.
It was controversial, at best, in earlier versions of Windows. Since USB sticks went mainstream, autorun became nothing more than an automatic virus installation feature. Soon after everyone started disabling it. Because of this recent versions of Windows seem to have dropped it or disable it by default.
An exception to this would be the Icon=diskicon.ico option, which allows you to change the icon of the drive. This might be still working, even if autorun is disabled.

Intercept and modify USB packets

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.

Is there a simple and efficient way to get listed all usb devices in C# or C/C++?

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

Datalogic Barcode/Weight Scanner

Could anyone please give me any idea as to where to start my coding in order to get data from OPOS(Datalogic Magellan device) weighting and barcode scanning in C#?? For example, what library and what function I should be using for this case. I am clueless as I have already spent numerous of hours searching for an answer online. Not even came close online.
I don't know any api that I can use to get the weight and barcode for the usb device into my C# program.
I am currently using Datalogic scale. I tried the build-in windows reader but it didn't read in any data from the device.
First off, I used the Microsoft.PointOfService library which can directly create connection to most of the opos base machine. And make sure you have your Logical Device Name right! Very Very important. This is NOT any normal name you found in your regedit, it MUST be define manually by yourself inside the opos adk program that you installed along with the opos machine.
Then you can pass in the name as usual in your C# program.
For example: you set USB_Scale as your logical device name inside OPOS program
in C#
this.myDevice = explore.GetDevice("Scale", "USB_Scale");
Note: Make sure you set claim to 1000; It might not work if you didn't do so.
Also : this.myScale = ((Scale)explore.CreateInstance(myDevice)); <- this might help~
The rest is just straight forward.

Audio Framework for Mac and Windows

I realize I asked a question similar to this before, but the planning on what I want to do has come some way, and the parameters have become a bit different.
Basically, I'm looking for the best option for decoding and outputting audio on both Mac and Windows. Ideally, there will be no differences in needed code between the two platforms. I just want to be able to pass it a file path or HTTP URL and have it play the audio with the ability to pause, seek, etc.
It must be able to decode MP3 and AAC out of the box with no dependencies on the OS (like Phonon for Qt which is entirely dependent on the OS). Any other codecs beyond that would be a very nice bonus.
I've looked at things like libavcodec, which supposedly can decode about anything, but haven't been able to figure out how to get it to work. So far it seems that libraries I've seen are also ready for Mac and Linux or Windows and Linux but not Mac and Windows.
It does not need to be open source, but if it is needs to be usable in commercial products. I'm OK with licensing something as long as it's not too expensive and easy to use.
Finally, while C/C++ would be preferred, if there's something that would work with C#/Mono, that's OK too.
Any suggestions on something that would work for this?
I've created a C++ audio library for Mac and Windows named "Crosstalk".
Crosstalk is a C++ audio engine that allows you to create and route audio systems in real-time. The engine takes care of all the audio routing and gives you a simple platform for creating system components (E.g. "Mp3 Decoder" component connected to a "Low-Pass Filter" connected to an "Audio Device" and "File Recorder").
It's very easy to use. Here's an example of how to play an mp3 file (These components are provided with the engine):
XtSystem system;
XtMp3Decoder mp3Decoder;
XtAudioDevice audioDevice;
long md = system.addComponent(&mp3Decoder);
long ad = system.addComponent(&audioDevice);
system.connOutToIn(md,0,ad,0);
system.connOutToIn(md,1,ad,1);
mp3Decoder.loadFile("../05 Tchaikovski-Swan Lake-Scene.mp3");
mp3Decoder.play();
Included with Crosstalk is example Xcode and Visual Studio projects.
You can download Crosstalk and check out the API documentation and licensing details here: http://www.adaptaudio.com/Crosstalk
EDIT (01-12-2012):
Crosstalk has been replaced by an open-source project called "DSPatch". DSPatch is essentially an upgraded version of the routing engine behind Crosstalk that is no longer limited to only audio processing. DSPatch allows you to create and route almost any type of process chain imaginable, and free for personal AND proprietary use :)
decode MP3 and AAC out of the box
I'm not aware of any audio library that does this so easilly. The problem is the license issue regarding MP3 decoding.
I discuss some options on this post, and they are good for Windows/Mac OS X, but I'm not sure if they have C# bindings.
If you are willing to write the bindings yourself, you might be interested at libaudiodecoder:
A C++ cross platform MP3/AAC/WMA/WAV decoder.
It comes with an example that shows how to play a song on Windows/Mac through PortAudio.

Categories