Skip to content

Commit 75a6f9c

Browse files
committed
Replace println with log4j
1 parent 1b5e1da commit 75a6f9c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/main/kotlin/operations/SubOperation.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,27 @@ import EnvironmentVariables
66
import IfEqual
77
import PlcMemory
88
import Sub
9+
import org.slf4j.LoggerFactory
910
import java.util.concurrent.CancellationException
1011
import toBooleanFromBinary
1112

1213

1314
class SubOperation(private val configuration: Configuration,private val memory: PlcMemory, environmentVariables: EnvironmentVariables
1415
) : BaseOperation(environmentVariables, configuration) {
1516

17+
companion object {
18+
val logger = LoggerFactory.getLogger("SubOperation")
19+
}
1620
fun subOperation(element: Sub) {
17-
println("Sub symbol ${element.symbol} value ${element.value}")
21+
logger.debug("Sub symbol ${element.symbol} value ${element.value}")
1822
var value = processValue(element.value)
1923
var variable = configuration.registers.getVarConfiguration(element.symbol)
2024
if (variable == null) {
21-
println("ERROR: Symbol ${element.symbol} not found during Set execution")
25+
logger.error("Symbol ${element.symbol} not found during Set execution")
2226
throw CancellationException("Error - Sub")
2327
} else {
2428
if (variable.addressType == AddressType.COIL || variable.addressType == AddressType.DISCRETE_INPUT) {
25-
println("ERROR: Symbol ${element.symbol} is of type COIL or DISCRETE_INPUT which is not support by Sub operation")
29+
logger.error("Symbol ${element.symbol} is of type COIL or DISCRETE_INPUT which is not support by Sub operation")
2630
throw CancellationException("Error - Sub")
2731
}
2832

@@ -36,7 +40,7 @@ class SubOperation(private val configuration: Configuration,private val memory:
3640
if (variable.datatype == "FLOAT32") {
3741
var currentValue = memory.readHoldingRegister(variable.address.toInt(), 2)
3842
if (currentValue.isEmpty()) {
39-
println("ERROR: Add Operation - Unable to get value of ${element.symbol} address ${variable.address} ")
43+
logger.error("Add Operation - Unable to get value of ${element.symbol} address ${variable.address} ")
4044
throw CancellationException("Error - Add")
4145
}
4246
val intValue = ((currentValue[1].toInt() shl 16) or (currentValue[0].toInt() and 0xFFFF))
@@ -47,7 +51,7 @@ class SubOperation(private val configuration: Configuration,private val memory:
4751
} else {
4852
var currentValue = memory.readHoldingRegister(variable.address.toInt(), 1)
4953
if (currentValue.isEmpty()) {
50-
println("ERROR: Add Operation - Unable to get value of ${element.symbol} address ${variable.address} ")
54+
logger.error("Add Operation - Unable to get value of ${element.symbol} address ${variable.address} ")
5155
throw CancellationException("Error - Add")
5256
}
5357
var intValue = value.toInt()

0 commit comments

Comments
 (0)