2012-10-11 81 views
0

這就是我能找到的所有東西,它們都不起作用。使用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 

什麼也沒有發生。這就像打印機根本沒有被代碼所觸及。

UPDATE 方法1是我可以打印文件的最接近的東西。執行該命令後,狀態欄上顯示一個打印機圖標,表示打印機已被調用並從我的代碼接收數據,但仍然沒有打印。幫助...

+0

如果您還沒有這麼做,請重新添加打印機,然後從製造商/驅動程序選擇對話框中選擇generic-> text only –

+0

Hi Alex。謝謝,但問題仍然存在。 – Quannt

回答

0

好吧,所以這就是我如何設法讓這項工作。不是我想要的最佳選擇,但是...它的工作原理。

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文件。最後,使用shell來執行它

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

,如果它被映射到並行或串行通訊端口,可以直接打開:

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

hi肖恩,我的打印機目前通過USB連接。我去端口設置,切換到LPT1:並按照您的代碼,並得到錯誤:運行時錯誤53,文件未找到。與Com1一樣 – Quannt

0

我喜歡做的是做一些類似的方法2的東西,但它保存到一個文件(原始打印機數據),然後將文件複製到UNC路徑。

文件拷貝 「C:\ label.txt」 \計算機名\共享名

這對我的作品。

+0

Hi Yosem,通過UNC路徑,您是指打印機的路徑?我現在通過USB電纜連接到我的筆記本電腦。 – Quannt

+0

我只是分享它(將它命名爲Zebra或其他),然後將該文件複製到\\ 127.0.0.1 \ Zebra(作爲UNC路徑) – Yosem

+0

我試過這段代碼FileCopy「C:\\ test.txt」,「 ZDesigner LP 2844「和」C:\\ test.txt「,」USB001「。我會嘗試你的現在:D – Quannt

0

我的解決方案斑馬

  1. 在Windows中創建然後發送給原始文件到這臺打印機
  2. 在Zebra打印機的高級設置通用/文本打印機 - >其他人, 有一個直通字符。您可以將原始文本發送到此打印機。
相關問題