Qt and USB Thermal Printer
-
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 ?@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?
-
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);
-
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...
-
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...
@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.
-
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 ?@Damian7546
C56SdkDemo01
example shows how to enumerate the printers inBOOL CC56SdkDemo01DlgMain::OnInitDialog
. -
@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 ? -
@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 ?@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.
-
@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.
@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
-
@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.
This post is deleted! -
This post is deleted!