Liquid Core Liquid Core - 2 months ago 25
C# Question

Using a USB printer with C#, with and without driver or API

I'm not exactly a C# expert, I made some awkward things like a piano roll for a music program (so generating a WPF canvas all with math and such) and some simple programs to do common tasks like elaborating some data on the fly (math operations, GUI interactions, etc.

I need a very general overview on how I could detect an USB printer on my own computer and work with it. I've already searched for that here and on google, and that's what I found:

Link 1

Link 2

Link 3

Link 4

Link 5

Link 6

And other similar links telling various methods of which I understood close to nothing :(

Ok here's what I came up with (I'll try to be as brief as possible):

A) For using a printer without the drivers (this definition may not be precise, but I'm a bit confused...)

I should:

1) Find a way to detect the usb doors and which device is connected to them through Product ID and Vendor ID. In the particular case of the Developerfusionarticle the authore explains some basics of USB and tells you to use Human Interface Device to detect it. (I am using windows 7 and I can't find any HID, just other random usb drives, and I have NO IDEA AT ALL on how to interact with them)

2)Create streams of data and send them to the usb printer (or watever device you intend to pilot) along with the commands, on the right message pipes.

B)To use a printer with drivers or windows API or prebaked drivers:

I should:

1)Use all the .NET classes found in [MSDN System.printing libraries][Link number 6] and pilot directly the printer (after finding the device with the use of the System.printing libraries) with the use of the right methods from those classes...

Ok, making the point:

I Have really NO IDEA on which the right steps, and that's what I'm trying to ask you:

A step to step guide on how to do it, expecially the first one (as I saw on the MSDN forum question the second one is really a matter of studying the code). I don't want you to write the code for me (though you can if you want). I'm asking just a general guideline on which are the right steps to follow to achieve the final result. Post links, whatever works...


This answer is for option A

Very difficult problem indeed. Accessing low level hardware, from such a high-level programming language is very tough. I used to do it using Assembly, which can give you very low-level control. The only thing I can think of is libusb which has good wrappers for C# as well. It provides direct access to USB devices, like printers. A good C# start would be controlling simpler usb devices to get the hang of it. Make sure you know how your printer interprets data, written from the usb port.

C# bindings