Beispiel #1
0
    static void Main(string[] args)
    {
        Server = new S7Server();

        // Set the callbacks (using the static var to avoid the garbage collect)
        TheEventCallBack  = new S7Server.TSrvCallback(EventCallback);
        TheRWAreaCallBack = new S7Server.TSrvRWAreaCallback(SrvRWAreaCallback);


        // Filter a bit of noise
        Server.EventMask = 0x3ff;
        Server.SetEventsCallBack(TheEventCallBack, IntPtr.Zero);
        Server.SetRWAreaCallBack(TheRWAreaCallBack, IntPtr.Zero);

        // Uncomment next line if you don't want to see wrapped messages
        // (Note : Doesn't work in Mono 2.10)

        Console.SetBufferSize(100, Int16.MaxValue - 1);

        // Start the server onto the default adapter.
        // To select an adapter we have to use Server->StartTo("192.168.x.y").
        // Start() is the same of StartTo("0.0.0.0");
        int Error = Server.Start();

        if (Error == 0)
        {
            // Now the server is running ... wait a key to terminate
            Console.ReadKey();
            Server.Stop();
        }
        else
        {
            Console.WriteLine(Server.ErrorText(Error));
        }
        // If you got a start error:
        // Windows - most likely you ar running the server in a pc on wich is
        //           installed step 7 : open a command prompt and type
        //             "net stop s7oiehsx"    (Win32) or
        //             "net stop s7oiehsx64"  (Win64)
        //           And after this test :
        //             "net start s7oiehsx"   (Win32) or
        //             "net start s7oiehsx64" (Win64)
        // Unix - you need root rights :-( because the isotcp port (102) is
        //        low and so it's considered "privileged".
    }