[Solved] How to send control command to POS printer?



  • Hi,

    I am creating an application which prints text through a POS printer.

    @#include "lanprinterui.h"
    #include "ui_lanprinterui.h"

    LanPrinterUI::LanPrinterUI(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::LanPrinterUI)
    {
    ui->setupUi(this);

    m_TextInput = ui->textEdit;
    m_pSocket   = new QTcpSocket();
    m_pSocket->connectToHost("192.168.1.20", 9100);
    m_ConnectStatus = true;
    
    QObject::connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(print()));
    

    }

    LanPrinterUI::~LanPrinterUI()
    {
    delete ui;
    delete m_pSocket;
    }

    void LanPrinterUI::print()
    {
    const int Timeout = 5 * 1000;

    if (!m_ConnectStatus)
    {
        m_pSocket->connectToHost("192.168.1.20", 9100);
    }
    
    if (!m_pSocket->waitForConnected(Timeout))
    {
        //sent error
        qDebug ("error in waitForConnected()");
        qDebug (qPrintable(m_pSocket->errorString()));
        m_ConnectStatus = false;
        return;
    }
    
    m_ConnectStatus = true;
    QByteArray block;
    QDataStream out(&block, QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_0);
    out << m_TextInput->toPlainText();
    out << '\n';
    m_pSocket->write(block);
    

    }
    @

    The prints works fine. But for POS printer there are control commands to do certain functions like : paper cut, cashdraw open etc.. For eg:

    Function: Partial cut
    Code:
    ASCII-------> ESC i
    Hex --------> 1B 69
    Decimal-----> 27 105

    When I try to send command 27 105 it just prints on paper.. I'm not exactly sure how to send it... Can someone suggest how to write to the socket...



  • I got the solution from a different forum..

    out << "\n\x1Bi";

    Hope this would help someone else...



  • @Abin hello albin ..can you please send me this full code...because im facing problem with printing using pos printer



  • @najeeb I second this. It would be great to download some source files of POS printing.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.