From 8b65c548c508ae5d7c77ae1d72934df130c4bb41 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 18 Sep 2023 23:54:10 +0000 Subject: [PATCH 1/6] Bump com.ghgande:j2mod from 2.5.5 to 3.2.0 in /cnf Bumps [com.ghgande:j2mod](https://github.com/steveohara/j2mod) from 2.5.5 to 3.2.0. - [Changelog](https://github.com/steveohara/j2mod/blob/development/RELEASE_NOTES.md) - [Commits](https://github.com/steveohara/j2mod/commits) --- updated-dependencies: - dependency-name: com.ghgande:j2mod dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- cnf/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cnf/pom.xml b/cnf/pom.xml index bbea8a798d1..cd72aeab8ff 100644 --- a/cnf/pom.xml +++ b/cnf/pom.xml @@ -22,7 +22,7 @@ com.ghgande j2mod - 2.5.5 + 3.2.0 com.github.rzymek From 0ee02f1f593561229f7207471b328385b4e99837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3r=C3=A1nt=20Meszl=C3=A9nyi?= Date: Thu, 11 Jan 2024 13:14:27 +0100 Subject: [PATCH 2/6] Update j2mod to latest snapshot --- cnf/pom.xml | 17 +++++++++++++---- io.openems.edge.application/EdgeApp.bndrun | 6 +++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cnf/pom.xml b/cnf/pom.xml index 9caeff5c5d1..4399e56a52d 100644 --- a/cnf/pom.xml +++ b/cnf/pom.xml @@ -4,6 +4,15 @@ central 0.0.0 pom + + + oss-j2mod-snapshots + https://oss.sonatype.org/content/repositories/snapshots + + true + + + @@ -17,12 +26,12 @@ com.fazecast jSerialComm - 2.5.1 + 2.10.3 - com.ghgande - j2mod - 2.5.5 + com.ghgande + j2mod + 3.2.1-SNAPSHOT com.github.rzymek diff --git a/io.openems.edge.application/EdgeApp.bndrun b/io.openems.edge.application/EdgeApp.bndrun index 914372435ef..4ce525c2c6a 100644 --- a/io.openems.edge.application/EdgeApp.bndrun +++ b/io.openems.edge.application/EdgeApp.bndrun @@ -182,8 +182,8 @@ -runbundles: \ Java-WebSocket;version='[1.5.4,1.5.5)',\ - com.fazecast.jSerialComm;version='[2.5.1,2.5.2)',\ - com.ghgande.j2mod;version='[2.5.5,2.5.6)',\ + com.fazecast.jSerialComm,\ + com.ghgande.j2mod,\ com.google.gson;version='[2.10.1,2.10.2)',\ com.google.guava;version='[32.1.2,32.1.3)',\ com.google.guava.failureaccess;version='[1.0.1,1.0.2)',\ @@ -398,4 +398,4 @@ org.osgi.util.promise;version='[1.3.0,1.3.1)',\ org.owasp.encoder;version='[1.2.3,1.2.4)',\ reactive-streams;version='[1.0.4,1.0.5)',\ - rrd4j;version='[3.9.0,3.9.1)' \ No newline at end of file + rrd4j;version='[3.9.0,3.9.1)' From 255ef23e338e9fb2c951a98e4e5b6d30ed2059e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3r=C3=A1nt=20Meszl=C3=A9nyi?= Date: Thu, 11 Jan 2024 13:34:13 +0100 Subject: [PATCH 3/6] Add j2mod to wrapper --- io.openems.wrapper/bnd.bnd | 1 + io.openems.wrapper/j2mod.bnd | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 io.openems.wrapper/j2mod.bnd diff --git a/io.openems.wrapper/bnd.bnd b/io.openems.wrapper/bnd.bnd index 2c988f8674e..7a6e8145311 100644 --- a/io.openems.wrapper/bnd.bnd +++ b/io.openems.wrapper/bnd.bnd @@ -3,6 +3,7 @@ Bundle-Description: This wraps external java libraries that do not have OSGi hea -sub: *.bnd -buildpath: \ + com.ghgande.j2mod,\ com.github.rzymek:opczip;version='1.2.0',\ com.influxdb:influxdb-client-core;version='6.10.0',\ com.influxdb:influxdb-client-java;version='6.10.0',\ diff --git a/io.openems.wrapper/j2mod.bnd b/io.openems.wrapper/j2mod.bnd new file mode 100644 index 00000000000..652c8b0bb42 --- /dev/null +++ b/io.openems.wrapper/j2mod.bnd @@ -0,0 +1,15 @@ +Bundle-Name: fastexcel +Bundle-DocURL: https://github.com/dhatim/fastexcel +Bundle-License: https://opensource.org/licenses/Apache-2.0 +Bundle-Version: 0.15.7 + +Include-Resource: @j2mod-3.2.1-SNAPSHOT.jar + +-dsannotations: * + +-metatypeannotations: * + +Export-Package: \ + org.ghgande.j2mod + +-sources: false From d6863b4437b783229de15b2055cba4b37c9ef8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3r=C3=A1nt=20Meszl=C3=A9nyi?= Date: Thu, 18 Jan 2024 11:47:20 +0100 Subject: [PATCH 4/6] Improve error handling for serial ports. --- .../bridge/modbus/BridgeModbusSerialImpl.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/BridgeModbusSerialImpl.java b/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/BridgeModbusSerialImpl.java index dd13dd2c81f..211b83c6223 100644 --- a/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/BridgeModbusSerialImpl.java +++ b/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/BridgeModbusSerialImpl.java @@ -1,5 +1,8 @@ package io.openems.edge.bridge.modbus; +import java.io.File; +import java.util.Arrays; + import org.osgi.service.component.ComponentContext; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; @@ -28,6 +31,7 @@ import io.openems.edge.bridge.modbus.api.Stopbit; import io.openems.edge.common.component.OpenemsComponent; import io.openems.edge.common.event.EdgeEventConstants; +import com.fazecast.jSerialComm.SerialPort; /** * Provides a service for connecting to, querying and writing to a Modbus/RTU @@ -45,7 +49,7 @@ }) public class BridgeModbusSerialImpl extends AbstractModbusBridge implements BridgeModbus, BridgeModbusSerial, OpenemsComponent, EventHandler { - + /** The configured Port-Name (e.g. '/dev/ttyUSB0' or 'COM3'). */ private String portName = ""; @@ -85,6 +89,17 @@ private void modified(ComponentContext context, ConfigSerial config) { } private void applyConfig(ConfigSerial config) { + File serport = new File(config.portName()); + if (!serport.exists()) { + throw new IllegalArgumentException("The provided path " + config.portName() + " does not exist."); + } + var ports = SerialPort.getCommPorts(); + var isSerial = Arrays.stream(ports).filter(val ->serport.getAbsolutePath().equals(val.getSystemPortPath())).findAny(); + if (isSerial.isEmpty()) { + var portNames = Arrays.stream(ports).map(t -> t.getSystemPortPath()).toList(); + throw new IllegalArgumentException("The provided path " + config.portName() + " is not a serial port. Serial ports available: " + portNames.toString()); + } + this.portName = config.portName(); this.baudrate = config.baudRate(); this.databits = config.databits(); From f93571f6ccfa73d0e3cd314d08d7f088342c0cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3r=C3=A1nt=20Meszl=C3=A9nyi?= Date: Thu, 18 Jan 2024 11:50:14 +0100 Subject: [PATCH 5/6] Add wrapper for j2mod not bundled. --- io.openems.edge.bridge.modbus/bnd.bnd | 1 + io.openems.wrapper/j2mod.bnd | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/io.openems.edge.bridge.modbus/bnd.bnd b/io.openems.edge.bridge.modbus/bnd.bnd index ab8a2868b1b..5bc81ae4cd3 100644 --- a/io.openems.edge.bridge.modbus/bnd.bnd +++ b/io.openems.edge.bridge.modbus/bnd.bnd @@ -6,6 +6,7 @@ Bundle-Version: 1.0.0.${tstamp} -buildpath: \ ${buildpath},\ com.ghgande.j2mod,\ + com.fazecast.jSerialComm,\ io.openems.common,\ io.openems.edge.common diff --git a/io.openems.wrapper/j2mod.bnd b/io.openems.wrapper/j2mod.bnd index 652c8b0bb42..c8923813d7c 100644 --- a/io.openems.wrapper/j2mod.bnd +++ b/io.openems.wrapper/j2mod.bnd @@ -10,6 +10,15 @@ Include-Resource: @j2mod-3.2.1-SNAPSHOT.jar -metatypeannotations: * Export-Package: \ - org.ghgande.j2mod + com.ghgande.j2mod,\ + com.ghgande.j2mod.modbus,\ + com.ghgande.j2mod.modbus.facade,\ + com.ghgande.j2mod.modbus.io,\ + com.ghgande.j2mod.modbus.msg,\ + com.ghgande.j2mod.modbus.net,\ + com.ghgande.j2mod.modbus.procimg,\ + com.ghgande.j2mod.modbus.slave,\ + com.ghgande.j2mod.modbus.util,\ + org.ghgande.j2mod -sources: false From 47bc5382d48d3c21abddbd4c75e48037f415398b Mon Sep 17 00:00:00 2001 From: da-Kai Date: Mon, 22 Jan 2024 10:36:14 +0100 Subject: [PATCH 6/6] implement j2mod 3.2.0 --- cnf/pom.xml | 17 +++------ io.openems.edge.application/EdgeApp.bndrun | 4 +-- io.openems.edge.bridge.modbus/bnd.bnd | 1 - .../bridge/modbus/BridgeModbusSerialImpl.java | 36 ++++++++++--------- .../edge/bridge/modbus/ConfigSerial.java | 9 +++++ .../modbus/BridgeModbusSerialImplTest.java | 3 ++ .../edge/bridge/modbus/MyConfigSerial.java | 33 +++++++++++++++++ io.openems.wrapper/bnd.bnd | 1 - io.openems.wrapper/j2mod.bnd | 24 ------------- 9 files changed, 71 insertions(+), 57 deletions(-) delete mode 100644 io.openems.wrapper/j2mod.bnd diff --git a/cnf/pom.xml b/cnf/pom.xml index 9e0d649fb90..415c0d42777 100644 --- a/cnf/pom.xml +++ b/cnf/pom.xml @@ -4,15 +4,6 @@ central 0.0.0 pom - - - oss-j2mod-snapshots - https://oss.sonatype.org/content/repositories/snapshots - - true - - - @@ -26,12 +17,12 @@ com.fazecast jSerialComm - 2.10.3 + 2.9.3 - com.ghgande - j2mod - 3.2.1-SNAPSHOT + com.ghgande + j2mod + 3.2.0 com.github.rzymek diff --git a/io.openems.edge.application/EdgeApp.bndrun b/io.openems.edge.application/EdgeApp.bndrun index 50ef0ff2842..0398f8d7922 100644 --- a/io.openems.edge.application/EdgeApp.bndrun +++ b/io.openems.edge.application/EdgeApp.bndrun @@ -188,8 +188,8 @@ bcpkix;version='[1.70.0,1.70.1)',\ bcprov;version='[1.70.0,1.70.1)',\ bcutil;version='[1.70.0,1.70.1)',\ - com.fazecast.jSerialComm;version='[2.5.1,2.5.2)',\ - com.ghgande.j2mod;version='[2.5.5,2.5.6)',\ + com.fazecast.jSerialComm;version='[2.9.3,2.9.4)',\ + com.ghgande.j2mod;version='[3.2.0,3.2.1)',\ com.google.gson;version='[2.10.1,2.10.2)',\ com.google.guava;version='[33.0.0,33.0.1)',\ com.google.guava.failureaccess;version='[1.0.2,1.0.3)',\ diff --git a/io.openems.edge.bridge.modbus/bnd.bnd b/io.openems.edge.bridge.modbus/bnd.bnd index 5bc81ae4cd3..ab8a2868b1b 100644 --- a/io.openems.edge.bridge.modbus/bnd.bnd +++ b/io.openems.edge.bridge.modbus/bnd.bnd @@ -6,7 +6,6 @@ Bundle-Version: 1.0.0.${tstamp} -buildpath: \ ${buildpath},\ com.ghgande.j2mod,\ - com.fazecast.jSerialComm,\ io.openems.common,\ io.openems.edge.common diff --git a/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/BridgeModbusSerialImpl.java b/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/BridgeModbusSerialImpl.java index 211b83c6223..4488593accc 100644 --- a/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/BridgeModbusSerialImpl.java +++ b/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/BridgeModbusSerialImpl.java @@ -1,8 +1,5 @@ package io.openems.edge.bridge.modbus; -import java.io.File; -import java.util.Arrays; - import org.osgi.service.component.ComponentContext; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; @@ -31,7 +28,6 @@ import io.openems.edge.bridge.modbus.api.Stopbit; import io.openems.edge.common.component.OpenemsComponent; import io.openems.edge.common.event.EdgeEventConstants; -import com.fazecast.jSerialComm.SerialPort; /** * Provides a service for connecting to, querying and writing to a Modbus/RTU @@ -49,7 +45,7 @@ }) public class BridgeModbusSerialImpl extends AbstractModbusBridge implements BridgeModbus, BridgeModbusSerial, OpenemsComponent, EventHandler { - + /** The configured Port-Name (e.g. '/dev/ttyUSB0' or 'COM3'). */ private String portName = ""; @@ -64,6 +60,15 @@ public class BridgeModbusSerialImpl extends AbstractModbusBridge /** The configured parity. */ private Parity parity; + + /** Enable internal bus termination. */ + private boolean enableTermination; + + /** The configured delay between activating the transmitter and actually sending data in microseconds. */ + private int delayBeforeTx; + + /** The configured delay between the end of transmitting data and deactivating transmitter in microseconds. */ + private int delayAfterTx; public BridgeModbusSerialImpl() { super(// @@ -89,22 +94,14 @@ private void modified(ComponentContext context, ConfigSerial config) { } private void applyConfig(ConfigSerial config) { - File serport = new File(config.portName()); - if (!serport.exists()) { - throw new IllegalArgumentException("The provided path " + config.portName() + " does not exist."); - } - var ports = SerialPort.getCommPorts(); - var isSerial = Arrays.stream(ports).filter(val ->serport.getAbsolutePath().equals(val.getSystemPortPath())).findAny(); - if (isSerial.isEmpty()) { - var portNames = Arrays.stream(ports).map(t -> t.getSystemPortPath()).toList(); - throw new IllegalArgumentException("The provided path " + config.portName() + " is not a serial port. Serial ports available: " + portNames.toString()); - } - this.portName = config.portName(); this.baudrate = config.baudRate(); this.databits = config.databits(); this.stopbits = config.stopbits(); this.parity = config.parity(); + this.enableTermination = config.enableTermination(); + this.delayBeforeTx = config.delayBeforeTx(); + this.delayAfterTx = config.delayAfterTx(); } @Override @@ -144,6 +141,13 @@ private synchronized SerialConnection getModbusConnection() throws OpenemsExcept params.setParity(this.parity.getValue()); params.setEncoding(Modbus.SERIAL_ENCODING_RTU); params.setEcho(false); + /* RS485 Settings */ + params.setRs485Mode(true); + params.setRs485RxDuringTx(false); + params.setRs485TxEnableActiveHigh(true); + params.setRs485EnableTermination(this.enableTermination); + params.setRs485DelayBeforeTxMicroseconds(this.delayBeforeTx); + params.setRs485DelayAfterTxMicroseconds(this.delayAfterTx); var connection = new SerialConnection(params); this._connection = connection; } diff --git a/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/ConfigSerial.java b/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/ConfigSerial.java index 3024294f204..5032b4f574c 100644 --- a/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/ConfigSerial.java +++ b/io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/ConfigSerial.java @@ -35,6 +35,15 @@ @AttributeDefinition(name = "Parity", description = "The parity - 'none', 'even', 'odd', 'mark' or 'space'") Parity parity() default Parity.NONE; + + @AttributeDefinition(name = "Enable termination", description = "Sets whether the interface shall enable internal bus termination") + boolean enableTermination() default true; + + @AttributeDefinition(name = "Delay before TX [μs]", description = "Sets the delay between activating the transmitter and actually sending data. There are devices in the field requiring such a delay for start bit detection.", min = "0") + int delayBeforeTx() default 1000; + + @AttributeDefinition(name = "Delay after TX [μs]", description = "Sets the delay between the end of transmitting data and deactivating the transmitter.", min = "0") + int delayAfterTx() default 0; @AttributeDefinition(name = "Log-Verbosity", description = "The log verbosity.") LogVerbosity logVerbosity() default LogVerbosity.NONE; diff --git a/io.openems.edge.bridge.modbus/test/io/openems/edge/bridge/modbus/BridgeModbusSerialImplTest.java b/io.openems.edge.bridge.modbus/test/io/openems/edge/bridge/modbus/BridgeModbusSerialImplTest.java index da821996473..3645d2d6fdf 100644 --- a/io.openems.edge.bridge.modbus/test/io/openems/edge/bridge/modbus/BridgeModbusSerialImplTest.java +++ b/io.openems.edge.bridge.modbus/test/io/openems/edge/bridge/modbus/BridgeModbusSerialImplTest.java @@ -22,6 +22,9 @@ public void test() throws Exception { .setParity(Parity.NONE) // .setStopbits(Stopbit.ONE) // .setInvalidateElementsAfterReadErrors(1) // + .setEnableTermination(true) // + .setDelayBeforeTx(1000) // + .setDelayAfterTx(0) // .setLogVerbosity(LogVerbosity.NONE) // .build()) // ; diff --git a/io.openems.edge.bridge.modbus/test/io/openems/edge/bridge/modbus/MyConfigSerial.java b/io.openems.edge.bridge.modbus/test/io/openems/edge/bridge/modbus/MyConfigSerial.java index 621dedce05f..5df6db2a1d2 100644 --- a/io.openems.edge.bridge.modbus/test/io/openems/edge/bridge/modbus/MyConfigSerial.java +++ b/io.openems.edge.bridge.modbus/test/io/openems/edge/bridge/modbus/MyConfigSerial.java @@ -15,6 +15,9 @@ protected static class Builder { private int databits; private Stopbit stopbits; private Parity parity; + private boolean enableTermination; + private int delayBeforeTx; + private int delayAfterTx; private LogVerbosity logVerbosity; private int invalidateElementsAfterReadErrors; @@ -50,6 +53,21 @@ public Builder setParity(Parity parity) { this.parity = parity; return this; } + + public Builder setEnableTermination(boolean enableTermination) { + this.enableTermination = enableTermination; + return this; + } + + public Builder setDelayBeforeTx(int delay) { + this.delayBeforeTx = delay; + return this; + } + + public Builder setDelayAfterTx(int delay) { + this.delayAfterTx = delay; + return this; + } public Builder setLogVerbosity(LogVerbosity logVerbosity) { this.logVerbosity = logVerbosity; @@ -106,6 +124,21 @@ public Stopbit stopbits() { public Parity parity() { return this.builder.parity; } + + @Override + public boolean enableTermination() { + return this.builder.enableTermination; + } + + @Override + public int delayBeforeTx() { + return this.builder.delayBeforeTx; + } + + @Override + public int delayAfterTx() { + return this.builder.delayAfterTx; + } @Override public LogVerbosity logVerbosity() { diff --git a/io.openems.wrapper/bnd.bnd b/io.openems.wrapper/bnd.bnd index 2b4b1c60f90..3f7b534f767 100644 --- a/io.openems.wrapper/bnd.bnd +++ b/io.openems.wrapper/bnd.bnd @@ -3,7 +3,6 @@ Bundle-Description: This wraps external java libraries that do not have OSGi hea -sub: *.bnd -buildpath: \ - com.ghgande.j2mod,\ com.github.rzymek:opczip;version='1.2.0',\ com.influxdb:influxdb-client-core;version='6.12.0',\ com.influxdb:influxdb-client-java;version='6.12.0',\ diff --git a/io.openems.wrapper/j2mod.bnd b/io.openems.wrapper/j2mod.bnd deleted file mode 100644 index c8923813d7c..00000000000 --- a/io.openems.wrapper/j2mod.bnd +++ /dev/null @@ -1,24 +0,0 @@ -Bundle-Name: fastexcel -Bundle-DocURL: https://github.com/dhatim/fastexcel -Bundle-License: https://opensource.org/licenses/Apache-2.0 -Bundle-Version: 0.15.7 - -Include-Resource: @j2mod-3.2.1-SNAPSHOT.jar - --dsannotations: * - --metatypeannotations: * - -Export-Package: \ - com.ghgande.j2mod,\ - com.ghgande.j2mod.modbus,\ - com.ghgande.j2mod.modbus.facade,\ - com.ghgande.j2mod.modbus.io,\ - com.ghgande.j2mod.modbus.msg,\ - com.ghgande.j2mod.modbus.net,\ - com.ghgande.j2mod.modbus.procimg,\ - com.ghgande.j2mod.modbus.slave,\ - com.ghgande.j2mod.modbus.util,\ - org.ghgande.j2mod - --sources: false