首页 > 解决方案 > 在 TSC 打印机上打印位图 - 使用 Node.js

问题描述

此问题类似,我想使用 TSPL 编程语言在 TSC 标签打印机上打印位图图像,但那里的答案没有显示如何将字节数组传递给sendcommand. 另外,我在 Node.js 中这样做。该文档有这个伪代码示例:

在此处输入图像描述

TSC 的示例代码有这个 Node.js 示例,它只显示如何打印文本:

...
function printfile() {
    var address = { ipaddress: '192.168.0.103', port: '9100', delay:'500' };

    var font_variable = { x: '50', y: '50', fonttype: '3', rotation: '0', xmul: '1', ymul: '1', text: 'Font Test' }
    var barcode_variable = { x: '50', y: '100', type: '128', height: '70', readable: '0', rotation: '0', narrow: '3', wide: '1', code: '123456' }
    var label_variable = { quantity: '1', copy: '1' };
    openport(address, true);
    var status = printer_status(300, true);
    clearbuffer('', true);
    printerfont(font_variable, true);
    barcode(barcode_variable, true);
    sendcommand('TEXT 250,50,\"0\",0,10,10,\"Text Test!!\"', true);
    printlabel(label_variable, true);
    closeport(2000, true);
}

我已经制作了字节数组(使用Buffer.from(array)wherearray是代表每个字节的十进制数字列表) - 但是如何将字节数组传递给sendcommand似乎通常采用字符串参数的字节数组?

标签: node.jsprintingtspl

解决方案


我也在做这个,我终于明白应该做什么了。我们应该使用sendcommand_binary而不是sendcommand. 在下面的代码中,我使用了 tsc 文档中描述的 cmd。附件请找到结果图像。

    openport('TSC TE310', true);
    setup({ width: '104 mm', height: '83 mm', speed: '1', density: '15', sensor: '0', vertical: '3 mm', offset: '1 mm' }, true);
    clearbuffer('', true);

    var cmd1 = 'CLS\r\nBITMAP 200,200,2,16,0,';
    var img = ["00", "00", "00", "00", "00", "00", "07", "FF", "03", "FF", "11", "FF", "18", "FF", "1C", "7F", "1E", "3F", "1F", "1F", "1F", "8F", "1F", "C7", "1F", "E3", "1F", "E7", "1F", "FF", "1F", "FF"];
    var cmd2 = '\r\nPRINT 1,1\r\n'
    var arr = [];

    for (var i = 0; i < cmd1.length; ++i) {
        arr.push(cmd1.charCodeAt(i));
    }
    for (var i = 0; i < img.length; ++i) {
        arr.push(parseInt(img[i], 16));
    }
    for (var i = 0; i < cmd2.length; ++i) {
        arr.push(cmd2.charCodeAt(i));
    }

    var buffer = new Uint8Array(arr);
    
    var hex = "";
    arr.map(value => {
        hex += value.toString(16) + ' ';
    })
// hex is the same as the hexadecimal column in the tsc document example
// 43 4c 53 d a 42 49 54 4d 41 50 20 32 30 30 2c 32 30 30 2c 32 2c 31 36 2c 30 2c 0 0 0 0 0 0 7 ff 3 ff 11 ff 18 ff 1c 7f 1e 3f 1f 1f 1f 8f 1f c7 1f e3 1f e7 1f ff 1f ff d a 50 52 49 4e 54 20 31 2c 31 d a
    console.log(hex);

    sendcommand_binary(buffer, true);

    closeport('', true);

在此处输入图像描述


推荐阅读