2014-02-27 105 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

相关问题