CodeReader3Handler.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package com.warewms.hailiang.connect.handler;
  2. import com.warewms.hailiang.connect.InkjetPrintersConnect;
  3. import com.warewms.hailiang.enums.CodeReaderEnum;
  4. import com.warewms.hailiang.init.TcpServiceRunner;
  5. import com.warewms.hailiang.util.ParseMsgTools;
  6. import io.netty.buffer.ByteBuf;
  7. import io.netty.buffer.Unpooled;
  8. import io.netty.channel.ChannelHandlerContext;
  9. import io.netty.channel.ChannelInboundHandlerAdapter;
  10. import io.netty.util.CharsetUtil;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.springframework.stereotype.Component;
  13. /**
  14. * Created with IntelliJ IDEA.
  15. *
  16. * @author: liuzhifei
  17. * Date: 2023/8/9
  18. * Time: 17:07
  19. * To change this template use File | Settings | File Templates.
  20. * Description: 喷码机连接消息处理类
  21. **/
  22. @Slf4j
  23. @Component
  24. public class CodeReader3Handler extends ChannelInboundHandlerAdapter {
  25. @Override
  26. public void channelActive(ChannelHandlerContext ctx) throws Exception {
  27. ctx.writeAndFlush(Unpooled.copiedBuffer(CodeReaderEnum.readCode.toString(), CharsetUtil.UTF_8));
  28. }
  29. @Override
  30. public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
  31. ByteBuf byteBuf = (ByteBuf) msg;
  32. log.info(String.valueOf(byteBuf.toString(CharsetUtil.UTF_8)));
  33. }
  34. @Override
  35. public void channelInactive(ChannelHandlerContext ctx) throws Exception {
  36. log.error("倒角读码器连接已断开!");
  37. InkjetPrintersConnect inkjetPrintersConnect = (InkjetPrintersConnect) TcpServiceRunner.getTCPInstanceList().get("InkjetPrintersConnect");
  38. inkjetPrintersConnect.retry();
  39. super.channelInactive(ctx);
  40. }
  41. }