|
@@ -21,7 +21,9 @@ import org.springframework.context.event.EventListener;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URISyntaxException;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
@@ -71,8 +73,15 @@ public class ModBusServiceImpl implements ModBusService {
|
|
|
// log.warn("[开始连接采集模块]: {}", JSON.toJSONString(collectModuleInfoList));
|
|
|
ModbusMaster master = ModBusUtil.createMaster(host, port);
|
|
|
MASTER_MAP.put(1l, master);
|
|
|
- try {
|
|
|
- show = new String(Files.readAllBytes(Paths.get(ClassLoader.getSystemResource("tag.json").toURI())), StandardCharsets.UTF_8);
|
|
|
+ InputStream inputStream = getClass().getClassLoader().getResourceAsStream("tag.json");
|
|
|
+ try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()){
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int length;
|
|
|
+ while ((length = inputStream.read(buffer)) != -1) {
|
|
|
+ byteArrayOutputStream.write(buffer, 0, length);
|
|
|
+ }
|
|
|
+ show = byteArrayOutputStream.toString(StandardCharsets.UTF_8.name());
|
|
|
+ // 使用 show 字符串
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|