0

嗨,伙计们,我是新手,所以我想知道这件事,所以请帮助我...我想知道如何通过超级终端向打印机发送命令以打印一些文本...。这对我有很大帮助...谢谢你们...这里我已经写了所有的过程...

1)要向打印机发送任何命令/数据,您需要将其作为协议命令发送,并且从串行或以太网端口发送出去。

2) 您需要发送 ESC ( 1B hex) 作为命令的开始, Eot ( 04 H ) 作为命令的结束发送每个命令

3) 在典型应用中,您需要将数据发送到打印机进行打印,然后监控打印机已完成的打印数量。这可以使用以下命令步骤来实现 a) 使用命令 ESC/S/002/要打印的数据/Eot发送消息数据

b) 使用命令ESC/P/1/002/Eot将消息分配给打印

c) 使用命令 Esc/I/1/Z/Eot 设置打印确认 – 我们将“Z”字符设置为标志。每当打印机在产品上打印时,它都会通过端口发送“Z”作为打印确认。通过跟踪 Z 收到的数量 可以计算打印的产品数量**

在 asp.net Web 应用程序中单击按钮,我们必须通过超级终端将此命令发送到打印机..

所以请帮助我解决这个问题。

4

1 回答 1

0

您可以尝试以下代码,它应该验证您可以从 VB 与设备“对话”

    Option Explicit
'
' Requires 2 multi line TextBoxes named txtSent and txtReceived
' one textbox named txtToSend
' CommandButton named cmdSend
'
Private Sub Form_Load()
txtSent.Text = vbNullString
txtReceived.Text = vbNullString
txtToSend.Text = vbNullString
'
' Configure the Port and send an Escape character to the device
'
With MSComm1
    .CommPort = 1
    .RThreshold = 1
    .Settings = "19200,n,8,1"
    .PortOpen = True
    .Output = Chr(27)
    txtSent.Text = "Escape" & vbNewLine
End With
End Sub

Private Sub cmdSend_Click()
'
' Send whatever is in txtToSend to the Device
'
If txtToSend <> vbNullString Then
    MSComm1.Output = txtToSend.Text & vbNewLine
    txtSent.Text = txtSent.Text & txtToSend.Text & vbNewLine
    txtToSend.Text = vbNullString
Else
    MsgBox "Enter a Command to Send to the Device"
End If
End Sub

Private Sub MSComm1_OnComm()
Dim strRx As String
Select Case MSComm1.CommEvent
    Case comEvReceive
        '
        ' Device has sent something. Add it to txtReceived
        '
        strRx = MSComm1.Input
        txtReceived.Text = txtReceived.Text & strRx
End Select
End Sub

只需在 txtToSend 中键入命令并单击 cmdSend,您应该会在 txtReceived 中看到来自设备的响应

于 2016-08-28T13:39:13.680 回答