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) { 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) var socket = new Socket(`${ipAddress}`, port * 1); 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);
}
}
|