Skip to content

Receiving data via modbus tcp #102

@RobertKR21

Description

@RobertKR21

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions