OutOfRange in some array, write doesn't work
This commit is contained in:
1
Main.cs
1
Main.cs
@@ -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")
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user