plc.myforum.ro Forum Index plc.myforum.ro
PLCs users www.plc.myforum.ro!
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How do you safely close WinCC by means of an external applic

 
Post new topic   Reply to topic    plc.myforum.ro Forum Index -> ROSIEMENS SIMATIC HMI
View previous topic :: View next topic  
Author Message
gert
Member 3
Member 3
gert

Joined: 02 Jan 2015
Posts: 645

PostPosted: 14/05/2015 19:37    Post subject: How do you safely close WinCC by means of an external applic Reply with quote

How do you safely close WinCC by means of an external application?

In certain cases, for example when using an uninterruptible power supply (UPS), it might be necessary to close WinCC and shut down the operating system by means of an external program.
The download in this entry contains a source code which you can use to resolve the task described.
To be able to use the function you must employ a UPS that can start the program automatically when power failure is detected.

Instructions
1 Download the text file located at the bottom of this entry.
2 Create a new C++ project (with Visual Studio, for example).
3 In the project properties you set the character set to "Multibyte". You do this, for example, in Microsoft Visual Studio 2010 via "Project > 'Project name' properties > Configuration properties > General > Character set".
4 Copy the source code into the project.
5 Replace the parameter of the function DMEXITWINCCEXFCT in line 45 with one of the following parameters:

DM_SDMODE_WINCC Closes WinCC
DM_SDMODE_LOGOFF Closes WinCC and logs off the user logged on to the operating system
DM_SDMODE_SYSTEM Closes WinCC and shuts down the operating system
DM_SDMODE_REBOOT Closes WinCC and restarts the operating system
DM_SDMODE_FORCE_POWEROFF Closes WinCC, shuts down the operating system and switches off the computer
6 Copy the header files "dmclient.h", "ohioapi.h", "dmdefs.h" and "license.h" from the "Installation path > Siemens > WinCC > aplib" folder into the project folder.
7 Compile the project.
8 Change the settings of the UPS so that when a power failure is detected, the executable file of the project(Shutdown_WinCC.exe, for example) is called.
Code:

#include "dmclient.h"
#include <stdio>
#include <time>

void main()
{

   FILE *fp=NULL;
   BOOL bRetVal=FALSE;
   time_t t;
   struct tm *tl;
   fp=fopen("ShutdownWinCC.log","w"); //Open Logfile
   
   if (fp != NULL)
   {
      int iResult=0;

      CMN_ERROR Error;
      memset(&Error, 0,sizeof(CMN_ERROR));
      BOOL ret = FALSE;
      TCHAR szAppName[255];
      VOID* pvUser = NULL;
      strcpy(szAppName,"ShutdownWinCC");

      HMODULE hDMClient = LoadLibrary("dmclient.dll");
      DMCONNECTFCTA DMCONNECTFCT = NULL;
      DMDISCONNECTFCTA DMDISCONNECTFCT = NULL;
      DMEXITWINCCEXFCTA DMEXITWINCCEXFCT = NULL;

      if(hDMClient != NULL)
      {

         DMCONNECTFCT = (DMCONNECTFCTA) GetProcAddress(hDMClient, "DMConnectA");

         if(DMCONNECTFCT)
         {
            t = time(NULL);
            tl = localtime(&t);
            bRetVal = DMCONNECTFCT(szAppName, NULL, pvUser, &Error);
            fprintf(fp,"%s; DMconnect OK!\n",asctime(tl));
         }

         DMEXITWINCCEXFCT = (DMEXITWINCCEXFCTA) GetProcAddress(hDMClient, "DMExitWinCCExA");

         if(DMEXITWINCCEXFCT)
         {
            bRetVal = DMEXITWINCCEXFCT(DM_SDMODE_FORCE_POWEROFF); // Terminate WinCC + Shutdown windows and power off by force
         }
            
         if(!bRetVal)
         {
            t = time(NULL);
            tl = localtime(&t);
            fprintf(fp,"%s; WinCC shutdown failed!\n",asctime(tl));
         }
         else
         {
            t = time(NULL);
            tl = localtime(&t);
            fprintf(fp,"%s; WinCC shutdown successful!\n",asctime(tl));
         }
   
         DMDISCONNECTFCT = (DMDISCONNECTFCTA) GetProcAddress(hDMClient, "DMDisConnectA");
         if(DMDISCONNECTFCT)
         {      
            bRetVal = DMDISCONNECTFCT( &Error);
            t = time(NULL);
            tl = localtime(&t);
            fprintf(fp,"%s; DMDisconnect OK!\n",asctime(tl));
            FreeLibrary(hDMClient);
         }
   
      }

      fclose(fp);
   }
}

On Line 45:
DMEXITWINCCEXFCT(DM_SDMODE_FORCE_POWEROFF); // Terminate WinCC + Shutdown windows and power off by force
Replace with one of the above bolded
Copy the "Shutdown_WinCC.txt" file into a separate directory and then follow the instructions given above.
http://www.datafilehost.com/d/6dcc74c9
Back to top
View user's profile Send private message
tnq13
Junior
Junior


Joined: 31 Jul 2018
Posts: 2

PostPosted: 13/01/2019 18:07    Post subject: Reply with quote

i was not able to downlaod de txt file. Can you post it's content here??
thanks in advance
Back to top
View user's profile Send private message
gert
Member 3
Member 3
gert

Joined: 02 Jan 2015
Posts: 645

PostPosted: 13/01/2019 21:53    Post subject: Reply with quote

It's the same text as in forum
https://megaupload.nz/41kb4bqebe/shutdown_wincc_zip
Back to top
View user's profile Send private message
tnq13
Junior
Junior


Joined: 31 Jul 2018
Posts: 2

PostPosted: 14/01/2019 13:07    Post subject: Reply with quote

I was able to find the Siemens FAQ: https://support.industry.siemens.com/cs/document/89257244/how-do-you-
safely-close-wincc-via-an-external-application-?dti=0&lc=en-GT

Where I was able to download the TXT file (in fact, it contains only the code!)

Another issue that I had was that I tried to compile the program using Visual Studio 2017, that complied the program using the definitions for Windows 10 family. I then downloaded the VS 2013, after compiling the program, I had the a issue with a DLL, as my system is 64-bit, I had to put the required DLL into C:\Windows\SysWOW64.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    plc.myforum.ro Forum Index -> ROSIEMENS SIMATIC HMI All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Fa-ti si tu propriul forum GRATUIT, pe www.myforum.ro