简体   繁体   English

使用带有C#的USB打印机,带或不带驱动程序或API

[英]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. 我不是一个C#专家,我做了一些尴尬的事情,如音乐程序的钢琴卷(因此生成一个带有数学等的WPF画布)和一些简单的程序来执行常见任务,如动态详细说明一些数据(数学运算,GUI交互等

I need a very general overview on how I could detect an USB printer on my own computer and work with it. 我需要非常概括地了解如何在自己的计算机上检测USB打印机并使用它。 I've already searched for that here and on google, and that's what I found: 我已经在谷歌搜索了这个,这就是我发现的:

Link 1 链接1

Link 2 链接2

Link 3 链接3

Link 4 链接4

Link 5 链接5

Link 6 链接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...) A)使用没有驱动程序的打印机(这个定义可能不准确,但我有点困惑......)

I should: 我应该:

1) Find a way to detect the usb doors and which device is connected to them through Product ID and Vendor ID. 1)找到一种方法来检测USB门以及通过产品ID和供应商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. 在Developerfusionarticle的特定情况下,authore解释了USB的一些基础知识,并告诉您使用人机接口设备来检测它。 (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) (我正在使用Windows 7,我找不到任何HID,只是其他随机的usb驱动器,而且我根本不知道如何与它们进行交互)

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. 2)创建数据流并将它们连同命令一起发送到USB消息管道上的usb打印机(或witver设备)。

B)To use a printer with drivers or windows API or prebaked drivers: B)使用带驱动程序或Windows API或预烘焙驱动程序的打印机:

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... 1)使用[MSDN System.printing libraries] [Link number 6]中的所有.NET类,并使用正确的方法直接引导打印机(在使用System.printing库查找设备之后)那些课......

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). 有关如何操作的步骤指导,特别是第一个(正如我在MSDN论坛上看到的问题,第二个问题实际上是研究代码的问题)。 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 这个答案是选项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. 我以前使用Assembly来做,这可以给你非常低级别的控制。 The only thing I can think of is libusb which has good wrappers for C# as well. 我唯一能想到的是libusb ,它也有很好的C#包装器。 It provides direct access to USB devices, like printers. 它可以直接访问USB设备,如打印机。 A good C# start would be controlling simpler usb devices to get the hang of it. 一个好的C#start将控制更简单的USB设备以获得它的悬念。 Make sure you know how your printer interprets data, written from the usb port. 确保您知道打印机如何解释从USB端口写入的数据。

C# bindings C#绑定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM