Skip to content
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

Receiving data via modbus tcp #102

Open
Boobert21 opened this issue Aug 25, 2023 · 1 comment
Open

Receiving data via modbus tcp #102

Boobert21 opened this issue Aug 25, 2023 · 1 comment

Comments

@Boobert21
Copy link

I have a PLC that broadcasts data. I tried to get this data using "easy modbus tcp", but I get ex "Starting address invalid or starting address + quantity invalid"

static void Modsim()
{
    ModbusClient modbusClient = new ModbusClient("10.7.0.2", 502);
    modbusClient.Connect();

    modbusClient.ReceiveDataChanged += ModbusClient_ReceiveDataChanged;
    Console.WriteLine("Receiving data:");

    int startingAddress = 49000;
    int quantity = 9;
    while (isChatRunning)
    {
        try
        {
            for (int i = startingAddress; i < startingAddress + quantity; i++)
            {
                modbusClient.ReadHoldingRegisters(startingAddress, quantity);
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}

static void ModbusClient_ReceiveDataChanged(object sender)
{
    ModbusClient modbusClient = (ModbusClient)sender;

    string receivedData = BitConverter.ToString(modbusClient.receiveData.ToArray());

    if (receivedData.Length > 0)
    {
        Console.WriteLine(receivedData);
    }

    Thread.Sleep(1000);
}

So far I'm training on modsim32. These are the values I have set:
Address: 9000
Length: 10
Device id: 1
Modbus Point Type: 03: Holding Register
IP: 127.0.0.1, Port: 502

Please tell me what I did wrong. Or what I didn't. I would be glad for any information)

@Padanian
Copy link

Padanian commented Aug 25, 2023 via email

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

2 participants