Reputation: 183
Tell me please. There is an Xprinter q260 receipt printer. How can I send esc / pos commands to it using the web?
The printer is connected to ethernet.
When switching to http://192.168.0.110:9100
, the printer prints information about the device from which they clicked on a web link.
Upvotes: 1
Views: 2404
Reputation: 1088
Suppose you use C++, then for this, I made a class. Here some snippets of the class to re-use:
to open a socket for the printer:
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;
to connect to the printer:
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;
to print data to the printer:
int bytes_sent = ::send( m_sock, data, length, MSG_NOSIGNAL );
to close the printer after the job:
::close( m_sock);
Upvotes: 0