使用字符串命令在 ESC/POS 中打印(Neodynamic PHP Web 客户端)

问题描述 投票:0回答:2

我正在尝试使用字符串命令剪纸,剪纸命令为

0x1D 0x56
,但它不起作用,是否是 Neodynamic PHP Web 客户端的其他代码。

到目前为止我做了什么,

    $useDefaultPrinter = ($qs['useDefaultPrinter'] === 'checked');
    $printerName = urldecode($qs['printerName']);

    //Create ESC/POS commands for sample receipt
    $esc = '0x1B'; //ESC byte in hex notation
    $newLine = '0x0A'; //LF byte in hex notation
     
    $cmds = '';
    $cmds = $esc . "@"; //Initializes the printer (ESC @)
    $cmds .= $esc . '!' . '0x38'; //Emphasized + Double-height + Double-width mode selected (ESC ! (8 + 16 + 32)) 56 dec => 38 hex
    $cmds .= 'BILL'; //text to print
    $cmds .= $newLine . $newLine;
    $cmds .= $esc . '!' . '0x00'; //Character font A selected (ESC ! 0)
    $cmds .= 'COOKIES                   5.00'; 
    $cmds .= $newLine;
    $cmds .= 'MILK 65 Fl oz             3.78';
    $cmds .= $newLine;
    $cmds .= 'TOTAL                     8.78';
    $cmds .= $newLine;
    $cmds .= '0x1D 0x56'; //This is not working...Im getting character 'V' as output

    //Create a ClientPrintJob obj that will be processed at the client side by the WCPP
    $cpj = new ClientPrintJob();
    //set ESCPOS commands to print...
    $cpj->printerCommands = $cmds;
    $cpj->formatHexValues = true;
     
    if ($useDefaultPrinter || $printerName === 'null') {
        $cpj->clientPrinter = new DefaultPrinter();
    } else {
        $cpj->clientPrinter = new InstalledPrinter($printerName);
    }

    //Send ClientPrintJob back to the client
    ob_start();
    ob_clean();
    header('Content-type: application/octet-stream');
    echo $cpj->sendToClient();
    ob_end_flush();
    exit();

我尝试过的代码有

'0x1D 0x56'
$esc . '!' . '0x1D 0x56'
'0x1D 0x56 <m>'

php thermal-printer escpos neodynamic
2个回答
0
投票

要剪纸,请使用

$cmds .= $esc . "m"
而不是
$cmds .= '0x1D 0x56';


0
投票

“esc m”已经过时,所以最好使用“选择切割模式并切割纸张”:

    $cmds .= hex2bin('1D5600'); // Full cut
    $cmds .= hex2bin('1D5601'); // Partial cut

https://download4.epson.biz/sec_pubs/pos/reference_en/escpos/gs_cv.html

© www.soinside.com 2019 - 2024. All rights reserved.