a/trunk/cforge/cforge/Helper.cs | b/trunk/cforge/cforge/Helper.cs | ||
---|---|---|---|
... |
... |
||
150 | } |
150 | } |
151 | // for now return a normal installation path for CODESYS |
151 | // for now return a normal installation path for CODESYS |
152 | return @"C:\Program Files (x86)\3S CODESYS\CODESYS\"; |
152 | return @"C:\Program Files (x86)\3S CODESYS\CODESYS\"; |
153 | } |
153 | } |
154 | 154 | ||
155 | /// <summary> |
||
156 | /// Function to retrieve the "ScriptLib" Path inside CODESYS. We just take the last one, probably this is the newest one |
||
157 | /// </summary> |
||
158 | /// <returns>full path to ScriptLib version folder</returns> |
||
159 | private static String GetCODESYSScriptingLibPath() |
||
160 | { |
||
161 | String path = Path.Combine(GetCODESYSRoot(), "ScriptLib"); |
||
162 | String version = Directory.EnumerateDirectories(path).Last(); |
||
163 | |||
164 | path = Path.Combine(path, version); |
||
165 | |||
166 | return path; |
||
167 | } |
||
155 | 168 | ||
156 | /// <summary> |
169 | /// <summary> |
157 | /// Function to retrieve the CFORGE Script path (this is where the IronPython scripts should reside) |
170 | /// Function to retrieve the CFORGE Script path (this is where the IronPython scripts should reside) |
158 | /// </summary> |
171 | /// </summary> |
159 | /// <returns>full path to CFORGE Scripts</returns> |
172 | /// <returns>full path to CFORGE Scripts</returns> |
... |
... |
||
253 | 266 | ||
254 | //ScriptEngine engine = Python.CreateEngine(); |
267 | //ScriptEngine engine = Python.CreateEngine(); |
255 | ScriptEngine engine = IronPython.Hosting.Python.CreateEngine(new Dictionary<string, object> { { "Debug", ScriptingRuntimeHelpers.True } }); |
268 | ScriptEngine engine = IronPython.Hosting.Python.CreateEngine(new Dictionary<string, object> { { "Debug", ScriptingRuntimeHelpers.True } }); |
256 | Debug.Assert(engine.Runtime.Setup.DebugMode); |
269 | Debug.Assert(engine.Runtime.Setup.DebugMode); |
257 | 270 | ||
271 | String strScriptingPath = GetCODESYSScriptingLibPath(); |
||
272 | |||
258 | try |
273 | try |
259 | { |
274 | { |
260 | dynamic sys = Python.GetSysModule(engine); |
275 | dynamic sys = Python.GetSysModule(engine); |
261 | sys.argv = args; |
276 | sys.argv = args; |
262 | 277 | sys.path.Add(strScriptingPath); |
|
278 | |||
263 | var source = engine.CreateScriptSourceFromFile(scriptfile); |
279 | var source = engine.CreateScriptSourceFromFile(scriptfile); |
264 | dynamic result = source.Execute(); |
280 | dynamic result = source.Execute(); |
265 | 281 | ||
266 | //Console.WriteLine("Script finished"); |
282 | //Console.WriteLine("Script finished"); |
267 | } |
283 | } |
284 | catch (IronPython.Runtime.Exceptions.SystemExitException ex) |
||
285 | { |
||
286 | Console.WriteLine(); |
||
287 | |||
288 | Console.WriteLine("[INFO] command " + command + ".py exited: "); |
||
289 | |||
290 | ExceptionOperations eo = engine.GetService<ExceptionOperations>(); |
||
291 | string error = "[INFO] " + eo.FormatException(ex); |
||
292 | Console.WriteLine(error); |
||
293 | } |
||
268 | catch (Exception ex) |
294 | catch (Exception ex) |
269 | { |
295 | { |
270 | Console.WriteLine(); |
296 | Console.WriteLine(); |
271 | 297 | ||
272 | Console.WriteLine("[Exception] command " + command + ".py caused an exception: " ); |
298 | Console.WriteLine("[Exception] command " + command + ".py caused an exception: " ); |