SerialPort,USB端口和端口名称 [英] SerialPort, USB ports and Port Names

查看:133
本文介绍了SerialPort,USB端口和端口名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SerialPort组件向连接的USB打印机发送一些打印机命令(ZPLII)

。我根本没有走得太远。事实上我

无处可去。


我遇到的第一个问题是调用SerialPort.GetPortNames()

返回一个空字符串[]。换句话说,返回NO端口名称。我是

对端口知之甚少,但是从硬件管理器我做了

注意我没有端口和设备条目(我认为'是什么

它被称为。)


如果我显示已安装打印机的属性对话框并更改为

端口选项卡我看到列出了几个端口(LPT1,COM1,USB001等)。


所以我的问题是:SerialPort.GetPortNames()应该返回USB,

我在打印机对话框中看到的LPT1和COM端口?我希望它可以吗

它不应该吗?


有非常简单的代码行:

string [ ] ports = System.IO.Ports.SerialPort.GetPortNames();


我要打开的端口称为USB001。 - 当我尝试使用SerialPort组件打开该端口

时,我得到一个异常,声明名称必须

以COM开头。

所以我的#2问题是:你们用USB连接设备通信的方式是什么?如果它不是SerialPort组件,那么类库中是否有另外一个组件?


我认为这将是小菜一碟!


感谢您的帮助,

Steve

I''m trying to send some printer commands (ZPLII) to an attached USB printer
using the SerialPort component. I didn''t get very far at all. In fact I
haven''t gotten anywhere.

The first problem I encountered is that a call to SerialPort.GetPortNames()
returns an empty string[]. In other words, NO port names are returned. I''m
not terribly knowledgable about ports but from the Hardware Manager I did
notice that I don''t have the Ports and Devices entry (I think that''s what
it''s called).

If I show the properties dialog for an installed printer and change to the
Ports tab I see several ports listed (LPT1, COM1, USB001, etc).

So my question is: Should SerialPort.GetPortNames() be returning the USB,
LPT1 and COM ports I see in the printer dialog? Am I expecting it to do
somethinh it shouldn''t?

There very simple line of code:
string[] ports = System.IO.Ports.SerialPort.GetPortNames();

The port I want to open is called "USB001" - when I try to open that port
using the SerialPort component I get an exception that states the name must
start with "COM".
So my #2 question is: What is the method that you all use to communicate
with a USB attached device? If it''s not the SerialPort component, is there
another component in the class library?

I thought this would be a piece of cake!

Thanks for any help,
Steve

推荐答案

4月29日, 2:02 * pm,sklett < s ... @ s.comwrote:
On Apr 29, 2:02*pm, "sklett" <s...@s.comwrote:

我正在尝试将一些打印机命令(ZPLII)发送到连接的USB打印机

使用SerialPort组件。 *我没有走得太远。 *实际上我

无处可去。


我遇到的第一个问题是调用SerialPort.GetPortNames()

返回一个空字符串[]。 *换句话说,返回NO端口名称。 *我是

对端口知之甚少,但是从硬件管理器我做了

注意我没有端口和设备条目(我认为是什么

它被称为。)


如果我显示已安装打印机的属性对话框并更改为

端口选项卡我看到列出了几个端口(LPT1,COM1,USB001等)。


所以我的问题是:* SerialPort.GetPortNames()应该返回USB,

我在打印机对话框中看到的LPT1和COM端口? *我希望它能做什么

它不应该吗?


有非常简单的代码行:

string [] ports = System.IO.Ports.SerialPort.GetPortNames();


我要打开的端口名为USB001。 - 当我尝试使用SerialPort组件打开该端口

时,我得到一个异常,声明名称必须

以COM开头。

所以我的#2问题是:*你用USB连接设备通信的方法是什么?
*如果它不是SerialPort组件,那么类库中的另一个组件是否有



我认为这将是小菜一碟!


感谢您的帮助,

Steve
I''m trying to send some printer commands (ZPLII) to an attached USB printer
using the SerialPort component. *I didn''t get very far at all. *In fact I
haven''t gotten anywhere.

The first problem I encountered is that a call to SerialPort.GetPortNames()
returns an empty string[]. *In other words, NO port names are returned. *I''m
not terribly knowledgable about ports but from the Hardware Manager I did
notice that I don''t have the Ports and Devices entry (I think that''s what
it''s called).

If I show the properties dialog for an installed printer and change to the
Ports tab I see several ports listed (LPT1, COM1, USB001, etc).

So my question is: *Should SerialPort.GetPortNames() be returning the USB,
LPT1 and COM ports I see in the printer dialog? *Am I expecting it to do
somethinh it shouldn''t?

There very simple line of code:
string[] ports = System.IO.Ports.SerialPort.GetPortNames();

The port I want to open is called "USB001" - when I try to open that port
using the SerialPort component I get an exception that states the name must
start with "COM".
So my #2 question is: *What is the method that you all use to communicate
with a USB attached device? *If it''s not the SerialPort component, is there
another component in the class library?

I thought this would be a piece of cake!

Thanks for any help,
Steve






显然你的问题是你可以使用串口

并且打印机连接到USB。

你能用串口连接你的打印机吗?电缆?

这是Zebra打印机吗?

Hi,

Apparentely your problem is that you aer tryig to use the serial port
and the printer is connected to USB.
Can you connect your printer using serial cable?
Is this a Zebra printer?


sklett写道:
sklett wrote:

我正在尝试使用SerialPort组件将一些打印机命令(ZPLII)发送到连接的USB

打印机。

所有我都没有走得太远。事实上,我没有到达任何地方。
I''m trying to send some printer commands (ZPLII) to an attached USB
printer using the SerialPort component. I didn''t get very far at
all. In fact I haven''t gotten anywhere.



您的USB打印机实现打印机设备类,而不是通信

设备类。 SerialPort只能与通信端口驱动程序一起使用,

自动加载标准UART芯片,CDC USB设备,以及

也可用于某些USB /串行转换器芯片那不是CDC。你的
打印机不属于那个类别。


OTOH,Win32打印API允许你发送各种特定于设备的命令

使用Escape,ExtEscape和/或WritePrinter。我不知道.NET

是否提供这些或者你必须调用它们。

Your USB printer implements the printer device class, not the communications
device class. SerialPort can only be used with communications port drivers,
which are automatically loaded for standard UART chips, CDC USB devices, and
are also provided for some USB/serial converter chips that aren''t CDC. Your
printer doesn''t fall in that category.

OTOH, the Win32 printing API lets you send various device-specific commands
using Escape, ExtEscape, and/or WritePrinter. I don''t know whether .NET
provides these or you have to p/invoke them.


Ignacio Machin(.NET / C# MVP)写道:
Ignacio Machin ( .NET/ C# MVP ) wrote:




显然你的问题是你在尝试使用串口

并且打印机连接到USB。

您可以使用串行电缆连接打印机吗?

这是Zebra打印机吗?
Hi,

Apparentely your problem is that you aer tryig to use the serial port
and the printer is connected to USB.
Can you connect your printer using serial cable?
Is this a Zebra printer?



嗨Ignacio,


比你回复!


你是正确的,打印机连接到USB。我在我的

头中有这个,虽然它使用的是USB端口,但这确实是真的是一个

COM端口。在幕后。我对端口,USB等一无所知。


我可以通过串口连接打印机,但会认为它是最后的

度假村。我们在我们的办公室周围部署了8台这样的打印机,而且需要通过串口连接所需的电缆需要安装等等的b / b
。实际上,我认为越多关于这个...不,我不是没有b $ b我认为我可以做一个真正的串行连接 - 我所指的电缆是一个

串口-USB转换器或它甚至可能是并行-USB(一端有

2.5宽连接器,另一端有USB。


我很漂亮确定我的问题是100%是由于缺乏对

端口工作方式以及不同类型端口的理解。

例如,我们使用基于Web的ERP / CRM名为NetSuite的应用程序 -

在NetSuite帮助中,他们有一个关于热敏打印的部分

说明说创建带有文本的* .bat文件:

" copy%1 LPT1"

然后将文件扩展名EPL2与此bat文件关联。


给我这意味着当NetSuite提供EPL2文件并且显示

浏览器打开/保存对话框时,我将选择打开按钮。反过来

会将文件传递给bat文件,而bat文件又会复制打印机

命令包含在LPT1端口。


所以在某种程度上,我想我刚才回答了我的部分问题; 0)

(我刚回复你的帖子之前在NetSuite找到了这个帮助部分)

我要做的是找到一种写的方法。从我的

C#应用程序到打印机。我准备使用的邮资网络服务可以用几种格式退回邮资,分为两类:图片

或打印机命令。打印机命令要小得多,并打印更快,因此它们是我的第一选择。


哦,回答你的问题:是的,这些是Zebra打印机,我们有

3844-Z和2844(cheapos)。


希望这些额外的信息能让你更好地了解

我正在追求。


再次感谢您的回复!

-Steve

Hi Ignacio,

Than you for the reply!

You are correct, the printer is connected to the USB. I had it in my
head that although it was using a USB port, this was somehow "really a
COM port" behind the scenes. I know nothing about ports, USB, etc.

I can connect the printer via serial but would consider it a last
resort. We have 8 of these printers deployed around our office and
warehouse, the cable needed to connect via serial requires drivers to be
installed, etc. Actually, the more I think about this... no, I don''t
think I can make a true serial connection - the cable I refer to is a
Serial -USB converter or it may even be a Parallel -USB (it has the
2.5" wide connector on one end and USB on the other.

I''m pretty sure my problem is 100% due to a lack of understanding of how
ports work and the different kinds of ports.
For example, we use a web based ERP/CRM application called "NetSuite" -
In the NetSuite help they have a section on "Thermal Printing"
The instructions say to create a *.bat file with the text:
"copy %1 LPT1"
then to associate the file extension EPL2 with this bat file.

To me this means that when NetSuite serves up an EPL2 file and the
browser Open/Save dialog is presented I will choose "Open" which in turn
will pass the file to the bat file which in turn will copy the printer
commands contained to the LPT1 port.

So in a way, I think I just answered part of my question ;0)
(I just found this help section in NetSuite before responding to your post)

What I''m looking to do is find a way to "write" to the printer from my
C# application. The postage web service that I''m preparing to use can
return the postage in several formats falling into two categories: image
or printer commands. The printer commands are much smaller and print
faster so they were my first choice.

Oh, to answer your question: Yes, these are Zebra printers, we have
both 3844-Z and 2844 (cheapos).

Hopefully this additional information will give you a better idea of
what I''m after.

Thanks again for the reply!
-Steve


这篇关于SerialPort,USB端口和端口名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆