/**
* @param
* @param item 多个储位序列化成list
* @return
* @throws ErrorResponseException
* @throws ModbusTransportException
*/
public static
List
list.parallelStream().forEach(pair ->{
try {
modbusMaster.setValue(pair.first, pair.second);
} catch (Exception e) {
log.error("wirte_to_modbus_error:{}" , Throwables.getStackTraceAsString(e));
}
});
return true;
};
/**
* @param
* @param item 多个储位序列化成list
* @return
*/
public static
final Pair
List
for ( T t : item ) {
List
list.addAll( modelList);
}
return list;
};
/**
* 单个实体转换为modbus 定位器
*
* @param
* @param i
* @return
*/
@SuppressWarnings("unchecked")
private static
Class itemClazz = i.getClass();
if (Objects.isNull(itemClazz)) {
return Lists.newArrayList();
}
ModBusItem modBusItem = itemClazz.getAnnotation(ModBusItem.class);
ToolUtil.isNull(modBusItem, "the javabean must annotatied ModBusItem annotation");
Map
List collect = map.entrySet().stream().filter(mapEntry -> Objects.nonNull(mapEntry.getValue())).map(item ->{
ModBusItem modbusItem = item.getValue();
BaseLocator loc = null;
if(modbusItem.loc() == NumericLocator.class) {
loc = BaseLocator.holdingRegister( slaveId, offsetTemp.first , modbusItem.dataType());
}
if(modbusItem.loc() == StringLocator.class) {
loc = new StringLocator(slaveId, RegisterRange.HOLDING_REGISTER, offsetTemp.first, DataType.CHAR, modbusItem.maxRegisterCount());
}
offsetTemp.setFirst(offsetTemp.first + modbusItem.maxRegisterCount());
Object value = null;
try {
value = item.getKey().get( i);
} catch (IllegalArgumentException | IllegalAccessException e) {
log.error("getJsonModelList_error:{}" , Throwables.getStackTraceAsString(e)) ;
}
return Pair.makePair(loc, value );
}).collect(Collectors.toList());
return (List
}