Difference between revisions of "Execute a script"

From Proview Wiki
Jump to: navigation, search
Line 6: Line 6:
 
Using pwrc (wb_cmd) command : wb_cmd -v MyRootVolumeName @config_from_excel<br /><br />
 
Using pwrc (wb_cmd) command : wb_cmd -v MyRootVolumeName @config_from_excel<br /><br />
  
'''Example csv file: (config_from_excel.csv) '''
+
'''Example csv file: (config_from_excel) '''
 
  <nowiki>
 
  <nowiki>
  
Line 53: Line 53:
 
!
 
!
 
!              Name of the file to read
 
!              Name of the file to read
   string filename = "test.csv";
+
   string filename = "'''test.csv'''";
 
!
 
!
 
   int file;
 
   int file;

Revision as of 06:07, 24 August 2013

In Proview you can use scripts to read csv files and create both the signal, card, channel objects and to connect them.
This can be handy to create the signals in the database so it is not necessary to create them one bye one with the editor.

A script-file can be executed from the command-line with the command:

wtt> @'filename'
Or
Using pwrc (wb_cmd) command : wb_cmd -v MyRootVolumeName @config_from_excel

Example csv file: (config_from_excel)


! Start with "wb_cmd -v volvfssx3 @config_from_excel"
!
! The .csv file should look like this
!
! Signalname              Class   Signal description         
! =====================   ====== =====================
! VFS-SX3-LM-AS13-KlippTK; Di    ;TK SAX 3 KLIPP +AS13  BL.21
!
! Hint, set a comment on "save" on the bottom row the first time to check that
! everything works.
! 

!
! Create an object and it's ancestors if they doesn't exist
!
function int  create_object( string name, string class)
  int	 i;
  int	 j;
  string parent;
  string object;
  int	 sts;

  i = strrchr( name, "-");
  if ( i)
    i++;
    j = i - 2;
    parent = extract( 1, j, name);
    object = extract( i, 80, name);
  else
    object = name;
    parent = "";
  endif
  if ( !ObjectExist( name))
    if ( parent != "")
      create_object( parent, class);
    endif
    create object/dest="'parent'"/class='class'/name="'object'"
  endif
endfunction


main()
!
!               Name of the file to read
  string	filename = "'''test.csv'''";
!
  int 		file;
  string        str;
  string 	name_str;
  string 	class_str;
  string 	descr_str;

  !verify(1);
  file = fopen( filename, "r");
  if ( !file)
    printf( "Unable to open %s\n", filename);
    exit();
  endif

  while ( fgets( str, file))
    if ( extract( 1, 1, str) == "!")
      continue;
    endif
    name_str = felement( 1, ";");
    if ( strlen( name_str) == 0)
      continue;
    endif
    name_str = edit( name_str);
    class_str = felement( 2, ";");
    class_str = edit( class_str);
    descr_str = felement( 3, ";");
    printf( "Processing signal: %s\n", name_str);

    create_object( name_str, class_str);
    set attr/noco/name='name_str'/attr=Description/value="'descr_str'"
  endwhile
  fclose( file);
!  save 
endmain



You can only set one attribute in a 'set value' command
It is possible to create objects in the nodes hierarchy and the Plant

The default directory is the one you started the configurator from.
Note that there is a menu entry Options/Script/Project that will show all the scripts on $pwrp_login.
You can exectute them by clicking on the icon or doubleclick on the text.

You need read access to the script files.

You can't run tne pwr_com scripts in the runtime environment, you can only execute them in the development environment with pwrc or in the configurator.
In the runtime environment you have the similar rtt_com scripts with xtt commands and functions.
They can be executed from rt_xtt and rt_rtt.

You can read about scripts in the Script chapter in Designer's Guide or search the forum

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox