Back

Topic

[KB313]How to restart a PcVue project – svrestart.exe

Tags: Addon, Scada Basic, Start, Startup, VBA

15 years ago
By RM
Options
Print

Applies to:

 

PcVue version 7.00 onwards


Summary:

 

This article describes how to restart a PcVue project by using the executable “SvRestart.exe”.
An attached project, made with version 8.2 of PcVue, purposes 3 ways to launch this executable in a multi-station environment:

  • VB script function (deprecated)
  • VBA function (deprecated)
  • SCADA Basic function

Note:

 

The executable “SvRestart.exe” is a program originally compiled with Framework 1.1. From PcVue version 8.2, Framework 1.1 is no longer used by PcVue and a new version of “SvRestart.exe” compiled with Framework 2.0 has been created.From PcVue version 11.0, PcVue installs Framework 4.5, which does not contain Framework 2.0. For installations without Framework 2.0, a new version of SvRestart.exe, compiled with Framework 4.0, has been produced.

PcVue   SvRestart
 Version   Framework       Version File
 From 7.00 to 8.00  none or V1.1   1.0 svrestart_FW1.1.exe
 From 8.10 to 10.0  V2.0    1.1 svrestart_FW2.0.exe
 From 11.0  V4.5    1.2 svrestart_FW4.0.exe

Details:

 

Once launched, SvRestart.exe waits that PcVue stops, and then restarts another program according to arguments. SvRestart.exe needs some arguments to be correctly executed.
Command line:
[PathSvRestart]svrestart.exe  [ProcessId]  “[PcVueExePath]” “ [PcVueArguments]” “[MessageToDisplay]”

  • [ProcessId] ID of sv32.exe running process
  • [PcVueExePath] Executable file of PcVue (with path)
  • [PcVueArguments] PcVue arguments.
  • [MessageToDisplay] Message displayed in svrestart message box.

Important: If quotes are needed in an argument (for path included space char), use the character | (pipe)

Example of command line:

C:\PcVue Projects\USR\DEMO_SVRESTART\Tp\SvRestart.exe 2592 “C:\PCVUE\PcVue 8.2\bin\sv32.exe” “-b |C:\PcVue Projects| -p |DEMO_SVRESTART| -r” “Restart Project DEMO_SVRESTART”


Solution (demo project with svrestart.exe in Project TP directory)To find the PcVue ProcessId, an API can be used: GetCurrentProcessId
  • In SCADA Basic, the script must be integrated in a preloaded SCADA Basic program. Run the Restart_PcVue function to launch the restart procedure. the function GetSvPath gets the PcVue path directory.
‘Declare Function GetCurrentProcessId Lib “kernel32” Alias “GetCurrentProcessId” () As Long;
‘Declare Function GetModuleFileNameEx Lib “psapi.dll” Alias “GetModuleFileNameExA” (hProcess As Long, hModule As Long, lpFilename As Long, nSize As Long) As Long;
‘Declare Function OpenProcess Lib “kernel32” (dwDesiredAccess As Long, bInheritHandle As Long, dwProcessId As Long) As Long;
‘Declare Function CloseHandle Lib “kernel32” (hObject As Long) As Long;

Sub Main()

End sub

Sub Restart_PcVue()

Dim SvProjectsPath as str;
Dim SvProjectPath as str;
Dim SvProjectName as str;
Dim SvPath As Str   ;             ‘Path of sv32.exe
Dim SvRestartPath As Str ;     ‘Path of SvRestart.exe
Dim CommandLine As Str ;     ‘Shell Command line
Dim Args As Str;                    ‘Arguments for SvRestart.exe
Dim MyId As Long ;                ‘Process Id of Pcvue32 get by system Dll
Dim i as integer;
Dim sMsg as str;                    ‘Message to display

MyId = GetCurrentProcessId() ;
SvProjectPath = GETPROJECTDIR();
SvPath =ADDSTRING ( “\”” , ADDSTRING ( GetSvPath ( MyId ) , “\””) );

While ( ASC( Right( SvProjectPath , i++) ) != ASC(“\\”) )

Wend

SvProjectName = ADDSTRING (“|”  ,  ADDSTRING (Right( SvProjectPath , i – 2)  ,   “|” ))  ;
SvProjectsPath = ADDSTRING (“|”  ,  ADDSTRING  (Left ( SvProjectPath , LEN (SvProjectPath ) – LEN (ADDSTRING (“USR” , SvProjectName))) , “|” )) ;

SvRestartPath = ADDSTRING (SvProjectPath , “\\TP\\svrestart.exe” );

Args = ADDSTRING ( ” ”  ,  TOC(MyId) );
Args = ADDSTRING (Args , ADDSTRING (  ” ”         , SvPath              )  );
Args = ADDSTRING (Args , ADDSTRING ( ” \”-b ” , SvProjectsPath ));
Args = ADDSTRING (Args , “\”” );

sMsg = ADDSTRING (” Restart via SCADA Basic: Project ” , SvProjectName );
sMsg = ADDSTRING ( ” \”” , ADDSTRING (sMsg , “\”” ) ) ;

APPLICATION(“LOAD”, SvRestartPath, ADDSTRING   ( Args, sMsg ) );

SYSTEM(“EXIT”);

end sub

‘Function that returns SvPath according to SvProcessId

Sub GetSvPath(ProcessID)

dim lBufProc as long;
dim lBufName as long;
dim lMaxSize as long;
dim sRet as str;

lMaxSize = 255;

lBufName = ALLOC_BUFFER( lMaxSize );
lBufProc = OpenProcess(  1040 , 0  , ProcessID );
GetModuleFileNameEx(   lBufProc , 0, lBufName  , lMaxSize );
CloseHandle( lBufProc  );

sRet = CGET_BUFFER( lBufName  , 0, lMaxSize );

FREE_BUFFER (lBufName);
SRet = LTRIM (sRet);

Return ( SRet);

end sub

Multi-station configuration

In a network architecture, in order to be able to restart a PcVue station from any other station,we can create 1 PcVue variable and 1 PcVue event per PcVue station. The proposal solution is thus:

Object to create

Name (for example)

Parameters

Variables @RESTART.[Station_Name] type bit
producer [Station_Name]
customer [All_Stations]
Events RESTART_[Station_Name] trigger @RESTART.[Station_Name]
transition 0>1
producer [Station_Name]
function to execute Restart_PcVue

Download attachments:

 

Created on: 23 Dec 2010 Last update: 31 Mar 2025