使用 Visual Basic (MS Access 2000) 将原始数据发送到 ZPL 打印机



这就是我能找到的全部内容,它们都不起作用。

选项比较数据库选项显式

  Private Type DOCINFO
      pDocName As String
      pOutputFile As String
      pDatatype As String
  End Type
  Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal _
     hPrinter As Long) As Long
  Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal _
     hPrinter As Long) As Long
  Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal _
     hPrinter As Long) As Long
  Private Declare Function OpenPrinter Lib "winspool.drv" Alias _
     "OpenPrinterA" (ByVal pPrinterName As String, phPrinter As Long, _
      ByVal pDefault As Long) As Long
  Private Declare Function StartDocPrinter Lib "winspool.drv" Alias _
     "StartDocPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, _
     pDocInfo As DOCINFO) As Long
  Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal _
     hPrinter As Long) As Long
  Private Declare Function WritePrinter Lib "winspool.drv" (ByVal _
     hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, _
     pcWritten As Long) As Long
  Private Sub TEST()
      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("ZDesigner LP 2844", lhPrinter, 0)
      If lReturn = 0 Then
          MsgBox "The Printer Name you typed wasn't recognized."
          Exit Sub
      End If
      MyDocInfo.pDocName = "AAAAAA"
      MyDocInfo.pOutputFile = vbNullString
      MyDocInfo.pDatatype = vbNullString
      lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
      Call StartPagePrinter(lhPrinter)
       sWrittenData = "N" & vbFormFeed
      sWrittenData = sWrittenData & "q609" & vbFormFeed
      sWrittenData = sWrittenData & "Q203,26" & vbFormFeed
      sWrittenData = sWrittenData & "B26,26,0,UA0,2,2,152,B," & Chr(34) & "603679025109" & Chr(34) & vbFormFeed
      sWrittenData = sWrittenData & "A253,26,0,3,1,1,N," & Chr(34) & "SKU 6205518 MFG 6354" & Chr(34) & vbFormFeed
      sWrittenData = sWrittenData & "A253,56,0,3,1,1,N," & Chr(34) & "2XIST TROPICAL BEACH" & Chr(34) & vbFormFeed
      sWrittenData = sWrittenData & "A253,86,0,3,1,1,N," & Chr(34) & "STRIPE SQUARE CUT TRUNK" & Chr(34) & vbFormFeed
      sWrittenData = sWrittenData & "A253,116,0,3,1,1,N," & Chr(34) & "BRICK" & Chr(34) & vbFormFeed
      sWrittenData = sWrittenData & "A253,146,0,3,1,1,N," & Chr(34) & "X-LARGE" & Chr(34) & vbFormFeed
      sWrittenData = sWrittenData & "P1,1" & vbFormFeed
      lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
         Len(sWrittenData), lpcWritten)
      lReturn = EndPagePrinter(lhPrinter)
      lReturn = EndDocPrinter(lhPrinter)
      lReturn = ClosePrinter(lhPrinter)
  End Sub

方法 2

Option Compare Database
Private Sub crtLabel()

Dim prtDevice As String
Dim strQuote As String
strQuote = Chr(34)
prtDevice = "ZDesigner LP 2844" ' whatever device Access currently has as the default. I have the user select a printer prior to printing, which sets the Access defaut printer
' open printer port
Open prtDevice For Output As #1
' initialize printer
Print #1, "OD" & vbCrLf
Print #1, "N" & vbCrLf
Print #1, "O" & vbCrLf
Print #1, "Q545,B12+23" & vbCrLf
Print #1, "q262" & vbCrLf
Print #1, "UN" & vbCrLf
Print #1, "rN" & vbCrLf
Print #1, "N" & vbCrLf
Print #1, "A4,94,3,3,1,1,N," & strQuote & "1803" & strQuote & vbCrLf
Print #1, "A36,74,3,3,1,1,N," & strQuote & "B" & strQuote & vbCrLf
Print #1, "A64,94,3,3,1,1,N," & strQuote & "079" & strQuote & vbCrLf
Print #1, "A112,8,0,2,1,1,N," & strQuote & strQuote & vbCrLf ' you can replace any string like "1803" with a string variable like SID or AID that gets passed to the sub
Print #1, "A112,32,0,3,1,1,N," & strQuote & strQuote & vbCrLf  ' same here
Print #1, "A112,64,0,1,1,1,N," & strQuote & "04/13/2009" & strQuote & vbCrLf
Print #1, "A130,100,0,1,1,1,N," & strQuote & "SWAB, NASO" & strQuote & vbCrLf
Print #1, "A4,100,0,1,1,1,N," & strQuote & "C146536" & strQuote & vbCrLf
Print #1, "B53,130,0,1,1,0,47,N," & strQuote & "2009-06868" & strQuote & vbCrLf
Print #1, "A112,188,0,1,1,1,N," & strQuote & "" & strQuote & vbCrLf
Print #1, "P1,1" & vbCrLf
Print #1, "O" & vbCrLf
' close printer port
Close #1

End Sub

运行函数后没有任何反应。就像打印机根本没有被代码触及一样。

更新方法 1 是我能得到的最接近打印文件的东西。执行命令后,状态栏上有一个打印机图标,显示打印机已被调用并从我的代码接收数据,但仍然完全没有打印。帮助。。。

如果它映射到并行或 COM 端口,您可以直接打开它:

open "LPT1:" For Output as #1
' or open "COM1:"
print #1, "SomeData"
Close #1

我喜欢做的是执行类似于方法 2 的操作,但将其保存到文件(原始打印机数据),然后将文件复制到 UNC 路径。

文件副本 "C:\label.txt" \计算机名\共享名

这对我有用。

好的,

这就是我设法完成这项工作的方式。不是我想要的最佳选择,但是...它有效。

1)我使用相同的函数,但用C++写的,取自这里 http://support.microsoft.com/kb/138594/EN-US

// RawDataToPrinter - sends binary data directly to a printer
   // 
   // Params:
   //   szPrinterName - NULL terminated string specifying printer name
   //   lpData        - Pointer to raw data bytes
   //   dwCount       - Length of lpData in bytes
   // 
   // Returns: TRUE for success, FALSE for failure.
   // 
   BOOL RawDataToPrinter(LPSTR szPrinterName, LPBYTE lpData, DWORD dwCount)
   {
     HANDLE     hPrinter;
     DOC_INFO_1 DocInfo;
     DWORD      dwJob;
     DWORD      dwBytesWritten;
     // Need a handle to the printer.
     if( ! OpenPrinter( szPrinterName, &hPrinter, NULL ) )
       return FALSE;
     // Fill in the structure with info about this "document."
     DocInfo.pDocName = "My Document";
     DocInfo.pOutputFile = NULL;
     DocInfo.pDatatype = "RAW";
     // Inform the spooler the document is beginning.
     if( (dwJob = StartDocPrinter( hPrinter, 1, (LPSTR)&DocInfo )) == 0 )
     {
       ClosePrinter( hPrinter );
       return FALSE;
     }
     // Start a page.
     if( ! StartPagePrinter( hPrinter ) )
     {
       EndDocPrinter( hPrinter );
       ClosePrinter( hPrinter );
       return FALSE;
     }
     // Send the data to the printer.
     if( ! WritePrinter( hPrinter, lpData, dwCount, &dwBytesWritten ) )
     {
       EndPagePrinter( hPrinter );
       EndDocPrinter( hPrinter );
       ClosePrinter( hPrinter );
       return FALSE;
     }
     // End the page.
     if( ! EndPagePrinter( hPrinter ) )
     {
       EndDocPrinter( hPrinter );
       ClosePrinter( hPrinter );
       return FALSE;
     }
     // Inform the spooler that the document is ending.
     if( ! EndDocPrinter( hPrinter ) )
     {
       ClosePrinter( hPrinter );
       return FALSE;
     }
     // Tidy up the printer handle.
     ClosePrinter( hPrinter );
     // Check to see if correct number of bytes were written.
     if( dwBytesWritten != dwCount )
       return FALSE;
     return TRUE;
   }

我得到了文件 RAWPRN.EXE从那里,将我的 EPL 代码放在 txt 文件中。最后,使用命令行管理程序执行它

Dim RetVal
RetVal = Shell("cmd .exe /c C:rawprintRawPrint.exe ""ZDesigner LP 2844"" ""C:eplcode.txt""", 1)

我的斑马技术解决方案

  1. 在 Windows 中创建通用/文本打印机,然后将原始文件发送到此打印机
  2. 在 Zebra 打印机高级设置 ->其他设置中,有一个直通字符。您可以将原始文本发送到此打印机。

我使用此解决方案,效果完美。

  1. 按照此配方制作通用文本打印机
  2. 将打印机映射到 LPT1,使用 "net use lpt1 \\computername\printername/persistent:yes
  3. 使用以下方法将文件发送到打印机:

VBA

Public function runCmd(cmd as String) as Boolean
  Dim wsh As Object
  Dim cmdToRun As String
  Dim Sts As Integer
  Set wsh = VBA.CreateObject("WScript.Shell")   
  cmdToRun = "cmd.exe /c " & Quote(cmd)
  'Run & wait to complete
  Sts = wsh.Run(cmdToRun, 0, 1)
  If Sts = 0 Then
    runCmd = True
  Else
    MsgBox cmd & vbCrLf & "Failed with error code " & Sts
  End If
  Set wsh = Nothing
End Function

使用 cmd : : "cd {dir} & Print \D:LPT1 [file [file]]"

相关内容

  • 没有找到相关文章

最新更新