Prechádzať zdrojové kódy

打印机连接优化

qzyReal 5 dní pred
rodič
commit
32b812e518

+ 9 - 8
config.xml

@@ -2,8 +2,8 @@
 
 <config>
     <managerSetting>
-        <enable>false</enable>
-        <host>192.168.3.15</host>
+        <enable>true</enable>
+        <host>192.168.3.67</host>
         <beatPort>8010</beatPort>
         <serverUrl>http://127.0.0.1:9191</serverUrl>
     </managerSetting>
@@ -12,7 +12,7 @@
         <!--本机IP-->
         <ip>10.3.2.153</ip>
         <channelName>3号地磅</channelName>
-        <channelCode>DLP01</channelCode>
+        <channelCode>db01</channelCode>
         <twinChannelCode></twinChannelCode>
         <!--共生通道地址-->
         <twinService></twinService>
@@ -66,7 +66,7 @@
         </caputreSetting>
         <!--串口服务器地址-->
         <serialSetting>
-            <host>192.168.127.254</host>
+            <host>10.26.6.92</host>
             <weighbridge>
                 <enable>false</enable>
                 <port>4003</port>
@@ -134,16 +134,17 @@
             <!--通道重置-->
             <name>PLC.IDLE</name>
             <actionList>
-                <action>CENTER.FINISH_WEIGHT</action>
-                <action>CENTER.TIMER_SLEEP(200)</action>
                 <action>WEIGHBRIDGE.CLEAN</action>
                 <action>CENTER.TIMER_SLEEP(100)</action>
                 <action>PLC.RED_LIGHT_OFF</action>
                 <action>CENTER.TIMER_SLEEP(300)</action>
                 <action>PLC.GREEN_LIGHT_ON</action>
                 <action>PLC.RAILING_RISE_OFF</action>
-                <action>PLC.BTN_DISABLE</action>
-                <action>LED.INIT</action>
+                <action>PLC.RELEASE_GATE_DOWN</action>
+                <action>LED.LED_SHOW_CONTENT(02|${platNo})</action>
+                <action>LED.LED_SHOW_CONTENT(03|${weight})</action>
+                <action>LED.LED_SHOW_CONTENT(01|${channel})</action>
+                <action>LED.LED_SHOW_CONTENT(04|信息采集中)</action>
             </actionList>
         </event>
 

+ 4 - 4
pom.xml

@@ -170,15 +170,15 @@
                     <!--联运中心-->
 <!--                    <code>D72E7F75D4CDEEFAD7AC77891557F586D41D8CD98F00B204E9800998ECF8427ED41D8CD98F00B204E9800998ECF8427E</code>-->
                     <!--北海无人地磅-->
-<!--                    <code>AE135DDFE7E3871BE848301327CA8E2ED41D8CD98F00B204E9800998ECF8427ED41D8CD98F00B204E9800998ECF8427E</code>-->
+                    <code>AE135DDFE7E3871BE848301327CA8E2ED41D8CD98F00B204E9800998ECF8427ED41D8CD98F00B204E9800998ECF8427E</code>
                     <!--南京-->
 <!--                    <code>A4CFD53BE12CC512727611ACFC1EE05ED41D8CD98F00B204E9800998ECF8427ED41D8CD98F00B204E9800998ECF8427E</code>-->
                     <!--限定区域-->
 <!--                    <code>C41BF0CE8FF4E89D45E95A3AFB46E2E9D41D8CD98F00B204E9800998ECF8427ED41D8CD98F00B204E9800998ECF8427E</code>-->
                     <!--联运中心无人地磅-->
-                    <code>
-                        C8B3CC11C158AD38AE69D6DB58E99BF8D41D8CD98F00B204E9800998ECF8427ED41D8CD98F00B204E9800998ECF8427E
-                    </code>
+<!--                    <code>-->
+<!--                        C8B3CC11C158AD38AE69D6DB58E99BF8D41D8CD98F00B204E9800998ECF8427ED41D8CD98F00B204E9800998ECF8427E-->
+<!--                    </code>-->
                     <packages>com.gzlh</packages> <!--可以多个-->
                     <!--                    <cfgfiles>application.yml</cfgfiles>-->
                     <excludes>org.spring</excludes>

+ 2 - 9
src/main/java/com/gzlh/api/OpenApi.java

@@ -6,7 +6,6 @@ import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.ReflectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.spring.SpringUtil;
-import cn.hutool.json.JSON;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.gzlh.bus.EventDataManager;
@@ -27,16 +26,13 @@ import com.gzlh.device.capture.event.CaptureEvent;
 import com.gzlh.device.capture.service.CaptureHandlerService;
 import com.gzlh.device.face.service.FaceService;
 import com.gzlh.device.face.hkutils.UserManage;
-import com.gzlh.device.led.utils.FengLiYuanPackUtils;
-import com.gzlh.device.passport.bo.PassportParamDTO;
 import com.gzlh.device.plc.event.PLCEvent;
 import com.gzlh.device.plc.handler.PLCHadnler;
 import com.gzlh.device.print.bo.BeiHaiWeightReport;
 import com.gzlh.device.print.bo.WeightReport;
+import com.gzlh.device.print.test.JMPrintThreadB;
 import com.gzlh.device.print.test.JMPrintThread;
 import com.gzlh.device.led.utils.LedOptions;
-import com.gzlh.device.print.test.PrintWithChapter;
-import com.gzlh.device.voice.client.VoiceNettyConfig;
 import com.gzlh.entity.AddFaceBO;
 import com.gzlh.entity.PicBO;
 import com.gzlh.entity.ReqBO;
@@ -50,10 +46,6 @@ import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
 import java.io.*;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.Base64;
@@ -255,6 +247,7 @@ public class OpenApi {
                 .setWWB_GTVOL(weightReport.getWwbGtvol())
                 .setWWB_PKSPAC(weightReport.getWwbPkspac())
                 .setWWB_ID(weightReport.getWwbId())
+                .setWB_MARKERNO(weightReport.getWbMarkern())
                 .setWWB_CAR_WGT(weightReport.getWwbCarWgt())
                 .setTK_REMARK(weightReport.getTkRemark());
         printBO.setTitle(title);

+ 5 - 1
src/main/java/com/gzlh/background/BackgroundClientHandler.java

@@ -104,7 +104,11 @@ public class BackgroundClientHandler extends SimpleChannelInboundHandler<String>
             CommandBO commandBO = JSONUtil.toBean(message, CommandBO.class);
             CommandBO.Command command = commandBO.getCommand();
             if (!StringUtils.isEmpty(command.getExtra())) {
-                LedOptions options = new LedOptions().setLine("03").setShowType("00");
+                String line = SysConfig.serialSetting.getLed().getLine();
+                if (StrUtil.isEmpty(line)) {
+                    line = "03";
+                }
+                LedOptions options = new LedOptions().setLine(line).setShowType("00");
                 SystemObject.ledFactory.handler(SysConfig.serialSetting.getLed().getBrand())
                         .sendMsg(command.getExtra(), options);
             }

+ 1 - 1
src/main/java/com/gzlh/config/ModuleEnum.java

@@ -7,7 +7,7 @@ import lombok.Getter;
 @Getter
 public enum ModuleEnum {
     LED_MODULE("led显示屏","LED"),
-    WEIGHBRIDGE_MODULE("地磅","WEIGHBRIDGE"),
+    WEIGHBRIDGE_MODULE("地磅表头","WEIGHBRIDGE"),
     INFRARED_MODULE("红外","INFRARED"),
     TRAFFIC_MODULE("红绿灯","TRAFFIC"),
     GATE_MODULE("道闸","GATE"),

+ 1 - 1
src/main/java/com/gzlh/device/led/client/LedNettyConfig.java

@@ -89,7 +89,7 @@ public class LedNettyConfig {
     }
 
     public void send(String message) {
-        // log.info("led send:{}", message);
+         log.info("led send:{}", message);
         if (channel != null && channel.isActive()) {
             ByteBuf bufff = Unpooled.buffer();
             bufff.writeBytes(XorUtils.hexString2Bytes(message));

+ 0 - 1
src/main/java/com/gzlh/device/print/client/PrintClientHandler.java

@@ -32,7 +32,6 @@ public class PrintClientHandler extends SimpleChannelInboundHandler<String> {
         log.error("print 客户端 连接断开,10s后进行重连");
         DeviceCache.changeDeviceStatus(ModuleEnum.PRINT_MODULE.getModuleZh(), 0);
         ThreadUtil.sleep(6000);
-        printNettyConfig.connect();
     }
 
     @Override

+ 14 - 70
src/main/java/com/gzlh/device/print/client/PrintNettyConfig.java

@@ -1,10 +1,13 @@
 package com.gzlh.device.print.client;
 
+import com.github.anastaciocintra.escpos.EscPos;
+import com.github.anastaciocintra.output.TcpIpOutputStream;
 import com.gzlh.bus.SysConfig;
 import com.gzlh.config.ModuleEnum;
 import com.gzlh.config.dto.SerialSetting;
 import com.gzlh.config.netty.NettyDecoder;
 import com.gzlh.utils.DeviceCache;
+import com.gzlh.utils.WordHandlerUtils;
 import com.gzlh.utils.XorUtils;
 import io.netty.bootstrap.Bootstrap;
 import io.netty.buffer.ByteBuf;
@@ -18,91 +21,32 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Component;
 
+import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.concurrent.TimeUnit;
 
-@Configuration
+@Component
 @Slf4j
 public class PrintNettyConfig {
 
 
-    @Autowired
-    private PrintClientHandler printClientHandler;
 
-    private Channel channel;
 
-    @Bean("printBootstrap")
-    public Bootstrap bootstrap() {
-        SerialSetting.PrintSetting print = SysConfig.serialSetting.getPrint();
-        String host = print.getIp();
-        int port = print.getPort();
-        if (!print.isEnable()) {
-            return new Bootstrap();
-        }
-        EventLoopGroup group = new NioEventLoopGroup();
-        return new Bootstrap()
-                .group(group)
-                .channel(NioSocketChannel.class)
-                .remoteAddress(host, port)
-                .option(ChannelOption.SO_KEEPALIVE, true)
-                .handler(new ChannelInitializer<SocketChannel>() {
-                    @Override
-                    protected void initChannel(SocketChannel ch) {
-                        try {
-                            ChannelPipeline pipeline = ch.pipeline();
-                            pipeline.addLast(new NettyDecoder());
-                            pipeline.addLast(new StringEncoder(StandardCharsets.UTF_8));
-                            pipeline.addLast("handler", printClientHandler);
-                        } catch (Exception e) {
-                            log.info("error connect:{}", e.getMessage());
-                        }
-                    }
-                });
-    }
 
-    @Bean("printClientHandler")
-    public PrintClientHandler printClientHandler() {
-        return new PrintClientHandler(this);
-    }
 
-    public void connect() {
-        SerialSetting.PrintSetting print = SysConfig.serialSetting.getPrint();
-        String host = print.getIp();
-        int port = print.getPort();
-        ChannelFuture future = bootstrap().connect();
-        future.addListener((ChannelFutureListener) future1 -> {
-            if (future1.isSuccess()) {
-                channel = future1.channel();
-                log.info("print 服务器连接成功,{},{}", host, port);
-                DeviceCache.changeDeviceStatus(ModuleEnum.PRINT_MODULE.getModuleZh(), 1);
-            } else {
-                log.error("-------------print 连接服务器失败,{},{}-----------,进行重连", host, port);
-                future1.channel().eventLoop().schedule(this::connect, 60, TimeUnit.SECONDS);
-            }
-        });
+    public void send( byte[] message) {
+        TcpIpOutputStream tcpIpOutputStream = null;
         try {
-            future.channel().closeFuture().sync();
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-    }
-
-    public void send(String message) {
-        // log.info("led send:{}", message);
-        if (channel != null && channel.isActive()) {
-            ByteBuf bufff = Unpooled.buffer();
-            bufff.writeBytes(XorUtils.hexString2Bytes(message));
-            channel.writeAndFlush(bufff);
-        } else {
-            //log.error("未建立连接,无法发送消息");
+            tcpIpOutputStream = new TcpIpOutputStream(SysConfig.serialSetting.getPrint().getIp(), SysConfig.serialSetting.getPrint().getPort());
+            EscPos escpos = new EscPos(tcpIpOutputStream);
+            escpos.write(message, 0, message.length);
+            escpos.close();
+        } catch (IOException e) {
+            return;
         }
-    }
 
-    public void close() {
-        if (channel != null) {
-            channel.close();
-        }
     }
 
 }

+ 0 - 1
src/main/java/com/gzlh/device/print/handler/IPrintHandler.java

@@ -7,7 +7,6 @@ public interface IPrintHandler {
     PrintBrandType brandType();
 
     void sendMsg( String content);
-    void close();
 
     void handlerMsg(String msg);
 

+ 78 - 18
src/main/java/com/gzlh/device/print/handler/impl/PrintYingMeiHandler.java

@@ -1,7 +1,6 @@
 package com.gzlh.device.print.handler.impl;
 
 
-import ch.qos.logback.core.util.TimeUtil;
 import cn.hutool.cache.CacheUtil;
 import cn.hutool.cache.impl.TimedCache;
 import cn.hutool.core.thread.ThreadUtil;
@@ -19,17 +18,17 @@ import com.gzlh.device.print.bo.BeiHaiWeightReport;
 import com.gzlh.device.print.brand.PrintBrandType;
 import com.gzlh.device.print.client.PrintNettyConfig;
 import com.gzlh.device.print.handler.IPrintHandler;
-import com.gzlh.device.print.test.BeiHaiPrintBO;
 import com.gzlh.device.print.test.JMPrintThread;
+import com.gzlh.entity.DeviceStatus;
 import com.gzlh.entity.ReqBO;
 import com.gzlh.utils.DeviceCache;
-import com.gzlh.utils.EpsonCommands;
 import com.gzlh.utils.WordHandlerUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.nio.charset.Charset;
+import java.io.*;
+import java.net.Socket;
 
 /**
  * 上海仰邦科技股份有限公司BX-5(M)K/6K(YY)-V4.2 led发送处理器
@@ -51,16 +50,10 @@ public class PrintYingMeiHandler implements IPrintHandler {
     @Override
     public void sendMsg(String content) {
         // log.info(PrintBrandType.YING_MEI.getBrand() + "发送消息:{}", content);
-        printNettyConfig.send(content);
+        printNettyConfig.send(WordHandlerUtils.hexToBytes(content));
     }
 
     @Override
-    public void close() {
-        printNettyConfig.close();
-    }
-
-
-    @Override
     public void handlerMsg(String msg) {
         if (StrUtil.equalsIgnoreCase(msg, "FF")) {
             return;
@@ -74,7 +67,7 @@ public class PrintYingMeiHandler implements IPrintHandler {
             binaryString = "0" + binaryString; // 在前面补0
         }
         // 输出二进制字符串
-//        log.info("二进制表示: " + binaryString);
+        log.info("二进制表示: " + binaryString);
         // 检查bit 2的状态
         // bit 2 是从右边数的第3位,对应索引为5(从0开始计数)
         String bit2 = binaryString.charAt(5) + "";
@@ -83,9 +76,66 @@ public class PrintYingMeiHandler implements IPrintHandler {
         DeviceCache.changeDeviceStatus(ModuleEnum.PRINT_MODULE.getModuleZh(), eMsg);
     }
 
+    public static boolean connect = false;
+    // 服务器返回的固定字节数
+    private static final int RESPONSE_LENGTH = 1;
+
     @Override
     public void checkStatus() {
-        sendMsg(STATUS_COMMAND);
+        Socket socket = null;
+        DataOutputStream dataOut = null;
+        DataInputStream dataIn = null;
+        try {
+            // 建立与服务器的连接
+            socket = new Socket(SysConfig.serialSetting.getPrint().getIp(), SysConfig.serialSetting.getPrint().getPort());
+            connect = socket.isConnected();
+
+            // 创建输入输出流
+            dataOut = new DataOutputStream(socket.getOutputStream());
+            dataIn = new DataInputStream(socket.getInputStream());
+
+            // 准备要发送的二进制数据
+            byte[] sendData = WordHandlerUtils.hexToBytes(STATUS_COMMAND);
+
+            // 先发送数据长度,再发送实际数据
+            dataOut.writeInt(sendData.length);
+            dataOut.write(sendData);
+            dataOut.flush();
+
+            // 接收服务器返回的2字节十六进制数据
+            byte[] responseData = new byte[RESPONSE_LENGTH];
+            int bytesRead = dataIn.read(responseData);
+            String hexResponse = bytesToHex(responseData);
+            //log.info("print resp:{}", hexResponse);
+            String eMsg = StrUtil.equals(hexResponse, "06") ? "打印机缺纸" : "";
+            DeviceCache.changeDeviceStatus(ModuleEnum.PRINT_MODULE.getModuleZh(), 1, eMsg);
+        } catch (IOException e) {
+            log.error("print error:{}", e.getMessage());
+            DeviceCache.changeDeviceStatus(ModuleEnum.PRINT_MODULE.getModuleZh(), 0, "打印机离线");
+        } finally {
+            // 关闭资源
+            try {
+                if (dataIn != null) dataIn.close();
+                if (dataOut != null) dataOut.close();
+                if (socket != null) socket.close();
+                connect = false;
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+
+    }
+
+    /**
+     * 将字节数组转换为十六进制字符串
+     */
+    private static String bytesToHex(byte[] bytes) {
+        StringBuilder sb = new StringBuilder();
+        for (byte b : bytes) {
+            // 格式化为两位十六进制数,不足两位前面补0
+            sb.append(String.format("%02X", b));
+        }
+        return sb.toString();
     }
 
     @Override
@@ -97,6 +147,20 @@ public class PrintYingMeiHandler implements IPrintHandler {
 
     @Override
     public void reqPrint() {
+        String line = SysConfig.serialSetting.getLed().getLine();
+        if (StrUtil.isEmpty(line)) {
+            line = "03";
+        }
+        LedOptions options = new LedOptions().setLine(line);
+        DeviceStatus.Device device = DeviceCache.getDevice(ModuleEnum.PRINT_MODULE.getModuleZh());
+        if (StrUtil.isNotEmpty(device.getEMsg())) {
+            ledFactory.handler(SysConfig.serialSetting.getPrint().getBrand()).sendMsg(device.getEMsg(), options);
+            return;
+        }
+        if (device.getStatus() == 0) {
+            ledFactory.handler(SysConfig.serialSetting.getPrint().getBrand()).sendMsg("打印机离线", options);
+            return;
+        }
         ReqBO reqBO = EventDataManager.getCacheData();
         String bodyParams = JSONUtil.toJsonStr(reqBO);
         if (StrUtil.isEmpty(reqBO.getCarNo())) {
@@ -120,11 +184,7 @@ public class PrintYingMeiHandler implements IPrintHandler {
                     BeiHaiWeightReport beiHaiWeightReport = JSONUtil.toBean(reportData, BeiHaiWeightReport.class);
                     doPrint(beiHaiWeightReport);
                 } else {
-                    String line = SysConfig.serialSetting.getLed().getLine();
-                    if (StrUtil.isEmpty(line)) {
-                        line = "03";
-                    }
-                    LedOptions options = new LedOptions().setLine(line);
+
                     ledFactory.handler(SysConfig.serialSetting.getLed().getBrand()).sendMsg(jsonObject.getStr("msg"), options);
                 }
             }

+ 28 - 33
src/main/java/com/gzlh/device/print/test/JMPrintThread.java

@@ -1,22 +1,19 @@
 package com.gzlh.device.print.test;
 
 import cn.hutool.core.codec.Base64Decoder;
-import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.NumberUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.spring.SpringUtil;
 import cn.hutool.json.JSONUtil;
 import com.github.anastaciocintra.escpos.EscPos;
-import com.github.anastaciocintra.escpos.EscPosConst;
-import com.github.anastaciocintra.escpos.Style;
 import com.github.anastaciocintra.escpos.image.*;
 import com.github.anastaciocintra.output.TcpIpOutputStream;
 import com.gzlh.bus.SysConfig;
-import com.gzlh.config.SystemObject;
 import com.gzlh.device.led.factory.LedFactory;
 import com.gzlh.device.led.utils.LedOptions;
 import com.gzlh.device.print.bo.BeiHaiWeightReport;
+import com.gzlh.device.print.handler.impl.PrintYingMeiHandler;
 import com.gzlh.utils.EpsonCommands;
 import com.gzlh.utils.WordHandlerUtils;
 import lombok.extern.slf4j.Slf4j;
@@ -25,8 +22,6 @@ import javax.imageio.ImageIO;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.io.OutputStream;
-import java.net.Socket;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 
@@ -44,31 +39,45 @@ public class JMPrintThread implements Runnable {
 
     @Override
     public void run() {
+        LedFactory ledFactory = SpringUtil.getBean(LedFactory.class);
+        String line = SysConfig.serialSetting.getLed().getLine();
+        if (StrUtil.isEmpty(line)) {
+            line = "03";
+        }
+        LedOptions options = new LedOptions().setLine(line);
+        int count = 10;
+        while (PrintYingMeiHandler.connect) {
+            count--;
+            if (count <= 0) {
+                ledFactory.handler(SysConfig.serialSetting.getLed().getBrand()).sendMsg("打印机连接异常", options);
+                return;
+            }
+            ThreadUtil.sleep(100);
+        }
         try {
             log.info("start print:{}", JSONUtil.toJsonStr(printBO));
-            SystemObject.printFactory.handler(SysConfig.serialSetting.getPrint().getBrand()).close();
             Charset charset = Charset.forName("GB2312");
-            String title = "    "+SysConfig.serialSetting.getPrint().getPrintTitle() + "\n";
+            String title = "    " + SysConfig.serialSetting.getPrint().getPrintTitle() + "\n";
             TcpIpOutputStream tcpIpOutputStream = new TcpIpOutputStream(SysConfig.serialSetting.getPrint().getIp(), SysConfig.serialSetting.getPrint().getPort());
             EscPos escpos = new EscPos(tcpIpOutputStream);
-            ThreadUtil.sleep(2000);
             Bitonal algorithm = new BitonalThreshold(160);
             escpos.initializePrinter();
             escpos.setCharsetName("GB2312");
-            byte[] zhFontSize = hexToBytes("1C2108");
+            byte[] zhFontSize = WordHandlerUtils.hexToBytes("1C2108");
             byte[] titleData = EpsonCommands.mergerByteArray(
-                    hexToBytes("1B6101"),
-                    hexToBytes("1C210B"),
+                    WordHandlerUtils.hexToBytes("1B6101"),
+                    WordHandlerUtils.hexToBytes("1C210B"),
                     title.getBytes(charset),
-                    hexToBytes("0D0A")
+                    WordHandlerUtils.hexToBytes("0D0A")
             );
             escpos.write(titleData, 0, titleData.length);
-            byte[] numberFontSize = hexToBytes("1B2110");
+            byte[] numberFontSize = WordHandlerUtils.hexToBytes("1B2110");
             String text =
                     "  货主/货代: " + printBO.getWWB_CST_OWNER() + " \n" +
                             "  船名: " + printBO.getWWB_VLS_VCNNM() + "\n" +
                             "  船次: " + printBO.getWWB_VIW_VOYAGE() + " \n" +
                             "  唛头: " + printBO.getWB_MARKERNO() + " \n" +
+                            "  电子单号: " + printBO.getWWB_ID() + " \n" +
                             "  货名: " + printBO.getWWB_GOODSNAME() + "\n" +
                             "  车号: " + printBO.getWWB_TRUCKNO() + "\n" +
                             "  毛重: " + printBO.getWWB_CAR_GW() + "吨\n" +
@@ -84,13 +93,13 @@ public class JMPrintThread implements Runnable {
                 String at = text.charAt(i) + "";
                 byte[] atByte = at.getBytes(charset);
                 if (NumberUtil.isNumber(at)) {
-                    atByte=at.getBytes(StandardCharsets.UTF_8);
-                    printData = EpsonCommands.mergerByteArray(printData,numberFontSize, atByte);
+                    atByte = at.getBytes(StandardCharsets.UTF_8);
+                    printData = EpsonCommands.mergerByteArray(printData, numberFontSize, atByte);
                 } else {
-                    printData = EpsonCommands.mergerByteArray(printData,zhFontSize, atByte);
+                    printData = EpsonCommands.mergerByteArray(printData, zhFontSize, atByte);
                 }
             }
-           // byte[] str = text.getBytes(charset);
+            // byte[] str = text.getBytes(charset);
             byte[] data = EpsonCommands.mergerByteArray(
                     EpsonCommands.printLineHeight((byte) 30), EpsonCommands.alignLeft(),
                     printData, EpsonCommands.printLineFeed((byte) 1));
@@ -109,12 +118,6 @@ public class JMPrintThread implements Runnable {
             escpos.write(footer, 0, footer.length);
             escpos.close();
             log.info("print done======:{}", JSONUtil.toJsonStr(printBO));
-            LedFactory ledFactory = SpringUtil.getBean(LedFactory.class);
-            String line = SysConfig.serialSetting.getLed().getLine();
-            if (StrUtil.isEmpty(line)) {
-                line = "03";
-            }
-            LedOptions options = new LedOptions().setLine(line);
             ledFactory.handler(SysConfig.serialSetting.getLed().getBrand()).sendMsg("已成功打印小票,请取走小票", options);
         } catch (IOException e) {
             throw new RuntimeException(e);
@@ -130,13 +133,5 @@ public class JMPrintThread implements Runnable {
         return sb.toString().toUpperCase();
     }
 
-    public static byte[] hexToBytes(String hex) {
-        int len = hex.length();
-        byte[] data = new byte[len / 2];
-        for (int i = 0; i < len; i += 2) {
-            data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
-                    + Character.digit(hex.charAt(i + 1), 16));
-        }
-        return data;
-    }
+
 }

+ 0 - 3
src/main/java/com/gzlh/device/print/test/JMPrintThreadB.java

@@ -1,9 +1,7 @@
 package com.gzlh.device.print.test;
 
-import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.json.JSONUtil;
 import com.gzlh.bus.SysConfig;
-import com.gzlh.config.SystemObject;
 import com.gzlh.device.print.bo.BeiHaiWeightReport;
 import com.gzlh.utils.EpsonCommands;
 import lombok.extern.slf4j.Slf4j;
@@ -29,7 +27,6 @@ public class JMPrintThreadB implements Runnable {
     public void run() {
         Socket socket = null;
         try {
-            SystemObject.printFactory.handler(SysConfig.serialSetting.getPrint().getBrand()).close();
             socket = new Socket(SysConfig.serialSetting.getPrint().getIp(), SysConfig.serialSetting.getPrint().getPort());
             socket.setSoTimeout(3000);
             boolean result = socket.isConnected();

+ 1 - 5
src/main/java/com/gzlh/device/weighbridge/handler/impl/WeighbridgeHandlerTuoLiDuo.java

@@ -138,11 +138,7 @@ public class WeighbridgeHandlerTuoLiDuo implements IWeighbridgeHandler {
 //                "\u000210  40080    00\n" +
 //                "\u000210  40080    00\n" +
 //                "\u000210  40080    00";
-        String msg = "8  44340    00\n" +
-                "\u000218  43900    00\n" +
-                "\u000218  43840    00\n" +
-                "\u000218  43300    00\n" +
-                "\u000218  42860    00";
+        String msg = "10   1900    00";
         msg = StrUtil.removeAll(msg, "\u0002");
         msg = StrUtil.removeAll(msg, "\r");
         msg = StrUtil.removeAll(msg, "\n");

+ 2 - 3
src/main/java/com/gzlh/startup/StartupRunner.java

@@ -85,8 +85,8 @@ public class StartupRunner implements CommandLineRunner {
     @Resource
     private CaptureHandlerService captureHandlerService;
 
-    @Resource
-    private PrintNettyConfig printNettyConfig;
+//    @Resource
+//    private PrintNettyConfig printNettyConfig;
 
     @Resource
     Environment env;
@@ -129,7 +129,6 @@ public class StartupRunner implements CommandLineRunner {
             scheduler.scheduleAtFixedRate(new SearchJob(), initialDelay, period, TimeUnit.MILLISECONDS);
         }
         if (SysConfig.serialSetting.getPrint() != null && SysConfig.serialSetting.getPrint().isEnable()) {
-            ThreadUtil.execute(() -> printNettyConfig.connect());
             long initialDelay = 10;
             long period = 5; // 10秒
             scheduler.scheduleAtFixedRate(new CheckPrintOnlineTask(), initialDelay, period, TimeUnit.SECONDS);

+ 7 - 0
src/main/java/com/gzlh/utils/DeviceCache.java

@@ -1,6 +1,7 @@
 package com.gzlh.utils;
 
 
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
 import com.gzlh.bus.SysConfig;
 import com.gzlh.config.ModuleEnum;
@@ -20,6 +21,7 @@ import org.springframework.util.StringUtils;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 @Slf4j
@@ -141,4 +143,9 @@ public class DeviceCache {
                     device.setEMsg(eMsg);
                 });
     }
+
+    public static DeviceStatus.Device getDevice(String name){
+       Optional<DeviceStatus.Device>optionalDevice= deviceStatus.getDeviceList().stream().filter(device -> StrUtil.equals(device.getName(),name)).findFirst();
+        return optionalDevice.orElse(null);
+    }
 }

+ 9 - 1
src/main/java/com/gzlh/utils/WordHandlerUtils.java

@@ -168,7 +168,15 @@ public class WordHandlerUtils {
         }
         return decryptStr;
     }
-
+    public static byte[] hexToBytes(String hex) {
+        int len = hex.length();
+        byte[] data = new byte[len / 2];
+        for (int i = 0; i < len; i += 2) {
+            data[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4)
+                    + Character.digit(hex.charAt(i + 1), 16));
+        }
+        return data;
+    }
 
 }
 

+ 1 - 1
src/main/resources/application.yml

@@ -15,7 +15,7 @@ file:
 #海康配置文件
 hk:
   log-home: D:\project\face\face-admin\logs\hk
-  lib-home: E:\libs\hklib
+  lib-home: F:\libs\hklib
   lib-path: ${hk.lib-home}\HCNetSDK.dll
   linux-libcrypto-path: ${hk.lib-home}/libcrypto.so.1.1
   linux-libssl-path: ${hk.lib-home}/libssl.so.1.1