c# - Communication ProfiNet protocol and windows application - Stack Overflow

admin2025-04-28  2

I use the S7 library to communicate with the PLC. When I try to read or write a single variable, at times, the system crashes. What is a better solution in this use for reading or writing a few variables?

Write To DB

or like example

WriteMultiVars

public Tuple<bool, string> WriteMultipleVarsItems(List<DataItem>writeDataItem)
    {
        string error = string.Empty;
        bool result; 
    
        try
        {
            plc!.Write(writeDataItem.ToArray());
            result = true;
            //Console.WriteLine("Write ok");
        }
        catch (PlcException e)
        {
            error = e.Message;
            result = false;
            Console.WriteLine(error);
        }
    
        return Tuple.Create(result, error);
}

What solution is better? I try both variants, but I'm not sure what is better.

转载请注明原文地址:http://anycun.com/QandA/1745855831a91280.html