首先要有设备的IP,端口号一般默认的是9100
- //打印设备网络IP
- etIp.setText("192.168.2.249");
- //打印设备端口号 一般为9100
- etPort.setText("9100");
之后建立连接:
- client = new Socket(etIp.getText().toString(), port);
- //打印输出 控制输出字符集位GBK 否则中文乱码
- PrintWriter oStream = new PrintWriter((new OutputStreamWriter(client.getOutputStream(),"GBK")),true);
发送打印指令:
- /* 纵向放大一倍 */
- oStream.write(0x1c);
- oStream.write(0x21);
- oStream.write(8);
- /* 横向纵向都放大一倍 */
- // oStream.write(0x1c);
- // oStream.write(0x21);
- // oStream.write(12);
-
-
- oStream.println("\t\t"+"餐厅订单"+"\n");
- String printStr = "交易流水:"+serNo+
- "\n"+"商户名称:"+"测试商户"+
- "\n"+"订单号:"+orderNo+
- "\n"+"卡号:"+CardNo+
- "\n"+"时间:"+time+
- "\n"+"交易金额:"+Amount+
- "\n"+"**********************************************************";
- oStream.print(printStr);
-
- oStream.println("\n\n");
这里还是给上完整DEMO
这里还有csdn下载连接http://download.csdn.net/detail/u013065139/7956445
-
666.76 KB, 下载次数: 3, 下载积分: e币 -10 元
demo和java打印文档