Skip to content

Convert Registers to Strings not correct #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wowogiengen opened this issue Mar 1, 2025 · 0 comments
Open

Convert Registers to Strings not correct #118

wowogiengen opened this issue Mar 1, 2025 · 0 comments

Comments

@wowogiengen
Copy link

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant