|
@@ -16,27 +16,139 @@ public class ModbusAutoConfiguration {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * RTU-Master
|
|
|
+ * RTU-Master first
|
|
|
+ * 注入方式@Autowired(required = true) private ModbusRtuMasterTemplate modbusRtuMasterTemplateFirst;
|
|
|
+ * 没有open=true的bean千万不要注入,@Autowired(required = false)也不行.
|
|
|
+ *
|
|
|
* @param modbusProperties
|
|
|
* @return
|
|
|
*/
|
|
|
@Bean
|
|
|
- @ConditionalOnProperty(prefix = "modbus.rtu-master", name = "open", havingValue = "true")
|
|
|
- public ModbusRtuMasterTemplate modbusRtuMasterTemplate(ModbusProperties modbusProperties) {
|
|
|
- ModbusProperties.RtuMaster rtu = modbusProperties.getRtuMaster();
|
|
|
+ @ConditionalOnProperty(prefix = "modbus.rtu-master.first", name = "open", havingValue = "true")
|
|
|
+ public ModbusRtuMasterTemplate modbusRtuMasterTemplateFirst(ModbusProperties modbusProperties) {
|
|
|
+ ModbusProperties.RtuMaster rtu = modbusProperties.getRtuMaster().getFirst();
|
|
|
return new ModbusRtuMasterTemplate(rtu.getPort(), rtu.getBaudRate(), rtu.getDataBits()
|
|
|
, rtu.getStopBits(), rtu.getParity(), rtu.getFlowControlIn(), rtu.getFlowControlOut());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * TCP-Master
|
|
|
+ * RTU-Master second
|
|
|
+ *
|
|
|
* @param modbusProperties
|
|
|
* @return
|
|
|
*/
|
|
|
@Bean
|
|
|
- @ConditionalOnProperty(prefix = "modbus.tcp-master", name = "open", havingValue = "true")
|
|
|
- public ModbusTcpMasterTemplate modbusTcpMasterTemplate(ModbusProperties modbusProperties) {
|
|
|
- ModbusProperties.TcpMaster tcp = modbusProperties.getTcpMaster();
|
|
|
+ @ConditionalOnProperty(prefix = "modbus.rtu-master.second", name = "open", havingValue = "true")
|
|
|
+ public ModbusRtuMasterTemplate modbusRtuMasterTemplateSecond(ModbusProperties modbusProperties) {
|
|
|
+ ModbusProperties.RtuMaster rtu = modbusProperties.getRtuMaster().getSecond();
|
|
|
+ return new ModbusRtuMasterTemplate(rtu.getPort(), rtu.getBaudRate(), rtu.getDataBits()
|
|
|
+ , rtu.getStopBits(), rtu.getParity(), rtu.getFlowControlIn(), rtu.getFlowControlOut());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * RTU-Master third
|
|
|
+ *
|
|
|
+ * @param modbusProperties
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ @ConditionalOnProperty(prefix = "modbus.rtu-master.third", name = "open", havingValue = "true")
|
|
|
+ public ModbusRtuMasterTemplate modbusRtuMasterTemplateThird(ModbusProperties modbusProperties) {
|
|
|
+ ModbusProperties.RtuMaster rtu = modbusProperties.getRtuMaster().getThird();
|
|
|
+ return new ModbusRtuMasterTemplate(rtu.getPort(), rtu.getBaudRate(), rtu.getDataBits()
|
|
|
+ , rtu.getStopBits(), rtu.getParity(), rtu.getFlowControlIn(), rtu.getFlowControlOut());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * RTU-Master fourth
|
|
|
+ *
|
|
|
+ * @param modbusProperties
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ @ConditionalOnProperty(prefix = "modbus.rtu-master.fourth", name = "open", havingValue = "true")
|
|
|
+ public ModbusRtuMasterTemplate modbusRtuMasterTemplateFourth(ModbusProperties modbusProperties) {
|
|
|
+ ModbusProperties.RtuMaster rtu = modbusProperties.getRtuMaster().getFourth();
|
|
|
+ return new ModbusRtuMasterTemplate(rtu.getPort(), rtu.getBaudRate(), rtu.getDataBits()
|
|
|
+ , rtu.getStopBits(), rtu.getParity(), rtu.getFlowControlIn(), rtu.getFlowControlOut());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * RTU-Master fifth
|
|
|
+ *
|
|
|
+ * @param modbusProperties
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ @ConditionalOnProperty(prefix = "modbus.rtu-master.fifth", name = "open", havingValue = "true")
|
|
|
+ public ModbusRtuMasterTemplate modbusRtuMasterTemplateFifth(ModbusProperties modbusProperties) {
|
|
|
+ ModbusProperties.RtuMaster rtu = modbusProperties.getRtuMaster().getFifth();
|
|
|
+ return new ModbusRtuMasterTemplate(rtu.getPort(), rtu.getBaudRate(), rtu.getDataBits()
|
|
|
+ , rtu.getStopBits(), rtu.getParity(), rtu.getFlowControlIn(), rtu.getFlowControlOut());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * TCP-Master first
|
|
|
+ *
|
|
|
+ * @param modbusProperties
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ @ConditionalOnProperty(prefix = "modbus.tcp-master.first", name = "open", havingValue = "true")
|
|
|
+ public ModbusTcpMasterTemplate modbusTcpMasterTemplateFirst(ModbusProperties modbusProperties) {
|
|
|
+ ModbusProperties.TcpMaster tcp = modbusProperties.getTcpMaster().getFirst();
|
|
|
+ return new ModbusTcpMasterTemplate(tcp.getHost(), tcp.getPort());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * TCP-Master second
|
|
|
+ *
|
|
|
+ * @param modbusProperties
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ @ConditionalOnProperty(prefix = "modbus.tcp-master.second", name = "open", havingValue = "true")
|
|
|
+ public ModbusTcpMasterTemplate modbusTcpMasterTemplateSecond(ModbusProperties modbusProperties) {
|
|
|
+ ModbusProperties.TcpMaster tcp = modbusProperties.getTcpMaster().getSecond();
|
|
|
+ return new ModbusTcpMasterTemplate(tcp.getHost(), tcp.getPort());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * TCP-Master third
|
|
|
+ *
|
|
|
+ * @param modbusProperties
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ @ConditionalOnProperty(prefix = "modbus.tcp-master.third", name = "open", havingValue = "true")
|
|
|
+ public ModbusTcpMasterTemplate modbusTcpMasterTemplateThird(ModbusProperties modbusProperties) {
|
|
|
+ ModbusProperties.TcpMaster tcp = modbusProperties.getTcpMaster().getThird();
|
|
|
+ return new ModbusTcpMasterTemplate(tcp.getHost(), tcp.getPort());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * TCP-Master fourth
|
|
|
+ *
|
|
|
+ * @param modbusProperties
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ @ConditionalOnProperty(prefix = "modbus.tcp-master.fourth", name = "open", havingValue = "true")
|
|
|
+ public ModbusTcpMasterTemplate modbusTcpMasterTemplateFourth(ModbusProperties modbusProperties) {
|
|
|
+ ModbusProperties.TcpMaster tcp = modbusProperties.getTcpMaster().getFourth();
|
|
|
+ return new ModbusTcpMasterTemplate(tcp.getHost(), tcp.getPort());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * TCP-Master fifth
|
|
|
+ *
|
|
|
+ * @param modbusProperties
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Bean
|
|
|
+ @ConditionalOnProperty(prefix = "modbus.tcp-master.fifth", name = "open", havingValue = "true")
|
|
|
+ public ModbusTcpMasterTemplate modbusTcpMasterTemplateFifth(ModbusProperties modbusProperties) {
|
|
|
+ ModbusProperties.TcpMaster tcp = modbusProperties.getTcpMaster().getFifth();
|
|
|
return new ModbusTcpMasterTemplate(tcp.getHost(), tcp.getPort());
|
|
|
}
|
|
|
}
|