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

Using the Read and Write method of S7MultiVar prompts ISO: Invalid PDU received #43

Open
2270969436 opened this issue Nov 8, 2024 · 0 comments

Comments

@2270969436
Copy link

2270969436 commented Nov 8, 2024

If my PLC PDU size value is 240, but I need to read or write a length of 500 bytes,25 bytes per address, how should I perform batch processing operations, calculate the byte length sent to the PLC, and determine the byte length of the PLC response? What is the formula for calculating the byte length of sending and receiving messages

var client = new S7Client();
int result = client.ConnectTo("127.0.0.1", 0, 2); 
if (result != 0)
{
    Console.WriteLine(client.ErrorText(result));
    return;
}

var items = new List<S7Tag>();
for (int i = 0; i < 20; i++)
{
    items.Add(new S7Tag
    {
        Area = (int)S7Area.DB,
        DBNumber = 1, 
        Start = i * 25,
        Elements = 25, 
        WordLen = (int)S7WordLength.Char,
    });
};
var length = tags.Sum(x => x.WordLen.DataSizeByte() * x.Elements);
var buffer = new byte[length];
var offset = 0;
var multiVar = new S7MultiVar(client);
foreach (var tag in tags)
{
     multiVar.Add(tag, ref buffer, offset);
     offset += tag.WordLen.DataSizeByte() * tag.Elements;
}
var readResult = multiVar.Read();
if (readResult != 0)
{
    Console.WriteLine(client.ErrorText(readResult));
    return;
}
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