确保连接到通过 COM 连接的 POSPrinter

发布于 2024-08-03 18:00:45 字数 242 浏览 11 评论 0原文

在将数据写入数据库然后打印收据之前,我需要确保与 POS 打印机的连接成功。 POSprinter 通常为 BTP 2002NP 类型,但可能有所不同。共同点是它们都是通过 COM 端口而不是 USB 连接的,因此客户端上根本没有安装任何驱动程序。

我可以在 COM 端口上发送某种“ping”并检查设备是否已连接并打开?非常感谢任何帮助或建议。

附加信息,该应用程序是在 VB.net 和 Visual Studio 2008 中开发的

I need to make sure that the connection to a POS printer is successful before writing data to the database and then printing a receipt. The POSprinter is normally of type BTP 2002NP but may differ. The common thing is that they are all connected via COM-port and NOT usb, so no drivers installed at all on the client.

Can I send some kind of "ping" on a COM-port and check if a device is connected and turned on? Any help or suggestions are very much appreciated.

Additional information, the application is developed in VB.net and Visual Studio 2008

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情域 2024-08-10 18:00:45

您所能做的就是向 com 端口写出一个字符串,然后等待,看看您的打印机是否做出响应。然而,您写入的字符串和您期望的字符串将取决于打印机本身。

有关示例,请参阅 BTP 2002NP 打印机编程手册 (我查看的谷歌中的第一个链接)

通过查看手册,发送到打印机的适当字符串是“DLE EOT n”命令,该命令请求打印机发回其当前状态。

至于该系列中的其他打印机,请查看此驱动程序和手册列表

About all you can do is write out a character string to the com port and wait and see if your printer responds with a reply. However the string you write and the string you expect will depend on the printer itself.

Refer to the BTP 2002NP printers programming manual for examples (the first link in google that I looked at)

From looking at the manual an appropriate string to send to the printer is the "DLE EOT n" command which requests that the printer send back its current status.

As for other printers in the range, check out this list of drivers and manuals

无所的.畏惧 2024-08-10 18:00:45

顺便说一句,这就是我最后想到的。

   Public Function ComTest() As Byte()

    Dim TXT As String
    TXT = Chr(&H10S) & Chr(&H4S) & Chr(1) 'DLE EOT 1

    If OpenCom() Then 'Connect to com
        moRS232.PurgeBuffer(Rs232.PurgeBuffers.TxClear Or Rs232.PurgeBuffers.RXClear)
        moRS232.Write(TXT)
        moRS232.Read(1)
        Return moRS232.InputStream
    Else
        Return Nothing          
    End If

End Function

该函数返回 1 个字节。然后我可以从手册中将该字节转换为打印机当前所处的状态。这可能适用于所有 ESC/P 打印机。

btw, this is what i came up with in the end.

   Public Function ComTest() As Byte()

    Dim TXT As String
    TXT = Chr(&H10S) & Chr(&H4S) & Chr(1) 'DLE EOT 1

    If OpenCom() Then 'Connect to com
        moRS232.PurgeBuffer(Rs232.PurgeBuffers.TxClear Or Rs232.PurgeBuffers.RXClear)
        moRS232.Write(TXT)
        moRS232.Read(1)
        Return moRS232.InputStream
    Else
        Return Nothing          
    End If

End Function

the function returns 1 byte. i can then from the manual translate this byte into what state the printer is currently in. this probably works for all ESC/P printers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文