Example #1
0
int main(int argc, char* argv[])
{
    int Error;
	char text[1024];

	Server = Srv_Create();

    // Share some resources with our virtual PLC
    Srv_RegisterArea(Server,
		     srvAreaDB,     // We are registering a DB
                     1,             // Its number is 1 (DB1)
                     &DB1,          // Our buffer for DB1
                     sizeof(DB1));  // Its size
    // Do the same for DB2 and DB3
    Srv_RegisterArea(Server, srvAreaDB, 2, &DB2, sizeof(DB2));
    Srv_RegisterArea(Server, srvAreaDB, 3, &DB3, sizeof(DB3));

    // change component identification
    Srv_SetSZL(Server, SZL_ID_001C, SZLC_ID_001C_IDX_XXXX,
    			sizeof(SZLC_ID_001C_IDX_XXXX));

    // Set the event callback to show something : it's not strictly needed.
    // If you comment next line the server still works fine.
    Srv_SetEventsCallback(Server, EventCallBack, NULL);

    // Start the server onto the default adapter.
    // To select an adapter we have to use Srv_StartTo(Server, "192.168.x.y").
    // Start() is the same of StartTo("0.0.0.0");
    Error=Srv_Start(Server);
    if (Error==0)
    {
	// Now the server is running ... wait a key to terminate
        getchar();
    }
    else
	{
        Srv_ErrorText(Error, text, 1024);
        printf("%s\n", text);
	}

    // 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".

    Srv_Stop(Server); // <- not strictly needed, every server is stopped on deletion
                    //    and every client is gracefully disconnected.
	Srv_Destroy(&Server);
	return 0;
}
Example #2
0
//---------------------------------------------------------------------------
int TS7Server::RegisterArea(int AreaCode, word Index, void *pUsrData, word Size)
{
    return Srv_RegisterArea(Server, AreaCode, Index, pUsrData, Size);
}