Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Print Test</title>
  6.  
  7. <script type="text/javascript" src="epos-2.3.0.js"></script>
  8.  
  9. <script type="text/javascript">
  10. var ePosDev = new epson.ePOSDevice();
  11.  
  12. function connect()
  13. {
  14. var ipAddress = '192.168.1.23';
  15. var port = '9100';
  16. ePosDev.connect(ipAddress, port, callback_connect);
  17. }
  18.  
  19. function callback_connect(resultConnect)
  20. {
  21. alert('Callback Called');
  22. var deviceId = 'local_printer';
  23. var options = {'crypto' : false, 'buffer' : false};
  24. alert(resultConnect);
  25.  
  26. if ((resultConnect == 'OK') || (resultConnect == 'SSL_CONNECT_OK')) {
  27. alert('Connected!');
  28. ePosDev.createDevice(deviceID,ePosDev.DEVICE_TYPE_PRINTER,options,callback_createDevice);
  29. }
  30. else
  31. {
  32. alert('Not Connected!');
  33. }
  34. }
  35.  
  36. var printer = null;
  37.  
  38. function callback_createDevice(deviceObj, errorCode)
  39. {
  40. if (deviceObj === null)
  41. {
  42. //Displays an error message if the system fails to retrieve the Printer object
  43. return;
  44. }
  45. printer = deviceObj;
  46. //Registers the print complete event
  47. printer.onreceive = function(response)
  48. {
  49. if (response.success)
  50. {
  51. //Displays the successful print message
  52. }
  53. else
  54. {
  55. //Displays error messages
  56. }
  57. };
  58. }
  59.  
  60. function createData()
  61. {
  62. printer.addTextAlign(printer.ALIGN_CENTER);
  63. printer.addText("Hello World\n");
  64. }
  65.  
  66. function send()
  67. {
  68. if (ePosDev.isConnected)
  69. {
  70. printer.send();
  71. }
  72. }
  73. </script>
  74. </head>
  75. <body>
  76. <input type="button" onclick="connect()" value="Connect" />
  77. <input type="button" onClick="send()" value="Print Hello World" />
  78. </body>
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement