Exemplo n.º 1
0
 //------------------------------------------------------------------------------
 // Main                                                
 //------------------------------------------------------------------------------
 static void Main(string[] args)
 {
     int SndError = 0;
     // Get Progran args
     if (args.Length != 1)
     {
         Usage();
         return;
     }
     // Create the ACTIVE partner
     Partner = new S7Partner(1);
     // Start
     // Local Address for an active partner is meaningless, leave
     // it always set to "0.0.0.0"
     int Error=Partner.StartTo("0.0.0.0", args[0], 0x1002, 0x1002);
     if (Error != 0)
     {
         Console.WriteLine(Partner.ErrorText(Error));
         return;
     }           
     // Endless loop : Exit with Ctrl-C       
     while (true)
     {
         while (!Partner.Linked)
         {
             Console.WriteLine("Connecting to " + args[0] + "...");
             System.Threading.Thread.Sleep(500);
         };
         do
         {
             PrepareBuffer();
             SndError = Partner.BSend(0x00000001, Buffer, size);
             if (SndError == 0)
                 Console.WriteLine("Succesfully sent "+size.ToString()+" bytes");
             else
                 Console.WriteLine(Partner.ErrorText(SndError));
             System.Threading.Thread.Sleep(300);
         } while (SndError == 0);
     }
 }
Exemplo n.º 2
0
 //------------------------------------------------------------------------------
 // Main                                                
 //------------------------------------------------------------------------------
 static void Main(string[] args)
 {
     // Get Progran args
     if (args.Length != 1)
     {
         Usage();
         return;
     }
     // Create the PASSIVE partner
     Partner = new S7Partner(0);
     
     // Set the BRecv callback (using the static var to avoid the garbage collect)
     CallBack = new S7Partner.S7ParRecvCallback(RecvCallback);
     Partner.SetRecvCallback(CallBack, IntPtr.Zero);
     
     // Start
     int Error=Partner.StartTo("0.0.0.0", args[0], 0x1002, 0x1002);
     if (Error == 0)
         Console.WriteLine("Passive partner started");
     else
         Console.WriteLine(Partner.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".
     Console.ReadKey();
     Partner.Stop(); 
 }