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. Qt and USB Thermal Printer
Forum Updated to NodeBB v4.3 + New Features

Qt and USB Thermal Printer

Scheduled Pinned Locked Moved Solved General and Desktop
37 Posts 6 Posters 5.9k Views
  • 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.
  • D Damian7546

    The big problem will be lack of description function in this library.

    Below is a example send text to printer:

    void CC56SdkDemo01DlgMain::OnBnPrintout()
    {
       CComboBox * pPrinterList;  // Pointer to combo box item
      
       //-- Get printer list (dialog item combo box)
       if ((pPrinterList = ((CComboBox *) this->GetDlgItem(IDC_COMBO_PRINTER_LIST))) != NULL) {
    
          INT iPrinterSel; // Selected printer
     
          //-- Determine selected printer
          if ((iPrinterSel = pPrinterList->GetCurSel()) != CB_ERR) {
     
             LPSTR lpszPrinter = NULL;  // Printer name
    
             //-- Allocate memory for this printer and get name from combo box
             if (    ((lpszPrinter = (LPSTR) malloc(pPrinterList->GetLBTextLen(iPrinterSel)+1)) != NULL) 
                  && (pPrinterList->GetLBText(iPrinterSel, lpszPrinter) != CB_ERR)
                ) {
    
                HANDLE hDocument; // Handle to document 
     
                //-- Start this document
                if ((hDocument = C56Sdk_DmStartDocument(lpszPrinter, "C56SdkDemo01")) != NULL) {
    
                   //-- Add print speed setup to document
                   { 
                      CComboBox  * pPrintSpeedList; 
    
                      //-- Get dialog item of print speed list
                      if ((pPrintSpeedList = ((CComboBox *) this->GetDlgItem(IDC_COMBO_PRINT_SPEED))) != NULL) {
    
                         //-- Set selected print speed 
                         switch (pPrintSpeedList->GetCurSel()) {
                            case 0:  C56Sdk_DcAddPrintSpeed(hDocument, C56PS_LOW);      break;
                            case 1:  C56Sdk_DcAddPrintSpeed(hDocument, C56PS_MEDIUM_2); break;
                            case 2:  C56Sdk_DcAddPrintSpeed(hDocument, C56PS_MEDIUM_1); break;
                            case 3:  C56Sdk_DcAddPrintSpeed(hDocument, C56PS_HIGH);     break;
                            default: C56Sdk_DcAddPrintSpeed(hDocument, C56PS_MEDIUM_2); break;
                         }
                      }
                   }
    
                   //-- Add print quality setup to document
                   { 
                      CComboBox  * pPrintQualityList; 
    
                      //-- Get dialog item of print quality list
                      if ((pPrintQualityList = ((CComboBox *) this->GetDlgItem(IDC_COMBO_PRINT_QUALITY))) != NULL) {
    
                         //-- Set selected print quality 
                         switch (pPrintQualityList->GetCurSel()) {
                            case 0:  C56Sdk_DcAddPrintQuality(hDocument, C56PQ_LOW);   break;
                            case 1:  C56Sdk_DcAddPrintQuality(hDocument, C56PQ_HIGH);  break;
                            default: C56Sdk_DcAddPrintQuality(hDocument, C56PQ_LOW);   break;
                         }
     
                         //-- Set impressed energy correction to ...
                         C56Sdk_DcAddImprEnergyCorrection(hDocument, 50);
                      }
                   }
    
                   //-- Set print mode to 8x16 (for the initial linefeed)
                   C56Sdk_DcAddPrintMode(hDocument, C56PM_FONT_08X16);
     
                   //-- Set initial linefeeds to power up the motor 
                   C56Sdk_DcAddLineFeed(hDocument, 1);
    
                   //-- Add text to print to document
                   { 
                      CEdit  * pTextToPrint; // Pointer to text to print box
    
                      //-- Get text to print (dialog item edit box)
                      if ((pTextToPrint = ((CEdit *) this->GetDlgItem(IDC_EDIT_TEXTTOPRINT))) != NULL) {
    
                         char szTextToPrint[2000+1]; // Buffer for text
    
                         //-- Get text to print
                         if (pTextToPrint->GetWindowText(szTextToPrint, sizeof(szTextToPrint)-1) > 0) {
    
                            //-- Set print mode to 8x16 (as initial text)
                            //.. disable reverse printing
                            //.. select primary font
                            //.. etc. etc. etc.
                            { 
                               C56Sdk_DcAddPrintMode(hDocument, C56PM_FONT_08X16);
                               C56Sdk_DcAddDisableReversePrinting(hDocument);     
                               C56Sdk_DcAddExtRegCharSet(hDocument, FALSE);
                            }
    
                            //-- Add "text to print" to document data
                            C56Sdk_DcAddText(hDocument, szTextToPrint);
                         }
                      }
                   }
    
                   //-- Set print mode to 8x16 (for the final linefeeds)
                   C56Sdk_DcAddPrintMode(hDocument, C56PM_FONT_08X16);
    
                   //-- Add final linefeeds to get text out of the shoot
                   C56Sdk_DcAddLineFeed(hDocument, 50);
    
                   //-- Print document and get job number
                   m_bJobNr = C56Sdk_DmPrintDocument(hDocument);
    
                   //-- End of document
                   C56Sdk_DmEndDocument(hDocument);
                }
             }
    
             //-- Free memory allocated for printer name
             if (lpszPrinter) free(lpszPrinter); lpszPrinter = NULL;
          }
       }
    }
    
    

    Some functions can be confused by the name but what is C56Sdk_DmStartDocument
    Can anyone tell me what this function is for:
    hDocument = C56Sdk_DmStartDocument(lpszPrinter, "C56SdkDemo01") ?

    lpszPrinter - is a name of printer driver, and hDocument ?

    D Offline
    D Offline
    DerReisende
    wrote on last edited by
    #28

    @Damian7546 said in Qt and USB Thermal Printer:

    Can anyone tell me what this function is for:
    hDocument = C56Sdk_DmStartDocument(lpszPrinter, "C56SdkDemo01") ?

    Have you looked at the definition in the header file? what are the variable names in there?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerReisende
      wrote on last edited by DerReisende
      #29

      I downloaded Hengstler's windows driver with the SDK and in the header file it is quite obvious that Dm functions are Document Manager functions, Dc functions belong to the document.

      You should be able to get the printer name from above via one of those functions:

      HANDLE          WINAPI C56Sdk_PmStartEnumPrinter            (VOID);
      VOID            WINAPI C56Sdk_PmEndEnumPrinter              (HANDLE hPrinter);
      LPSTR           WINAPI C56Sdk_PmEnumPrinter                 (HANDLE hPrinter, BOOL fReset);
      BOOL            WINAPI C56Sdk_PmEnumPrinterName             (HANDLE hPrinter, char * pszBuff, WORD wBuffSize, BOOL fReset);
      
      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #30

        Wouldn't it be better to ask the vendor of this library instead? I mean - you bought it from them so they have to give support. We can only do wild guessing...

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        D 1 Reply Last reply
        1
        • Christian EhrlicherC Christian Ehrlicher

          Wouldn't it be better to ask the vendor of this library instead? I mean - you bought it from them so they have to give support. We can only do wild guessing...

          D Offline
          D Offline
          DerReisende
          wrote on last edited by
          #31

          @Christian-Ehrlicher The driver/sdk is free, it contains exe binaries of the examples and the source code. I is only MFC or .NET code that needs to be read. It shouldn't be too difficult.

          1 Reply Last reply
          0
          • D Damian7546

            The big problem will be lack of description function in this library.

            Below is a example send text to printer:

            void CC56SdkDemo01DlgMain::OnBnPrintout()
            {
               CComboBox * pPrinterList;  // Pointer to combo box item
              
               //-- Get printer list (dialog item combo box)
               if ((pPrinterList = ((CComboBox *) this->GetDlgItem(IDC_COMBO_PRINTER_LIST))) != NULL) {
            
                  INT iPrinterSel; // Selected printer
             
                  //-- Determine selected printer
                  if ((iPrinterSel = pPrinterList->GetCurSel()) != CB_ERR) {
             
                     LPSTR lpszPrinter = NULL;  // Printer name
            
                     //-- Allocate memory for this printer and get name from combo box
                     if (    ((lpszPrinter = (LPSTR) malloc(pPrinterList->GetLBTextLen(iPrinterSel)+1)) != NULL) 
                          && (pPrinterList->GetLBText(iPrinterSel, lpszPrinter) != CB_ERR)
                        ) {
            
                        HANDLE hDocument; // Handle to document 
             
                        //-- Start this document
                        if ((hDocument = C56Sdk_DmStartDocument(lpszPrinter, "C56SdkDemo01")) != NULL) {
            
                           //-- Add print speed setup to document
                           { 
                              CComboBox  * pPrintSpeedList; 
            
                              //-- Get dialog item of print speed list
                              if ((pPrintSpeedList = ((CComboBox *) this->GetDlgItem(IDC_COMBO_PRINT_SPEED))) != NULL) {
            
                                 //-- Set selected print speed 
                                 switch (pPrintSpeedList->GetCurSel()) {
                                    case 0:  C56Sdk_DcAddPrintSpeed(hDocument, C56PS_LOW);      break;
                                    case 1:  C56Sdk_DcAddPrintSpeed(hDocument, C56PS_MEDIUM_2); break;
                                    case 2:  C56Sdk_DcAddPrintSpeed(hDocument, C56PS_MEDIUM_1); break;
                                    case 3:  C56Sdk_DcAddPrintSpeed(hDocument, C56PS_HIGH);     break;
                                    default: C56Sdk_DcAddPrintSpeed(hDocument, C56PS_MEDIUM_2); break;
                                 }
                              }
                           }
            
                           //-- Add print quality setup to document
                           { 
                              CComboBox  * pPrintQualityList; 
            
                              //-- Get dialog item of print quality list
                              if ((pPrintQualityList = ((CComboBox *) this->GetDlgItem(IDC_COMBO_PRINT_QUALITY))) != NULL) {
            
                                 //-- Set selected print quality 
                                 switch (pPrintQualityList->GetCurSel()) {
                                    case 0:  C56Sdk_DcAddPrintQuality(hDocument, C56PQ_LOW);   break;
                                    case 1:  C56Sdk_DcAddPrintQuality(hDocument, C56PQ_HIGH);  break;
                                    default: C56Sdk_DcAddPrintQuality(hDocument, C56PQ_LOW);   break;
                                 }
             
                                 //-- Set impressed energy correction to ...
                                 C56Sdk_DcAddImprEnergyCorrection(hDocument, 50);
                              }
                           }
            
                           //-- Set print mode to 8x16 (for the initial linefeed)
                           C56Sdk_DcAddPrintMode(hDocument, C56PM_FONT_08X16);
             
                           //-- Set initial linefeeds to power up the motor 
                           C56Sdk_DcAddLineFeed(hDocument, 1);
            
                           //-- Add text to print to document
                           { 
                              CEdit  * pTextToPrint; // Pointer to text to print box
            
                              //-- Get text to print (dialog item edit box)
                              if ((pTextToPrint = ((CEdit *) this->GetDlgItem(IDC_EDIT_TEXTTOPRINT))) != NULL) {
            
                                 char szTextToPrint[2000+1]; // Buffer for text
            
                                 //-- Get text to print
                                 if (pTextToPrint->GetWindowText(szTextToPrint, sizeof(szTextToPrint)-1) > 0) {
            
                                    //-- Set print mode to 8x16 (as initial text)
                                    //.. disable reverse printing
                                    //.. select primary font
                                    //.. etc. etc. etc.
                                    { 
                                       C56Sdk_DcAddPrintMode(hDocument, C56PM_FONT_08X16);
                                       C56Sdk_DcAddDisableReversePrinting(hDocument);     
                                       C56Sdk_DcAddExtRegCharSet(hDocument, FALSE);
                                    }
            
                                    //-- Add "text to print" to document data
                                    C56Sdk_DcAddText(hDocument, szTextToPrint);
                                 }
                              }
                           }
            
                           //-- Set print mode to 8x16 (for the final linefeeds)
                           C56Sdk_DcAddPrintMode(hDocument, C56PM_FONT_08X16);
            
                           //-- Add final linefeeds to get text out of the shoot
                           C56Sdk_DcAddLineFeed(hDocument, 50);
            
                           //-- Print document and get job number
                           m_bJobNr = C56Sdk_DmPrintDocument(hDocument);
            
                           //-- End of document
                           C56Sdk_DmEndDocument(hDocument);
                        }
                     }
            
                     //-- Free memory allocated for printer name
                     if (lpszPrinter) free(lpszPrinter); lpszPrinter = NULL;
                  }
               }
            }
            
            

            Some functions can be confused by the name but what is C56Sdk_DmStartDocument
            Can anyone tell me what this function is for:
            hDocument = C56Sdk_DmStartDocument(lpszPrinter, "C56SdkDemo01") ?

            lpszPrinter - is a name of printer driver, and hDocument ?

            D Offline
            D Offline
            DerReisende
            wrote on last edited by
            #32

            @Damian7546 C56SdkDemo01 example shows how to enumerate the printers in BOOL CC56SdkDemo01DlgMain::OnInitDialog.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Damian7546
              wrote on last edited by Damian7546
              #33

              @DerReisende I have a printer name , I published my calss , which one return printer name:

              #include "c56sdkapp.h"
              #include <QDebug>
              C56SdkApp::C56SdkApp()
              {
              
              }
              void C56SdkApp::AvailablePrinters()
              {
                  QString lpszPrinter; // Name of printer
                  HANDLE hEnumPrinter; // Handle for enumeration
                  //-- Start access SDK to go through all C-56 printers
                  if ((hEnumPrinter = C56Sdk_PmStartEnumPrinter()) != NULL) {
              
                      //-- Go through all C-56 printers
                      for ( lpszPrinter = C56Sdk_PmEnumPrinter(hEnumPrinter, TRUE); lpszPrinter != NULL ; lpszPrinter = C56Sdk_PmEnumPrinter(hEnumPrinter, FALSE))
                      {
                         //-- List printer to console
                          qDebug()<< "Printer:" << lpszPrinter;
                      }
                  }
              
              }
              

              but I askd about hDocument = C56Sdk_DmStartDocument(lpszPrinter, "C56SdkDemo01") I read name printer, but I do not know what is the second parametr "C56SdkDemo01" To run any function we need hDocument, what is it ?

              D 1 Reply Last reply
              0
              • D Damian7546

                @DerReisende I have a printer name , I published my calss , which one return printer name:

                #include "c56sdkapp.h"
                #include <QDebug>
                C56SdkApp::C56SdkApp()
                {
                
                }
                void C56SdkApp::AvailablePrinters()
                {
                    QString lpszPrinter; // Name of printer
                    HANDLE hEnumPrinter; // Handle for enumeration
                    //-- Start access SDK to go through all C-56 printers
                    if ((hEnumPrinter = C56Sdk_PmStartEnumPrinter()) != NULL) {
                
                        //-- Go through all C-56 printers
                        for ( lpszPrinter = C56Sdk_PmEnumPrinter(hEnumPrinter, TRUE); lpszPrinter != NULL ; lpszPrinter = C56Sdk_PmEnumPrinter(hEnumPrinter, FALSE))
                        {
                           //-- List printer to console
                            qDebug()<< "Printer:" << lpszPrinter;
                        }
                    }
                
                }
                

                but I askd about hDocument = C56Sdk_DmStartDocument(lpszPrinter, "C56SdkDemo01") I read name printer, but I do not know what is the second parametr "C56SdkDemo01" To run any function we need hDocument, what is it ?

                D Offline
                D Offline
                DerReisende
                wrote on last edited by DerReisende
                #34

                @Damian7546 Why dont you look at the other samples? lpszDocument seems to be just a name for the document as it changes in all other examples as well. And by trial and error setting it to "whateverIwanttonamemydocument" this should work as well.

                What is a HANDLE? See https://stackoverflow.com/questions/902967/what-is-a-windows-handle for explanation and https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types for the definition. Basically it is a void*to a structure that is used internally. What is inside this structure is irrelevant as you have multiple functions to properly manipulate it.

                I can't see any problems that will prevent you from using the Sdk. Even at beginner level with all the examples it looks fairly simple to write a small demo to print something and then extend on the knowledge. Or as @Christian-Ehrlicher said: Maybe ask the vendor as I dont have such a printer but even with example 01 I really think I would be able to print a hello world on it and extend this behaviour.

                D 2 Replies Last reply
                0
                • D DerReisende

                  @Damian7546 Why dont you look at the other samples? lpszDocument seems to be just a name for the document as it changes in all other examples as well. And by trial and error setting it to "whateverIwanttonamemydocument" this should work as well.

                  What is a HANDLE? See https://stackoverflow.com/questions/902967/what-is-a-windows-handle for explanation and https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types for the definition. Basically it is a void*to a structure that is used internally. What is inside this structure is irrelevant as you have multiple functions to properly manipulate it.

                  I can't see any problems that will prevent you from using the Sdk. Even at beginner level with all the examples it looks fairly simple to write a small demo to print something and then extend on the knowledge. Or as @Christian-Ehrlicher said: Maybe ask the vendor as I dont have such a printer but even with example 01 I really think I would be able to print a hello world on it and extend this behaviour.

                  D Offline
                  D Offline
                  Damian7546
                  wrote on last edited by Damian7546
                  #35

                  @DerReisende said in Qt and USB Thermal Printer:

                  And by trial and error setting it to "whateverIwanttonamemydocument" this should work as well.

                  You are right

                  1 Reply Last reply
                  0
                  • D DerReisende

                    @Damian7546 Why dont you look at the other samples? lpszDocument seems to be just a name for the document as it changes in all other examples as well. And by trial and error setting it to "whateverIwanttonamemydocument" this should work as well.

                    What is a HANDLE? See https://stackoverflow.com/questions/902967/what-is-a-windows-handle for explanation and https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types for the definition. Basically it is a void*to a structure that is used internally. What is inside this structure is irrelevant as you have multiple functions to properly manipulate it.

                    I can't see any problems that will prevent you from using the Sdk. Even at beginner level with all the examples it looks fairly simple to write a small demo to print something and then extend on the knowledge. Or as @Christian-Ehrlicher said: Maybe ask the vendor as I dont have such a printer but even with example 01 I really think I would be able to print a hello world on it and extend this behaviour.

                    D Offline
                    D Offline
                    Damian7546
                    wrote on last edited by Damian7546
                    #36
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kunoichi15901
                      wrote on last edited by
                      #37
                      This post is deleted!
                      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