-
-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Description
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;
}
Metadata
Metadata
Assignees
Labels
No labels