Epson TM U295 User Manual - Page 41
Using ESC/POS commands
View all Epson TM U295 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 41 highlights
6.2.7. Using ESC/POS commands The following example shows how you can use the Win32 API to transmit ESC/POS commands directly to the printer. For more details, refer to the Win32 API help information. Public Type DOCINFO pDocName As String pOutputFile As String pDatatype As String End Type ''Win32 API external reference definitions Public Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long Public Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long Public Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long Public Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" _ (ByVal pPrinterName As String, phPrinter As Long, ByVal pDefault As Long) As Long Public Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" _ (ByVal hPrinter As Long, ByVal Level As Long, pDocInfo As DOCINFO) As Long Public Declare Function StartPagePrinter Lib "winspool.drv" _ (ByVal hPrinter As Long) As Long Public Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrinter As Long, _ pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long '##### Source Code ##### Dim lhPrinter As Long Dim lReturn As Long Dim lpcWritten As Long Dim lDoc As Long Dim sWrittenData As String Dim MyDocInfo As DOCINFO lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0) If lReturn = 0 Then MsgBox "Open Printer Error!" End If MyDocInfo.pDocName = "SAMPLE" MyDocInfo.pOutputFile = vbNullString MyDocInfo.pDatatype = vbNullString lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo) Call StartPagePrinter(lhPrinter) ''Output ESC/POS commands and the string to be displayed sWrittenData = Chr(&H1B) + "=" + Chr(&H2) 'Select the peripheral device. sWrittenData = sWrittenData + Chr(&H1B) + "t" + Chr(&H0) 'Select the character code table. sWrittenData = sWrittenData + Chr(&H1B) + "R" + Chr(&H0) 'Select international characters. sWrittenData = sWrittenData + "SEIKO EPSON ESC/POS" 'String to be displayed. lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, Len(sWrittenData), lpcWritten) lReturn = EndPagePrinter(lhPrinter) lReturn = EndDocPrinter(lhPrinter) lReturn = ClosePrinter(lhPrinter) TITLE EPSON TM Printer Driver User's Manual SHEET REVISION 1.60 NO NEXT 42 SHEET 41