java打印标签(机型TOSHIBA条码打印机B-EX4T)

java打印标签

    • 实现方式
    • 标签效果
    • 代码
    • 获取更多相关资料
    • 实现rfid写入功能

实现方式

打印机设置网络ip
java获取socket连接,调用TPCL指令

标签效果

java打印标签(机型TOSHIBA条码打印机B-EX4T)_第1张图片

代码

package org.jeecg.modules.invinfo.util;

import org.jeecg.modules.invinfo.vo.BatKcInventoryDetailVo;
import org.springframework.beans.factory.annotation.Value;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

public class TCPClient {

    public static void printTag(BatKcInventoryDetailVo batKcInventoryDetailVo,String ipAddress,int port) throws IOException {
        Socket clientSocket = new Socket(ipAddress,port);
        DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream() );
        String batteryIndex = batKcInventoryDetailVo.getBatteryIndex();
        outToServer.writeBytes("{D0800,0750,0400|}" + '\n'); //定义标签纸 600mm*375mm,标签间隔3mm
        outToServer.writeBytes("{C|}" + '\n'); //缓存初始化
        outToServer.writeBytes("{XB00;0475,0100,T,L,10,A,0,M2="+batteryIndex+"|}" + '\n');//二维码
        //电池名称
        String batteryName = "{PC002;0075,0080,2,3,r,00,B="+batKcInventoryDetailVo.getBatteryName()+"|}"+ '\n';
        writeChines(outToServer,batteryName);
        String ratedVoltage = "{PC002;0075,0150,2,2,r,00,B=额定电压(V):"+batKcInventoryDetailVo.getRatedVoltage()+"|}"+ '\n';
        writeChines(outToServer,ratedVoltage);
        String ratedCurrent = "{PC003;0075,0220,2,2,r,00,B=额定电流(A):"+batKcInventoryDetailVo.getRatedCurrent()+"|}"+ '\n';
        writeChines(outToServer,ratedCurrent);
        outToServer.writeBytes("{PC000;0075,0370,1,1,A,00,B="+batteryIndex+"|}" + '\n');
        outToServer.writeBytes("{XS;I,0001,0002C6111|}" + '\n');//输出1张
        clientSocket.close();
    }

    private static void writeChines(DataOutputStream outToServer,String str) throws IOException {
        byte[] bytes = str.getBytes("GBK");
        outToServer.write(bytes);
    }
}

获取更多相关资料

百度搜索:东芝中国
java打印标签(机型TOSHIBA条码打印机B-EX4T)_第2张图片

java打印标签(机型TOSHIBA条码打印机B-EX4T)_第3张图片

java打印标签(机型TOSHIBA条码打印机B-EX4T)_第4张图片
购买TOSHIBA条码打印机B-EX4T+RFID模块

实现rfid写入功能

    public static void main(String[] args) {
        Socket clientSocket = new Socket();
        try {
            clientSocket.connect(new InetSocketAddress("192.168.4.198", 8000), 2000);
            DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
            String batteryIndex = "8577c2a8974749a9bd49f9ccea9c9f71";
            outToServer.writeBytes("{Z2;2,+000+000+00+000+00+00+00+001014|}" + '\n');//rfid写入需要设置
            outToServer.writeBytes("{Z2;3,42400020052000520+000040600106050|}" + '\n');//rfid写入需要设置
            outToServer.writeBytes("{D0500,0500,0500|}" + '\n'); //定义标签纸 50mm*50mm,标签间隔3mm
            outToServer.writeBytes("{C|}" + '\n'); //缓存初始化
            outToServer.writeBytes("{XB00;0310,0100,T,L,08,A,0,M2=" + batteryIndex + "|}" + '\n');//二维码
            outToServer.writeBytes("{XB01;0000,0000,r,T24,G2,B01=" + batteryIndex + "|}" + '\n');rfid写入
            //电池名称
            String batteryName = "{PC002;0015,0080,15,2,r,00,B=" + "蓄电池测试标签打印" + "|}" + '\n';
            writeChines(outToServer, batteryName);
            String ratedVoltage = "{PC002;0015,0150,15,15,r,00,B=额定电压(V):" + "1.5" + "|}" + '\n';
            writeChines(outToServer, ratedVoltage);
            String ratedCurrent = "{PC003;0015,0210,15,15,r,00,B=额定电流(A):" + "1.5" + "|}" + '\n';
            writeChines(outToServer, ratedCurrent);
            outToServer.writeBytes("{PC000;0015,0370,1,1,A,00,B=" + batteryIndex + "|}" + '\n');
            outToServer.writeBytes("{XS;I,0001,0002C6111|}" + '\n');//输出1张
            clientSocket.close();
        }catch (IOException e) {
            System.out.println("111");
        }
        System.out.println("222");
    }

重要:
{Z2;2,+000+000+00+000+00+00+00+001014|}
{Z2;3,42400020052000520+000040600106050|}
{XB01;0000,0000,r,T24,G2,B01=AABBCCDDEEFFAABBCCDDEEFF|}

打印机遇到问题:更换标签纸后,卡纸(屏幕显示,实际未卡纸)

设置:启动标签自动校正(官网视频教程)
java打印标签(机型TOSHIBA条码打印机B-EX4T)_第5张图片

你可能感兴趣的:(JAVA,java)