OutOfRange in some array, write doesn't work

This commit is contained in:
nikzori
2024-12-17 16:55:55 +03:00
parent ab5c06df5e
commit 61546de4ca
2 changed files with 3 additions and 0 deletions

View File

@@ -474,6 +474,7 @@ namespace Gidrolock_Modbus_Scanner
switch ((FunctionCode)functionCode) switch ((FunctionCode)functionCode)
{ {
case (FunctionCode.WriteCoil): case (FunctionCode.WriteCoil):
Console.WriteLine("Trying to force single coil");
if (valueLower == "true" || valueLower == "1") if (valueLower == "true" || valueLower == "1")
await Modbus.WriteSingleAsync(port, (FunctionCode)functionCode, (byte)UpDown_ModbusID.Value, (ushort)address, 0xFF_00); await Modbus.WriteSingleAsync(port, (FunctionCode)functionCode, (byte)UpDown_ModbusID.Value, (ushort)address, 0xFF_00);
else if (valueLower == "false" || valueLower == "0") else if (valueLower == "false" || valueLower == "0")

View File

@@ -55,6 +55,7 @@ namespace Gidrolock_Modbus_Scanner
GetCRC(_message, ref CRC); GetCRC(_message, ref CRC);
_message[6] = CRC[0]; _message[6] = CRC[0];
_message[7] = CRC[1]; _message[7] = CRC[1];
Console.WriteLine("Message: " + ByteArrayToString(_message));
return _message; return _message;
} }
else return new byte[1] { 0xFF }; else return new byte[1] { 0xFF };
@@ -129,6 +130,7 @@ namespace Gidrolock_Modbus_Scanner
try try
{ {
port.Write(message, 0, message.Length); port.Write(message, 0, message.Length);
Console.WriteLine("Write message sent successfully");
return true; return true;
} }
catch (Exception err) catch (Exception err)