Epson TM-T20II-i Server Direct Print Users Manual for TM-i firmware ver.4.1 - Page 38

Program Example

Page 38 highlights

Program Example See the following programming data (file name: Test_print.php) 38

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

38
Program Example
See the following programming data (file name: Test_print.php)
<?php
header('Content-Type: text/xml; charset=UTF-8');
define("REQUEST_XML_PATH", "demo/request/sample.xml");
define("RESPONSE_XML_PATH", "demo/response/sample.xml");
if (isset($_POST["ConnectionType"])) {
$http_request = $_POST["ConnectionType"];
}
if ($http_request == 'GetRequest') {
# send print data
# ID
#
#
$shop_id = $_POST["ID"];
# create print data
if (file_exists(REQUEST_XML_PATH)) {
# return print data
$handle = fopen(REQUEST_XML_PATH, "r");
fpassthru($handle);
fclose($handle);
# move file
rename(REQUEST_XML_PATH, RESPONSE_XML_PATH);
}
} else if ($http_request == 'SetResponse') {
# get print result
$xml = simplexml_load_string($_POST["ResponseFile"]);
$version = $xml['Version'];
if ($version == '1.00') {
# save log
$fhandle = @fopen("ResultPrint.log", "wt");
fprintf($fhandle, "PrintResponseInfo Version %s\n", $version);
foreach ($xml->response as $response) {
fprintf($fhandle, "----------\nsuccess : %s\ncode : %s\n",
$response['success'], $response['code']);
}
fclose($fhandle);
} else if ($version == '2.00') {
# save log
$fhandle = @fopen("ResultPrint.log", "wt");
fprintf($fhandle, "PrintResponseInfo Version %s\n", $version);
foreach ($xml->ePOSPrint as $eposprint) {
$devid = $eposprint->Parameter->devid;
$printjobid = $eposprint->Parameter->printjobid;
$response = $eposprint->PrintResponse->response;
fprintf($fhandle, "----------\ndevid : %s\nprintjobid : %s\nsuccess :
%s\ncode : %s\n", $devid, $printjobid, $response['success'],
$response['code']);
}
fclose($fhandle);
} else {
# Ignore other version
}
} else {
# Ignore other connectionType than GetRequest and SetResponse.
}
?>