Skip to content

Commit

Permalink
Merge pull request #11 from vhu474/mudbus-fixes-FC5,15,16
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
luizcantoni authored Oct 18, 2024
2 parents 8aaa42b + 8912bab commit 94c56be
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions Mudbus/Mudbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void Mudbus::Run()
// For Arduino 1.0
EthernetClient client = MbServer.available();
if(client.available())
if(!client.connected())
{
client.stop();
return;
}
{
Reads = 1 + Reads * (Reads < 999);
int i = 0;
Expand Down Expand Up @@ -91,7 +96,7 @@ void Mudbus::Run()
bitWrite(ByteArray[9 + i], j, C[Start + i * 8 + j]);
}
}
MessageLength = ByteDataLength + 9;
MessageLength = 6 + ByteArray[5];
client.write(ByteArray, MessageLength);
Writes = 1 + Writes * (Writes < 999);
FC = MB_FC_NONE;
Expand All @@ -116,7 +121,7 @@ void Mudbus::Run()
ByteArray[ 9 + i * 2] = highByte(R[Start + i]);
ByteArray[10 + i * 2] = lowByte(R[Start + i]);
}
MessageLength = ByteDataLength + 9;
MessageLength = 6 + ByteArray[5];
client.write(ByteArray, MessageLength);
Writes = 1 + Writes * (Writes < 999);
FC = MB_FC_NONE;
Expand All @@ -133,8 +138,8 @@ void Mudbus::Run()
Serial.print("=");
Serial.println(C[Start]);
#endif
ByteArray[5] = 2; //Number of bytes after this one.
MessageLength = 8;
ByteArray[5] = 6; //Number of bytes after this one.
MessageLength = 6 + ByteArray[5];
client.write(ByteArray, MessageLength);
Writes = 1 + Writes * (Writes < 999);
FC = MB_FC_NONE;
Expand All @@ -152,7 +157,7 @@ void Mudbus::Run()
Serial.println(R[Start]);
#endif
ByteArray[5] = 6; //Number of bytes after this one.
MessageLength = 12;
MessageLength = 6 + ByteArray[5];
client.write(ByteArray, MessageLength);
Writes = 1 + Writes * (Writes < 999);
FC = MB_FC_NONE;
Expand Down Expand Up @@ -182,7 +187,7 @@ void Mudbus::Run()
C[Start + i * 8 + j] = bitRead( ByteArray[13 + i], j);
}
}
MessageLength = 12;
MessageLength = 6 + ByteArray[5];
client.write(ByteArray, MessageLength);
Writes = 1 + Writes * (Writes < 999);
FC = MB_FC_NONE;
Expand All @@ -207,7 +212,7 @@ void Mudbus::Run()
{
R[Start + i] = word(ByteArray[ 13 + i * 2],ByteArray[14 + i * 2]);
}
MessageLength = 12;
MessageLength = 6 + ByteArray[5];
client.write(ByteArray, MessageLength);
Writes = 1 + Writes * (Writes < 999);
FC = MB_FC_NONE;
Expand Down

0 comments on commit 94c56be

Please sign in to comment.