Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] How to send control command to POS printer?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Abin
    wrote on last edited by
    #1

    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...

    najeebN 1 Reply Last reply
    1
    • A Offline
      A Offline
      Abin
      wrote on last edited by
      #2

      I got the solution from a different forum..

      out << "\n\x1Bi";

      Hope this would help someone else...

      1 Reply Last reply
      0
      • A Abin

        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...

        najeebN Offline
        najeebN Offline
        najeeb
        wrote on last edited by
        #3

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

        AriakasA 1 Reply Last reply
        0
        • najeebN najeeb

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

          AriakasA Offline
          AriakasA Offline
          Ariakas
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved