2014-02-27 109 views
1

參考(EPOS-打印API/XML):
https://download.epson-biz.com/modules/community/index.php?content_subject=ePOS-Print%20API/XML

簡單的測試網站:

print.html

<script type="text/javascript" src="js/epos-print-3.0.0.js"></script> 

代碼

function printTest() { 
    // open print dialog 
    $('#print').dialog('open'); 

    // 
    // build print data 
    // 

    // create print data builder object 
    var builder = new epson.ePOSBuilder(); 

    builder.addText('Test Print\n'); 
    builder.addFeedLine(1); 

    // append paper cutting 
    builder.addCut(); 

    // 
    // send print data 
    // 

    // create print object 
    var url = 'http://192.168.x.x/cgi-bin/epos/service.cgi?devid=local_printer&timeout=6000'; 
    var epos = new epson.ePOSPrint(url); 

    // register callback function 
    epos.onreceive = function (res) { 
     // close print dialog 
     $('#print').dialog('close'); 
     // print failure 
     if (!res.success) { 
      // show error message 
      $('#receive').dialog('open'); 
     } 
    } 

    // register callback function 
    epos.onerror = function (err) { 
     // close print dialog 
     $('#print').dialog('close'); 
     // show error message 
     $('#error').dialog('open'); 
    } 

    // send 
    epos.send(builder.toString()); 

} 

請求service.cgi:

<?xml version="1.0" encoding="utf-8"?> 
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Body> 
     <epos-print xmlns="http://www.epson-pos.com/schemas/2011/03/epos-print"> 
      <text>Test Print!!&#10;</text> 
      <feed line="1"/> 
      <cut/> 
     </epos-print> 
    </s:Body> 
</s:Envelope> 

響應:EPSON API手冊(狀態:00000001 =從TM打印機無響應)

<?xml version="1.0" encoding="UTF-8" ?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Body> 
     <response success="false" code="EX_TIMEOUT" status="1" xmlns="http://www.epson-pos.com/schemas/2011/03/epos-print" /> 
    </soapenv:Body> 
</soapenv:Envelope> 

當我改變服務URL一個其他設備

var url = 'http://192.168.x.x/cgi-bin/epos/service.cgi?devid=other_printer&timeout=6000'; 

請求正確

Sucess="False" code="DeviceNotFound" status="0" 

Windows應用程序例如同樣的反應:

Public Class Form1 

    ' URL of ePOS-Print supported TM printer 
    Private address As String = "http://192.168.x.x/cgi-bin/epos/service.cgi?devid=local_printer&timeout=10000" 

    ' XML namespace 
    Private soap As XNamespace = "http://schemas.xmlsoap.org/soap/envelope/" 
    Private epos As XNamespace = "http://www.epson-pos.com/schemas/2011/03/epos-print" 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 

     ' Create print document 
     Dim req As XElement = _ 
      <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
       <s:Body> 
        <epos-print xmlns="http://www.epson-pos.com/schemas/2011/03/epos-print"> 
         <text lang="en" smooth="true">Intelligent Printer&#10;</text> 
         <cut/> 
        </epos-print> 
       </s:Body> 
      </s:Envelope> 

     ' Send print document 
     Dim client As WebClient = New WebClient() 
     client.Headers.Set("Content-Type", "text/xml; charset=utf-8") 
     AddHandler client.UploadStringCompleted, AddressOf UploadStringCompletedEventHandler 
     client.UploadStringAsync(New Uri(address, UriKind.Absolute), req.ToString()) 

    End Sub 

    ' Receive response document 
    Private Sub UploadStringCompletedEventHandler(sender As Object, e As UploadStringCompletedEventArgs) 

     If (e.Error IsNot Nothing) Then 
      MessageBox.Show(e.Error.Message) 
     Else 
      'Parse response document 
      Dim res As XElement = XElement.Parse(e.Result) 
      Dim c = From el In res.Descendants(epos + "response") Select el.Attribute("success") 
      MessageBox.Show(c.First().Value) 
     End If 

    End Sub 

End Class 

回答

0

兩種可能性:

您的打印機有一個設備ID,它是從local_printer不同 - 檢查配置頁面。

ePOSPrint()函數不允許直接發送URL。我有我的第一個測試頁面(我的工作,現在建設爲同一臺打印機的應用程序)看起來比你的不同:

var epos = new epson.ePOSPrint(); 
epos.address = 'http://192.168.0.1/cgi-bin/epos/services.cgi?devid=local_printer&timeout=6000'; 

注意空()以及如何鏈接初始化後交付。


檢查後,它看起來像其他一些測試代碼我有沒有提交URL作爲參數傳遞給函數就像你擁有了它,所以我只能猜測是,設備ID local_printer不正確。

+0

但是我們怎樣才能得到設備ID,因爲在配置頁面中沒有什麼像DeviceId? – Kashyap

+0

我再也無法訪問打印機了,但我相信「local_printer」可能是打印機的原始名稱(=設備ID),所以我會先從該打印機開始。 – semmelbroesel

+0

#semmelbroesel。我發現它上面有些打印機配置頁面是不同的。我有TM82-I,它有很多選擇,然後TM-U220-B和TM-88V-i。在配置頁面中,我可以設置設備ID。 TM-82-I。 – Kashyap

相關問題