Skip to content

Commit

Permalink
提交资料
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangle committed Jul 24, 2023
1 parent 025edff commit 3dd08b0
Show file tree
Hide file tree
Showing 5 changed files with 455 additions and 92 deletions.
19 changes: 19 additions & 0 deletions dmeo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//string to utf8
function strToUtf8Bytes(text) {
const code = encodeURIComponent(text)
const bytes = []
for (let i = 0;i < code.length;i++) {
const c = code.charAt(i)
if (c === '%') {
const hex = code.charAt(i + 1) + code.charAt(i + 2)
const hexval = parseInt(hex, 16)
bytes.push(hexval)
i += 2
} else {
bytes.push(c.charCodeAt(0))
}
}
return bytes
}

console.log(strToUtf8Bytes('达摩克利斯之剑'))
Binary file not shown.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h1 id ="demo">tsc 打印</h1>
</form>


<form action= "/128M" method= "post" >
<form action= "/128C" method= "post" >
<input type="submit" id="btn3" name="btn1" value="Post_Test">
</form>

Expand Down
217 changes: 126 additions & 91 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var closeport;
var sendcommand_utf8;
var sendcommand_binary;
var windowsfont;
var nobackfeed;


var urlencodedParser = bodyParser.urlencoded({extended: false});
app.use(bodyParser.urlencoded({
Expand Down Expand Up @@ -50,6 +52,11 @@ app.post('/128B', urlencodedParser, function (req, res) {
res.redirect(req.get('referer'));
});

app.post('/128C', urlencodedParser, function (req, res) {
printfile128C();
res.redirect(req.get('referer'));
});


try {
openport = edge.func({
Expand Down Expand Up @@ -137,6 +144,16 @@ try {
console.log(error);
}

try {
nobackfeed = edge.func({
assemblyFile: 'tsclibnet.dll',
typeName: 'TSCSDK.node_driver',
methodName: 'nobackfeed'
});
} catch (error) {
console.log(error);
}

try {
sendcommand_utf8 = edge.func({
assemblyFile: 'tsclibnet.dll',
Expand Down Expand Up @@ -166,115 +183,133 @@ try {
} catch (error) {
console.log(error);
}
//string to utf8
function strToUtf8Bytes(text) {
const code = encodeURIComponent(text)
const bytes = []
for (let i = 0;i < code.length;i++) {
const c = code.charAt(i)
if (c === '%') {
const hex = code.charAt(i + 1) + code.charAt(i + 2)
const hexval = parseInt(hex, 16)
bytes.push(hexval)
i += 2
} else {
bytes.push(c.charCodeAt(0))
}
}
return bytes
}


function printfile() {
var font_variable = {x: '50', y: '50', fonttype: '3', rotation: '0', xmul: '1', ymul: '1', text: 'Font Test'}
// let bytes = strToUtf8Bytes('达摩克利斯之剑');
// console.log("%c printfile🚀", "color: red;font-size: 18px", bytes);
var windowsfont_variable = {
x: 50,
y: 250,
fontheight: 64,
x: 20,
y: 0,
fontheight: 63,
rotation: 0,
fontstyle: 0,
fontstyle: 5,
fontunderline: 0,
szFaceName: 'Arial',
content: 'Windowsfont Test'
szFaceName: 'Microsoft YaHei',
content: '此条指令用来清除打印机中的图像缓存'
// content: bytes
}
var barcode_variable = {
x: '50',
y: '100',
type: '128',
height: '70',
readable: '0',
rotation: '0',
narrow: '3',
wide: '1',
code: '123456'
var windowsfont_unicode = {
x: 20,
y: 0,
fontheight: 63,
rotation: 0,
fontstyle: 5,
fontunderline: 0,
szFaceName: 'Microsoft YaHei',
content: '此条指令用来清除打印机中的图像缓存'
// content: bytes
}
var label_variable = {quantity: '1', copy: '1'};
// 测试一代码
/*for (let i = 0; i < 2; i++) {
openport('TSC TE244', true);
sendcommand(`SIZE 4.00 3.00`, true);
// sendcommand(`SIZE 2.33 1.56`, true);
sendcommand(`DIRECTION 1`, true); // 待确定
// sendcommand(`CLS`, true); // 此条指令用来清除打印机中的图像缓存
clearbuffer('', true); // 此条指令用来清除打印机中的图像缓存
sendcommand(`BARCODE 5,10,"128",50,1,0,2,2,"23030700011${i+1}"`, true);
sendcommand('PRINT 1,1', true);
// sendcommand('CLS', true); // test code 此条指令用来清除打印机中的图像缓存
// sendcommand('EOJ', true) // test code
closeport('', true);*/

// 1. printlabel/PRINT 1,1
// 2. size 精确度问题
// 3. CLS, clearbuffer问题
// 测试二代码, size 问题导致
for (let i = 0; i < 1; i++) {
openport('TSC TE244', true);
clearbuffer('', true); // 此条指令用来清除打印机中的图像缓存
// sendcommand(`CLS`, true); // 此条指令用来清除打印机中的图像缓存
// sendcommand(`SIZE 4.00 3.00`, true);
sendcommand(`DIRECTION 1`, true); // 待确定
// sendcommand(`BARCODE 5,10,"128",50,1,0,2,2,"23030700011${i+1}"`, true);
windowsfont_variable.y = 0
let height = 0
for (let j = 0; j < 5; j++) {
// windowsfont_variable.y = windowsfont_variable.y + 2
// windowsfont(`20,${windowsfont_variable.y},63,0,5,"Arial","达摩克利斯之剑"`, true);

// windowsfont(windowsfont_variable, true)
// sendcommand(`TEXT 100,${windowsfont_variable.y},"SimSun",0,18,18,"达摩克利斯之剑"`, true);
// height = height + 2
// sendcommand(`BARCODE 5,${height},"128",50,1,0,3,3,"AUDAUFADADCRQERHADADSF${i+1}"`, true);
}
sendcommand('PRINT 1,1', true); // printlabel(label_variable, true); 问题
// sendcommand('CLS', true); // test code 此条指令用来清除打印机中的图像缓存
// sendcommand('EOJ', true) // test code
// clearbuffer('', true); // 此条指令用来清除打印机中的图像缓存
closeport('', true);
}
}

function printfile128B() {
var label_variable = {quantity: '1', copy: '1'};
openport('TSC TE244', true);

clearbuffer('', true);
/* sendcommand(`TEXT 0,0,"0",0,12,12,"1234567890-0"`, true);
sendcommand(`TEXT 0,40,"0",0,12,12,"1234567890-1"`, true);
sendcommand(`TEXT 0,80,"0",0,12,12,"1234567890-2"`, true);
sendcommand(`TEXT 0,120,"0",0,12,12,"1234567890-3"`, true);
sendcommand(`TEXT 0,270,"0",0,12,12,"1234567890-4"`, true);
sendcommand(`TEXT 0,180,"0",0,12,12,"1234567890-4"`, true);
sendcommand(`TEXT 0,200,"0",0,12,12,"1234567890-5"`, true);
// sendcommand(`TEXT 100,250,"0",0,12,12,"1234567890-6"`, true);
// sendcommand(`TEXT 0,280,"0",0,12,12,"1234567890-6.1"`, true);
sendcommand(`TEXT 0,290,"0",0,12,12,"1234567890-6.2"`, true);*/

// sendcommand(`BARCODE 20,10,"128M",70,1,0,2,2,"CP-OXL-0232A00858"`, true);

// sendcommand(`TEXT 0,0,"0",0,12,12,"1-1 0 M"`, true);
// sendcommand(`BARCODE 100,50,"128",70,1,0,1,1,"CP-OXL-0208-CP-CP"`, true);
// sendcommand(`BARCODE 50,150,"128M",70,0,0,2,2,"CP-OXL-0232A00858"`, true);
// sendcommand(`BARCODE 100,150,"128M",70,1,0,1,1,"CP-OXL-0208-CP-CP"`, true);

sendcommand(`BARCODE 5,10,"128",50,1,0,2,2,"230307000161"`, true);
sendcommand(`BARCODE 5,100,"128",50,1,0,2,2,"230307000161"`, true);
sendcommand(`BARCODE 5,190,"128",50,1,0,3,3,"230307000161"`, true);
sendcommand(`BARCODE 5,250,"128",50,1,0,4,4,"230307000161"`, true);

// sendcommand(`BARCODE 5,50,"128M",50,1,0,2,2,"230307000162"`, true);
// sendcommand(`BARCODE 5,150,"128M",50,1,0,3,3,"230307000162"`, true);

// sendcommand(`BARCODE 5,50,"EAN128",50,1,0,2,2,"230307000163"`, true);
// sendcommand(`BARCODE 5,150,"EAN128",50,1,0,3,3,"230307000163"`, true);

// sendcommand(`BARCODE 5,50,"93",50,1,0,2,2,"230307000163"`, true);
// sendcommand(`BARCODE 5,150,"93",50,1,0,3,3,"230307000163"`, true);


/*sendcommand(`TEXT 0,0,"0",0,12,12,"2-2 0 M"`, true);
sendcommand(`BARCODE 20,10,"128",70,1,0,2,2,"CP-OXL-0232A008581"`, true);
// sendcommand(`BARCODE 50,150,"128M",70,0,0,2,2,"CP-OXL-0232A00858"`, true);
sendcommand(`BARCODE 20,150,"128M",70,1,0,2,2,"210-000-2A00858M1"`, true);*/


// sendcommand('CODEPAGE UTF-8', true);
// sendcommand('TEXT 0,50,"YZ",0,1,1,"中文测试"', true); // 可行
// sendcommand('TEXT 0,20,"arial12",0,2,2,"中文测试01AAABBB-TEST"', true); // 可行
// sendcommand('TEXT 0,80,"arial14",0,2,2,"中文测试01AAABBB-TEST"', true); // 可行r
sendcommand('DMATRIX 10,110,400,400,"DMATRIX EXAMPLE 1"', true); // 可行
// sendcommand('TEXT 200,100,"zhongwen",0,2,2,"中文测试01234AAABBB-TEST"', true); // 可行

// sendcommand('TEXT 200,120,"song22",0,1,1,"中文测试123AAABBB-TEST"', true); // 可行
// sendcommand('TEXT 200,180,"song22",0,3,3,"中文测试123AAABBB-TEST"', true); // 可行
// sendcommand('TEXT 0,100,"0",0,16,16,"hello world!"', true);
printlabel(label_variable, true);

//var selftest_command = 'SELFTEST\r\n';
//var arr = [];
//for (var i = 0; i < selftest_command.length; ++i)
// arr.push(selftest_command.charCodeAt(i));
//var selftest_command_buffer = new Uint8Array(arr);
//sendcommand_binary(selftest_command_buffer, true);

// nobackfeed()
closeport('', true);
}

function printfile128B() {
var font_variable = {x: '50', y: '50', fonttype: '3', rotation: '0', xmul: '1', ymul: '1', text: 'Font Test'}
var windowsfont_variable = {
x: 20,
y: 100,
fontheight: 64,
rotation: 0,
fontstyle: 3,
fontunderline: 0,
szFaceName: 'Arial',
content: '达摩克利斯之剑'
}
var barcode_variable = {
x: '50',
y: '100',
type: '128',
height: '70',
readable: '0',
rotation: '0',
narrow: '3',
wide: '1',
code: '123456'
}
function printfile128C() {
// var windowsfont_variable = {
// x: 20,
// y: 100,
// fontheight: 64,
// rotation: 0,
// fontstyle: 3,
// fontunderline: 0,
// szFaceName: 'Arial',
// content: '达摩克利斯之剑'
// }
var font_variable = { x: '50', y: '50', fonttype: '0', rotation: '0', xmul: '1', ymul: '1', text: 'Font Test' }
var label_variable = {quantity: '1', copy: '1'};

openport('TSC TE244', true);
clearbuffer('', true);
windowsfont(windowsfont_variable, true);
printerfont(font_variable, true);
// windowsfont(0, 50, 64, 0, 0, 0, "Arial", "Windows Arial Font Test")
// windowsfont(windowsfont_variable);

// sendcommand(`SIZE 1.07, 1.07`, true);
// sendcommand(`SIZE 2.33, 1.54`, true);
// sendcommand(`BOX 0, 0, 480, 320, 10`, true);
Expand Down
Loading

0 comments on commit 3dd08b0

Please sign in to comment.