Sharp7 icon indicating copy to clipboard operation
Sharp7 copied to clipboard

ArgumentOutOfRangeException when executing the method DBWrite

Open PozitronikAkr opened this issue 1 year ago • 1 comments

Hi !

There is no physical connection.

The DBRead method predictably returns error number 9. CLI : Client not connected. The DB Write method returns an exception System.ArgumentOutOfRangeException. And it should, as it seemed to me, also return error number 9. Why is this not the case?

namespace TestSharp7ConsoleApplication
{
    class Program
    {
        static void Main()
        {
            int result;
            byte[] db = new byte[20];
            S7Client client = new S7Client();
            client.ConnectTo("192.168.0.2", 0, 1);
            try
            {                
                result = client.DBRead(10, 0, db.Length, db);
                Console.WriteLine($"{result} : {client.ErrorText(result)}");
                result = client.DBWrite(10, 0, db.Length, db);
                Console.WriteLine($"{result} : {client.ErrorText(result)}");
            }
            catch (System.ArgumentOutOfRangeException e)
            {
                result = -1;
                Console.WriteLine($"{result} : {e.Message}");
            }
            Console.WriteLine();
            Console.WriteLine("Press <Enter> for exit");
            Console.ReadLine();        
        }
    }
}

PozitronikAkr avatar Jul 03 '23 08:07 PozitronikAkr