Skip to content

Commit b54da17

Browse files
committed
fixed issue with data bytes to follow
1 parent 7295bdd commit b54da17

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/main/kotlin/ModbusReadCoilStatusResponse.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ class ModbusReadCoilStatusResponse: ModbusPacket {
6161
}
6262
println("min $minIndex max $maxIndex")
6363
val numberOfBytes = ((maxIndex.toInt() - minIndex.toInt() + 1)/8) + extraByte((maxIndex.toInt() - minIndex.toInt() + 1))
64-
val length = max(numberOfBytes, 1).toByte()
64+
val length = max(numberOfBytes, 1).toUByte()
6565
println("modbus length $length")
66-
byteVector = ByteArray(LEN_BYTES_METADATA_SIZE + length )
67-
byteVector[0] = length
66+
byteVector = ByteArray(LEN_BYTES_METADATA_SIZE + length.toInt() )
67+
byteVector[0] = length.toByte()
6868
for(element in listIndexToCoilValue){
6969
if(element.second) {
7070
println("byte index ${((element.first - minIndex)/8)+ 1} bit index ${(element.first - minIndex) % 8}")

src/main/kotlin/ModbusReadHoldingRegisterResponse.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class ModbusReadHoldingRegisterResponse: ModbusPacket{
3939
}
4040

4141
val numberOfBytes = (maxIndex.toInt() - minIndex.toInt() + 1) * 2
42-
val length = max(numberOfBytes, 1).toByte()
42+
val length = max(numberOfBytes, 1).toUByte()
4343
println("modbus length $length")
44-
byteVector = ByteArray(LEN_BYTES_METADATA_SIZE + length )
45-
byteVector[0] = length
44+
byteVector = ByteArray(LEN_BYTES_METADATA_SIZE + length.toInt() )
45+
byteVector[0] = length.toByte()
4646
var i = 1
4747
for(element in listIndexToRegisterValue){
4848
println("byte[${i}]=${DataConverter.toBytes(element.second)[1]}")

0 commit comments

Comments
 (0)