1

Similar to this question I want to print a bitmap image on a TSC label printer using the TSPL programming language, but the answer there doesn't show how to pass the byte array to sendcommand. Also, I'm doing this in Node.js. The documentation has this pseudo code example:

enter image description here

Sample code from TSC has this Node.js example that only shows how to print text:

...
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);
}

I have made the byte array (using Buffer.from(array) where array is a list of decimal numbers representing each byte) - but how do I pass the byte array to sendcommand which seems to normally take string arguments?

TheStoryCoder
  • 3,403
  • 6
  • 34
  • 64

2 Answers2

0

I am working on this too, and I finally understand what should be done. We should use sendcommand_binary instead of sendcommand. In the below code, I used the cmd described in the tsc document. Attached please find the result image.

    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);

enter image description here

Gena Kwee
  • 31
  • 4
-1

There are actually a number of different sendcommand methods which can be used to send TSPL commands to the printer taking different arguments, encoding and timers. Here are their signatures copied out of the SDK:

public String sendcommand(String message)
public String sendcommand(String message, int timer)
public String sendcommand(byte[] message) 
public String sendcommand(byte[] message, int timer)
public String sendcommandUTF8(String message)
public String sendcommandBig5(String message)
public String sendcommandGB2312(String message)
public String sendcommandGB2312(String message, int timer)
Mag Riada
  • 1
  • 1
  • 1
    I don't think those are available in Node.JS - so not really relevant... – TheStoryCoder Mar 06 '20 at 13:03
  • Apologies, I overlooked that and went straight to my experience with the Android SDK assuming they'd be the same as the documentation had me stumped at the time. Sorry I couldn't help you. – Mag Riada Mar 06 '20 at 13:22