È possibile eseguire i file degli script (nomefile.py), contenenti una sequenza di comandi di script, dall'interfaccia utente di EcoStruxure Machine Expert.
Per ulteriori informazioni sull'esecuzione degli script dall'interfaccia utente di EcoStruxure Machine Expert, consultare il capitolo Comandi correlati agli script.
Comandi utilizzati frequentemente
Comando |
Descrizione |
---|---|
- REM oppure :: |
La riga è un commento e viene ignorata. |
cd |
Passa a un'altra directory. |
echo off |
I comandi non vengono visualizzati. Per evitare la visualizzazione dei singoli comandi, inserire un carattere @ davanti al comando. |
echo |
Visualizza una stringa o variabile nella console di programmazione. |
set |
Dichiara una variabile e vi assegna un valore. |
> |
Scrive il risultato su file. Il file, se è già esistente, viene sovrascritto. |
>> |
Aggiunge il risultato a un file. Il file, se non esiste, viene creato. |
Esempio di applicazione:
@echo off
REM Go to the directory where EcoStruxure Machine Expert is installed
cd "<Replace this with the path to the LogicBuilder.exe, for example, C:\Program Files (x86)\Schneider Electric\SoMachine Software\>"
REM Run LogicBuilder.exe with no graphical user interface and the full path to the script
LogicBuilder.exe --noui --runscript="<Replace this with the full file path where the script is stored, for example, D:\MyScripts\TestScript.py>"
pause
Eseguendo lo script in un'applicazione C# è possibile modificare lo script in modo dinamico prima che lo script venga eseguito dal motore. Inoltre, è anche possibile eseguire alcuni passi precedenti nell'applicazione C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace ExecuteScriptExample
{
class Program
{
static void Main(string[] args)
{
try
{
ProcessStartInfo psi = new ProcessStartInfo();
// Specify the name and the arguments you want to pass
psi.FileName = @"<Replace this with the path to the LogicBuilderShell.exe, for example, C:\Program Files (x86)\Schneider Electric\SoMachine Software\LogicBuilderShell.exe";
psi.Arguments = "\ "<Replace this with the full file path where the script is stored, for example, D:\MyScripts\TestScript.py\"";
// Create new process and set the starting information
Process p = new Process();
p.StartInfo = psi;
// Set this so that you can tell when the process has completed
p.EnableRaisingEvents = true;
p.Start();
// Wait until the process has completed
while (!p.HasExited)
{
System.Threading.Thread.Sleep(1000);
}
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
Console.ReadKey();
}
}
}