package com.zy.core.thread; import com.zy.core.Slave; import com.zy.core.ThreadHandler; import lombok.Data; import lombok.extern.slf4j.Slf4j; import java.io.IOException; /** * 台车线程 * Created by vincent on 2020/8/4 */ @Data @Slf4j public class CarThread implements Runnable, ThreadHandler { private Slave slave; public CarThread(Slave slave) { this.slave = slave; } @Override @SuppressWarnings("InfiniteLoopStatement") public void run() { connect(); while (true) { try { Thread.sleep(1000); } catch (Exception e) { e.printStackTrace(); } } } @Override public boolean connect() { try { } catch (Exception e) { log.error("台车连接失败!!! ===>> [id:{}] [ip:{}] [port:{}]", slave.getId(), slave.getIp(), slave.getPort()); return false; } return true; } @Override public void close() { } public void write(byte[] msg, int len) throws IOException { } public byte[] read(int bufferSize, int timeOut) throws IOException { return null; } public static void main(String[] args) throws Exception { CarThread barcodeThread = new CarThread(new Slave()); barcodeThread.getSlave().setIp("192.168.2.150"); barcodeThread.getSlave().setPort(51236); boolean connect = barcodeThread.connect(); System.out.println(connect); barcodeThread.write("T".getBytes(), "T".length()); byte[] read = barcodeThread.read(11, 1000); System.out.println(new String(read)); } }