1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- package com.warewms.hailiang.connect.handler;
- import com.warewms.hailiang.connect.InkjetPrintersConnect;
- import com.warewms.hailiang.enums.CodeReaderEnum;
- import com.warewms.hailiang.init.TcpServiceRunner;
- import com.warewms.hailiang.util.ParseMsgTools;
- import io.netty.buffer.ByteBuf;
- import io.netty.buffer.Unpooled;
- import io.netty.channel.ChannelHandlerContext;
- import io.netty.channel.ChannelInboundHandlerAdapter;
- import io.netty.util.CharsetUtil;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Component;
- /**
- * Created with IntelliJ IDEA.
- *
- * @author: liuzhifei
- * Date: 2023/8/9
- * Time: 17:07
- * To change this template use File | Settings | File Templates.
- * Description: 喷码机连接消息处理类
- **/
- @Slf4j
- @Component
- public class CodeReader3Handler extends ChannelInboundHandlerAdapter {
- @Override
- public void channelActive(ChannelHandlerContext ctx) throws Exception {
- ctx.writeAndFlush(Unpooled.copiedBuffer(CodeReaderEnum.readCode.toString(), CharsetUtil.UTF_8));
- }
- @Override
- public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
- ByteBuf byteBuf = (ByteBuf) msg;
- log.info(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
- }
- @Override
- public void channelInactive(ChannelHandlerContext ctx) throws Exception {
- log.error("倒角读码器连接已断开!");
- InkjetPrintersConnect inkjetPrintersConnect = (InkjetPrintersConnect) TcpServiceRunner.getTCPInstanceList().get("InkjetPrintersConnect");
- inkjetPrintersConnect.retry();
- super.channelInactive(ctx);
- }
- }
|