SpringBoot 整合netty实现modbus服务控制硬件
现在我发送报文查询设备状态,每次发送的报文是什么,回写的报文就是什么?
我想知道netty使用writeAndFlush发送报文后如何监听回写的报文呢?
// 指令发送
ByteBuf buffer = Unpooled.buffer();
log.info("开始发送报文:{}",Arrays.toString(msgBytes));
buffer.writeBytes(msgBytes);
channel.writeAndFlush(buffer).addListener((ChannelFutureListener) future -> {
System.out.println(future);
if (future.isSuccess()) {
// 修改为合闸状态
if (msgBytes.equals(msgBytes1)){
log.info("客户端:{},查询结果为合闸:{}",imei,Arrays.toString(msgBytes));
WlEquipmentConfig wlEquipmentConfig = new WlEquipmentConfig();
wlEquipmentConfig.setWlPumpState(0);
wlEquipmentConfig.setWlEquipmentImei(imei);
wlEquipmentConfigMapper.updateWlEquipmentConfigByIMEI(wlEquipmentConfig);
}else if (msgBytes.equals(msgBytes2)){
log.info("客户端:{},查询结果为分闸:{}",imei,Arrays.toString(msgBytes));
WlEquipmentConfig wlEquipmentConfig = new WlEquipmentConfig();
wlEquipmentConfig.setWlPumpState(1);
wlEquipmentConfig.setWlEquipmentImei(imei);
wlEquipmentConfigMapper.updateWlEquipmentConfigByIMEI(wlEquipmentConfig);
}
log.info("客户端:{},查询结果为:{}",imei,Arrays.toString(msgBytes));
我现在好像就是发送的啥回写打印就是啥,netty如何监听到真正的设备响应报文呢?想请教一下