PcVue 11 DataExports Excel

Partie du forum pour tout ce qui concerne la supervision industrielle. Forum, conseil, astuce et entraide sur les logiciels de supervision tels que PC Vue, Vijeo designer, WinCC, win cc, monitor pro, so machine, Citect, Intouch .
Répondre
micka
Apprend le binaire
Apprend le binaire
Messages : 3
Enregistré le : 02 janv. 2017, 10:18

PcVue 11 DataExports Excel

Message par micka »

Bonjour à tous

Je me permets de solliciter votre aide, car je suis face à un problème pour exporter les données de PCvue

J’ai créé les variables dans Exports de données dans l’Application Explorer, quand je génère manuellement l’export des données tout fonctionne correctement je retrouve bien mes fichier Excel dans le dossier DataExport de mon application.

Je souhaite effectuer l’export via un bouton sur ma supervision ; j’applique donc l’animation forçage programme.

Hors je suis bloqué sur la rédaction du script dans l’éditeur SCADABasic du programme à forcer, avez-vous déjà réalisé un script pour générer l’exportation es données. Quelqu’un peut-il m’aider

Merci à tous
Avatar du membre
maxpeigne
Dieu du process
Dieu du process
Messages : 771
Enregistré le : 11 oct. 2015, 17:31
Localisation : Nord pas de calais

Re: PcVue 11 DataExports Excel

Message par maxpeigne »

J'ai fais quelque chose du genre mais c'etait sous PCVue 7.20D.

Dans le dossier "P", il y a un script nommé "rapport.prg". Il est plutot bien documenté, en enlevant quelques commentaires, tu arriveras à faire ce que tu souhaites.

J'espere simplement qu'il est encore présent dans la version 11...
http://automacile.fr - Site et tutoriels sur l'arduino.
micka
Apprend le binaire
Apprend le binaire
Messages : 3
Enregistré le : 02 janv. 2017, 10:18

Re: PcVue 11 DataExports Excel

Message par micka »

Bonjour merci pour l’info

Dans le dossier "P", le script nommé "rapport.prg" n’est plus présent sur PC Vue 11
Avatar du membre
maxpeigne
Dieu du process
Dieu du process
Messages : 771
Enregistré le : 11 oct. 2015, 17:31
Localisation : Nord pas de calais

Re: PcVue 11 DataExports Excel

Message par maxpeigne »

Je te le copie ici:

Code : Tout sélectionner

'Version 1
'************************************************************************
'Ce programme permet d'obtenir des rapports journaliers et mensuels
'au format csv  directement exploitables sous EXCEL .
'************************************************************************

' ** Utilisation ** :  

'Ce programme lit  pour chaque rapport un fichier contenant la liste des variables  .
' Un fichier facultatif  pourra  contenir le titre du rapport .
'Ces fichiers seront dans la directory  TP du projet .
'On pourra les modifier dynamiquement en run time.

'Par exemple le fichier report1 contiendra les noms de variables  :
'DATE
'TIME
'MOTEUR1.TEMPS
'MOTEUR2.TEMPS

'Le fichier facultatif Report1_Title  contiendrait par exemple
'les titres de chaque colonne  :
'Date;Heure;Temps Moteur1;Temps Moteur2
'Ne pas oublier d'effectuer un saut de ligne en fin de ce fichier.

'On obtiendra automatiquement un exemplaire de ces deux fichiers en executant le main( )
'avec  une variable creation_option  valant 1 .



'En sortie pour le rapport report1 par exemple on obtiendra les fichiers suivants  :
' un journalier report1_Jour_Mois_Annee_D.csv 
' un mensuel    report1_Mois_Annee_M.csv     
'Le nom de ces fichiers est configurable en modifiant les variables Day_Format et 
'Month_Format

'Ils seront dans la directory TP du projet mais on pourra changer le chemin 
'en modifiant  la variable Path_reports du programme.


' Lancement:

'Le programme Report.prg pourrait se lancer  en utilisant l'instruction 
'PROGRAM ("START","/UTILITIES/Report_v1.prg" , "");
'Il faut par contre l'adapter et donc  le recopier dans la directory P de votre projet.
'L'instruction devient alors :
'PROGRAM ("START","Report_v1.prg" , "");

'Il faut modifier la fonction  main  en ajoutant  un appel Add_report  pour chaque rapport voulu .
'Par exemple pour obtenir deux rapports report1 et report2 la fonction contiendra
'les deux lignes suivantes :
'Add_report( "report1" ) ;
'Add_report( "report2" ) ;


'Execution :

'Chaque appel de la fonction write_reports ( ) se traduira par une nouvel enregistrement 
'des valeurs des variables .


'************************************************************************
'************************************************************************
'************************************************************************
'************************************************************************
'************************************************************************


const  Type_Bit=1 ;
const  Type_Register=2;
const  Type_Text=4 ;
const  Type_Alarm=8 ;
const  MAX_REPORTS=64 ;		
Dim  Number_reports as integer ;
Dim list_report[64] as str ; 
dim Path_reports  as str; 			'Path for the reports 
dim separator as str;		'separator
Dim Day_Format  as str;		'Configurable format of the day file report
Dim Month_Format as str;		'Configurable format of the Month file report
Dim title_extension as str;		'extension  for the title file
Dim creation_option as integer   ;         ' Option to create a sample files =1 create
Dim main_executed  as integer;          ' ( =0 main program not executed ) (=1 executed )
'*************************************************************

'-------------------------------------------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------------------------------------------


sub main ( )

main_executed              =1 ; 	 'The main program has been executed once


'*************************************************************
'**********Locals variables which can be modified  ******
'*************************************************************
'  path for the generated files 
' Path_reports ="d:\\Reports\\" ;	'to store in d:\reports for instance

Path_reports	      ="" ;		'By default inside the TP directory of the  project
'Path_reports ="d:\\Reports\\" ;	'to store in d:\reports for instance

separator	                     =",";		'separator between values 
Title_extension              ="_title" ;	 'extension to get the report title Example report1_title

'for the meaning of the # caracters check the scada basic datetimestring instruction 
Day_Format                  ="_#D_#M_###Y_D.csv" ;     'Format for the daily reports
Month_Format 	        ="_#M_###Y_M.csv" ;      'Format for the monthly reports

creation_option              =1; 		' if 1 an automatic sample will be created .

'*************************************************************

Add_report( "epaisseur_pnx" ) ;
'Add_report( "report2" ) ;

'*************************************************************
' Example to program a scheduler to write the reports each hour
 ' Crontab ("ADDPROG","EACH_HOUR","","00","Report_v1.prg","","write_reports");


end sub 



'-------------------------------------------------------------------------------------------------------------------------------

sub write_reports ( )
dim i_report as integer;
' this function must be called to write a new record inside the differents reports 
'for example you can  use a scheduled action with a frequency of each hour :
'
if ( main_executed ==0 ) then	'security 
	  main ( );		' Execute the main program because it was not executed
end if
for (  i_report = 0  ;  i_report < Number_reports ;  i_report++ )
	'print (  i_report , "  " ,    List_report[ i_report]  );
 	  Write_record (  List_report[ i_report]  ) ;
next 
end sub

'-------------------------------------------------------------------------------------------------------------------------------

sub Add_report (which_report)
' This function adds  a new report to the  list 

dim ret as integer;
dim sample_title as str;
dim report_title_file as str;

fclose(which_report );
ret=fopen (which_report, "r") ;
fclose(which_report );
if (ret ==0 ) then			'report  does not exist
	if ( creation_option ) then	'Create a sample for the report
		' create a sample variable file
		create_file (which_report , "DATE\nTIME\n\SYSTEM.STATION_NUMBER") ;
		' create a sample title  file
		sample_title = concat("Example title ", which_report,";time;Number of the station\n") ;

		report_title_file=addstring (which_report,Title_extension) ;
		create_file (report_title_file,sample_title )  ;
	else
		print ("Unknown report file " , which_report );
		return ( 0) ;
	end if
end if
' add to the list
if (Number_reports < MAX_REPORTS ) then
	List_report[Number_reports]=which_report ;
	Number_reports=Number_reports +1 ;
  'print (Number_reports , " reports   " ,which_report );
else 
	print (Number_reports , " Too many reports for  " ,which_report );
end if
end sub

'-------------------------------------------------------------------------------------------------------------------------------



sub Write_record (which_report)
' This function adds  a new record to the  report named  which_report
'
dim j_nbvar as integer;
dim info as str;
dim  Value_Register as single;		'Register value
dim  Value_Bit  as integer;		'Bit value
dim  Value_Text as str;		'Text value
dim report_title_file as str ;		'Title for the report
dim model_buffer as long;
dim eof as integer;
dim variable_name as str;		'variable name 
dim Destination_File as str;		
dim Day_file as str;
dim Month_file as str;
dim File_Format as str;
dim ret as integer;
dim Type as integer;			'variable type
j_nbvar=0;			'variable index

fclose(which_report );
ret=fopen (which_report, "r") ;
if (ret ==0 ) then			'file does not exist
		print ("Unknown file " , which_report );
		return ( 0 );
end if

Destination_File=addstring(Path_reports ,which_report );	'adds the path

File_Format=datetimestring (datetimevalue ( ), Day_Format  );
Day_file=addstring (Destination_File,File_Format);	'Day file name
File_Format=datetimestring (datetimevalue ( ), Month_Format  );
Month_file=addstring (Destination_File,File_Format);	'Month file name

report_title_file=addstring (which_report,Title_extension) ;
 model_buffer=0;
model_buffer=filetobuf(report_title_file);	
if ( model_buffer ) then 			'there is a title file
   Copy_model (  model_buffer,Day_file ) ;	  'copies a model to  Day_file
   Copy_model (  model_buffer,Month_file ) ;	 'copies a model to the Month_file
 free_buffer (model_buffer);		'free the allocated buffer
end if

fclose (Day_file);
fclose (Month_file);
fopen ( Day_file     , "a" );	                             'open to write at the end (append mode)
fopen ( Month_file  , "a" );	                             'open to write at the end (append mode)

'print (" files ", Day_file, "   " ,Month_file);
eof=0;
while (eof==0)
variable_name=fgets( which_report, 128);
variable_name=ltrim( rtrim ( variable_name)); 	'remove spaces 
eof=feof( which_report);

	if ( variable("STATUS",variable_name,"exist" ) )then
		Type=variable("GET_TYPE",variable_name);
		if (Type==Type_Register  )then
			Value_Register=?variable_name;	'Register value
			info=toc(Value_Register);
		else 
		if (Type==Type_Bit || Type==Type_Alarm )then
			Value_Bit=?variable_name;		'Bit value
			info=toc(Value_Bit);
		else
		if (Type==Type_Text  )then
			info=?variable_name;		'Text value
		end if
		end if
		end if
		if ( variable("STATUS",variable_name,"VALID" ) ==0) then
			info="?" ;
		end if
	else		'the variable does not exist
		if ( cmpstring ( variable_name, "" )==0) then
			info="";   		'empty variable  reserved one ?
		else
			info=addstring("????  unexisting variable  " ,variable_name);
			print ( "????  unexisting variable  " ,variable_name );
		end if
	end if
if ( j_nbvar  ) then 
	info=addstring(separator ,info );
end if
fputs ( Day_file,info);
fputs ( Month_file,info);
j_nbvar++;
' print ( j_nbvar,"  variable " ,variable_name , "  " , Type  );		

wend


fputs ( Day_file,"\n");	 'adds a rclf ( go to next line )
fputs ( Month_file,"\n");	'adds a rclf ( go to next line )

fclose ( which_report);
fclose (Day_file);
fclose (Month_file);


end sub
'-------------------------------------------------------------------------------------------------------------------------------


sub Copy_model ( model_file, file ) 
'This function will copy a buffer model file to an empty file 
fclose (file );
if (fopen ( file, "r" )==0 ) then 		' new   file  copy the model if exist
	buftofile ( model_file,file);  'copy the model title
end if
fclose (file);
end sub

'-------------------------------------------------------------------------------------------------------------------------------

sub concat ( str1,str2,str3 )
' This function returns  a string equals to str1+str2+str3
dim  ch as str;
ch=addstring( str1,str2) ;
ch=addstring( ch,str3) ;
return ( ch );
end sub

'-------------------------------------------------------------------------------------------------------------------------------


sub create_file ( file , content )
fclose (file );
if ( fopen (file, "r") ==0 ) then		'file does not exist 
	fopen (file , "w");		'create file
	fputs (file ,content  );
	fclose (file );
print ( "file " ,file  ," does not exist ??? a sample file has  been created " );
end if
end sub 

Vois si ca fonctionne sous ta version.
http://automacile.fr - Site et tutoriels sur l'arduino.
micka
Apprend le binaire
Apprend le binaire
Messages : 3
Enregistré le : 02 janv. 2017, 10:18

Re: PcVue 11 DataExports Excel

Message par micka »

Merci pour le retour
Avatar du membre
maxpeigne
Dieu du process
Dieu du process
Messages : 771
Enregistré le : 11 oct. 2015, 17:31
Localisation : Nord pas de calais

Re: PcVue 11 DataExports Excel

Message par maxpeigne »

micka a écrit :Merci pour le retour
Ca sera surtout a toi de nous faire un retour pour savoir si ca marche ;)
http://automacile.fr - Site et tutoriels sur l'arduino.
Niamor
Apprend le binaire
Apprend le binaire
Messages : 1
Enregistré le : 16 déc. 2016, 12:12

Re: PcVue 11 DataExports Excel

Message par Niamor »

Le script dont parle Maxpeigne ne semble plus être fournit depuis l'arrivée du Data Export qui permet de faire des export de données beaucoup plus aisement.

As tu regardé dans l'aide s'il n'y pas un exemple de script ? De mémoire c'est l'instruction EXPORT qu'il faut utilisé.

As tu pensé à contacter le support de PcVue ?
Répondre