Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 378
Liquid Core Avatar asked Mar 26 '13 21:03

Liquid Core


People also ask

Can I connect to printer with USB-C?

You need a USB-A female (receptacle) to USB-C male (plug) adapter, which can connect your printer's existing USB cable to your computer. The adapter should support USB 3.1 so it can be used with all USB devices, not just USB 2.0. Or you can replace the printer's existing USB cable with a USB-B male to USB-C male cable.

Can you print directly from a USB?

You can print directly from a USB flash drive without having to connect your computer to the printer. Here is a look at some of the best printers that can print from a flash drive.

How do I setup my printer to print from USB?

Simply plug the USB cable from your printer into an available USB port on your PC, and turn the printer on. Select the Start button, then select Settings >Devices >Printers & scanners. Select Add a printer or scanner. Wait for it to find nearby printers, then choose the one you want to use, and select Add device.

Can USB B connect to USB-C?

Uniquely, USB Type-C is reversible, meaning you can plug it in upside down and it will still work. However, you cannot plug existing USB A or USB B connectors into a USB Type-C port, nor can you plug a USB Type-C connector into an older port.


1 Answers

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

like image 134
Shreyas Kapur Avatar answered Oct 31 '22 04:10

Shreyas Kapur