-
Notifications
You must be signed in to change notification settings - Fork 443
Description
I am reading Registers from my GoodWe inverters GW6000ES20 and GW10KN-ET.
The documentation says
Offset: 35003
Description: Inverter SN
Mode: RO
Type: STR
Length: 8
Remark: ASCII code,16 bytes. Read together.
I am reading 5 int values like
[0] = 0x00004757 | int
[1] = 0x00003630 | int
[2] = 0x00003030 | int
[3] = 0x00004553 | int
[4] = 0x00003230 | int
When i try to convert the register values with ConvertRegistersToString, it uses RegisterOrder.HighLow (by code), and the result is
WG0600SE02
after implementing RegisterOrder.LowHigh, it converts correctly: GW6000ES20
So the method should look like
'''
///
/// Converts 16 - Bit Register values to String
///
/// Register array received via Modbus
/// First Register containing the String to convert
/// number of characters in String (must be even)
/// Desired Word Order (Low Register first or High Register first
/// Converted String
public static string ConvertRegistersToString(int[] registers, int offset, int stringLength, RegisterOrder order = RegisterOrder.LowHigh)
{
byte[] result = new byte[stringLength];
byte[] registerResult = new byte[2];
for (int i = 0; i < stringLength/2; i++)
{
registerResult = BitConverter.GetBytes(registers[offset + i]);
if (order == RegisterOrder.HighLow)
{
result[i * 2] = registerResult[0];
result[i * 2 + 1] = registerResult[1];
}
else if (order == RegisterOrder.LowHigh)
{
result[i * 2 + 1] = registerResult[0];
result[i * 2] = registerResult[1];
}
}
return System.Text.Encoding.Default.GetString(result);
}
Sorry if the formatting is not so pretty, this is my first time reporting an issue...