【问题标题】:Sending commands to an esc / pos network printer向 esc / pos 网络打印机发送命令
【发布时间】:2020-04-04 22:01:46
【问题描述】:

请告诉我。有一台 Xprinter q260 收据打印机。如何使用网络向它发送 esc / pos 命令? 打印机已连接到以太网。 当切换到http://192.168.0.110:9100 时,打印机会打印有关他们单击网络链接的设备的信息。

【问题讨论】:

标签: escpos


【解决方案1】:

假设你使用 C++,那么为此,我做了一个类。这里有一些类的 sn-ps 可以重用:

为打印机打开一个套接字:

m_sock =socket( AF_INET, SOCK_STREAM, 0);
int on =1;
if ( setsockopt( m_sock, SOL_SOCKET, SO_REUSEADDR, (const char*) &on,
        sizeof(on)) == -1)
    return false;

连接打印机:

sockaddr_in m_addr;
m_addr.sin_family =AF_INET;
m_addr.sin_port =htons( port);
int status =inet_pton( AF_INET, host.c_str(), &m_addr.sin_addr);
if ( errno == EAFNOSUPPORT)
    return false;
status =::connect( m_sock, (sockaddr *) &m_addr, sizeof(m_addr));
return ( status == 0) ? true:false;

将数据打印到打印机:

int bytes_sent = ::send( m_sock, data, length, MSG_NOSIGNAL );

在作业后关闭打印机:

::close( m_sock);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-18
    • 2020-11-16
    • 2015-08-20
    • 2020-05-07
    • 2011-02-19
    • 2017-10-21
    • 2017-05-18
    相关资源
    最近更新 更多