通过IP地址连接斑马打印机

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
49
50
51
52
53
54
55
56
57
58
59
60
61
export default function print(op, ipAddress, port) {
//使用ZPL指令打印
var ZPLString = `^XA
^MD30
^CWJ,E:SIMSUN.TTF^FS
^FO40,30^AJN,42,42^CI28^FD生产订单号:^FS^CI28
^FO320,30^AJN,42,42^FH\^CI28^FD` + op.aufnr + `^FS^CI28
^FO640,30^AJN,42,42^CI28^FD数量:^FS^CI28
^FO750,30^AJN,42,42^FH\^CI28^FD` + op.lmnga + `^FS^CI27
^FO40,90^AJN,42,42^CI28^FD本阶料号:^FS^CI27
^FO320,90^AJN,42,42^FH\^CI28^FD` + op.matnr + `^FS^CI27
^FO40,150^AJN,42,42^CI28^FD品名规格:^FS^CI27
^FO320,150^AJN,42,42^FH\^CI28^FD` + op.maktx + `^FS^CI27
^FO40,210^AJN,42,42^CI28^FD炉号:^FS^CI27
^FO320,210^AJN,42,42^FH\^CI28^FD` + op.charg0 + `^FS^CI27
^FO40,380^AJN,42,42^CI28^FD填写人:^FS^CI27
^FO320,380^AJN,42,42^FH\^CI28^FD` + op.name + `^FS^CI27
^FO640,380^AJN,42,42^CI28^FD日期:^FS^CI28
^FO750,380^AJN,42,42^FH\^CI28^FD` + op.date + `^FS^CI27
^FO40,438^AJN,42,42^CI28^FD备注:^FS^CI28
^PQ1,,,Y
^XZ`


if (plus.os.name == "Android") {
var Socket = plus.android.importClass("java.net.Socket");
var PrintWriter = plus.android.importClass("java.io.PrintWriter");
var BufferedWriter = plus.android.importClass("java.io.BufferedWriter");
var OutputStreamWriter = plus.android.importClass("java.io.OutputStreamWriter");
var BufferedReader = plus.android.importClass("java.io.BufferedReader");
var InputStreamReader = plus.android.importClass("java.io.InputStreamReader");


var StrictMode = plus.android.importClass("android.os.StrictMode");
var Build = plus.android.importClass("android.os.Build");
if (Build.VERSION.SDK_INT > 9) {
var policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
console.log("连接服务器中...")
console.log("ip..." + ipAddress, port)
//port * 1 传递过的值默认为字符串 无效 转为数值
var socket = new Socket(`${ipAddress}`, port * 1); // "172.16.19.***", 91**
socket.setSoTimeout(5000);
var inputStreamReader = new InputStreamReader(socket.getInputStream());
var socketReader = new BufferedReader(inputStreamReader);

var outputStreamWriter = new OutputStreamWriter(socket.getOutputStream());
var bufferWriter = new BufferedWriter(outputStreamWriter);
var socketWriter = new PrintWriter(bufferWriter, true);
socketWriter.println(ZPLString);

console.log("socketWriter..." + socketWriter)
var msgBeReceived = socketReader.readLine();
console.log(msgBeReceived);

}


}

打印不出中文解决办法

指令:^XA^WD*:*.**^XZ

作用:打印出所有内存信息,可以用来寻找字体信息.TTF文件