11

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...

Community
  • 1
  • 1
Liquid Core
  • 1
  • 6
  • 27
  • 52
  • `I'm asking just a general guideline on which are the right steps to follow to achieve the final result.` But SO is not for it. – I4V Mar 26 '13 at 21:24
  • Well put the code then, I'm fine with it too since I have no real idea on how to start. Thanks. – Liquid Core Mar 26 '13 at 21:42
  • 4
    Don't do any "detecting" at all. It is Windows' job to hide the differences between printers. Every printer looks the same to your program. – Hans Passant Mar 26 '13 at 21:56
  • @user2212907 `Well put the code then`, this is what we expect you to do :), Otherwise try google. – I4V Mar 26 '13 at 21:57
  • 3
    You do not want to attempt approach A. There lies madness. You end up writing your own printer driver. With approach B, you start by finding the printer you want. See http://stackoverflow.com/questions/2354435/how-to-get-the-list-of-all-printers-in-computer-c-sharp-winform, for example. – Jim Mischel Mar 26 '13 at 23:35
  • What do you want to accomplish with the USB printer once you have detected it? – Timothy Schoonover Mar 28 '13 at 13:52
  • I don't see the problem here in terms of code.. Do you have some old printer you trying to use and you can't find a driver for it? what is the agenda here? – G.Y Mar 30 '13 at 03:43

1 Answers1

5

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

Shreyas Kapur
  • 669
  • 4
  • 15
  • Thank you, this is a useful answer! If I don't receive any better answer in some days, I'll check you as best answer. Well I needed to control a COM serial printer, but I found C# has some libraries to do that and so I solved the problem by using System.IO.Ports.SerialPort namespace. Since the subject of your answer still interest me, I'll check the working of libusb too. Thank you again. – Liquid Core Apr 01 '13 at 22:04