When using StartDebugServer it is possible to enable remote debugging of your application like shown here.
HaEngine = new HDevEngine();
HaEngine.StartDebugServer();
When using an exported library it gives you a wrapper .cs file that does not use a global HDevEngine like in the examples, but only this reference to the HDevEngine:
private static void AddResourcePathToProcedurePath()
{
lock(_procedure_path_lock)
{
if(!_procedure_path_initialized)
{
new HDevEngine().AddProcedurePath(ResourcePath);
_procedure_path_initialized = true;
}
}
}
I know there is a HDevEngine initialized here but have no idea how to add StartDebugServer.
How to remotely debug the generated wrapper program generated by Halcon?
I haven't figured out how to do it with an exported library, but I did get it to work with exported procedure files (.hdvp).
Put procedure files in bin folder.
using HalconDotNet;
HDevEngine eng = new HDevEngine();
eng.SetProcedurePath("./");
eng.StartDebugServer();
string procedureName = "testProcedure_long";
var procedure = new HDevProcedure(procedureName);
var procedureCall = new HDevProcedureCall(procedure);
procedureCall.Execute();
Then:
# Halcon IDE -> Execute -> Attach to process -> Default values -> Go
How to run .py files and call function by using python.Net library.
i have tried below code but it is not running.
using (Py.GIL()){
var fromFile = PythonEngine.Compile(null, #"C:\PycharmProjects\pythonenet\main.py", RunFlagType.File);
fromFile.InvokeMethod("replace");//
}
main.py file:
import re
def replace():
print(re.sub(r"\s","*","Python is a programming langauge"))
When i try to run from string it is working.
using (Py.GIL()){
string co = #"def someMethod():
print('This is from static script')";
var fromString = PythonEngine.ModuleFromString("someName", co);
fromString.InvokeMethod("someMethod");
}
Finally i ended up with the following solution.
using (Py.GIL()){
dynamic os = Py.Import("os");
dynamic sys = Py.Import("sys");
sys.path.append(os.path.dirname(os.path.expanduser(filePath)));
var fromFile = Py.Import(Path.GetFileNameWithoutExtension(filePath));
fromFile.InvokeMethod("replace");
}
I wrote this code in python to draw dendrogram:
import numpy as np
from scipy.cluster.hierarchy import linkage,dendrogram
import matplotlib.pyplot as plt
x = np.array([[2,3],[5,5],[4.3,6],[5.5,4.9],[4.4,5.8],[10,10],[40,40],
[2.2,5]])
plt.scatter(x[:,0],x[:,1],s=30)
lin=linkage(x,"single")
den=dendrogram(lin,truncate_mode="none")
plt.show()
It works correctly and generates the dendrogram. After that, I want to convert this code to a method in Python script and execute it over a C# project so I can use IronPython.
But there is an error in the script at this part linkage(x,"single"), truncate_mode = "none" and this line plt.show(), as shown in the following c# code:
var pySrc =
#"def Generatedendrogram():
import numpy as np
from scipy.cluster.hierarchy import linkage,dendrogram
import matplotlib.pyplot as plt
x = np.array([[2,3],[5,5],[4.3,6],[5.5,4.9],[4.4,5.8],[10,10],[40,40]])
plt.scatter(x[:,0],x[:,1],s=30)
//There is an error in the next 2 lines
dendrogram(linkage(x,"single"), truncate_mode = "none")
plt.show()";
// host python and execute script
var engine = IronPython.Hosting.Python.CreateEngine();
var scope = engine.CreateScope();
engine.Execute(pySrc, scope);
// get function and dynamically invoke
var dendro = scope.GetVariable("Generatedendrogram");
Generatedendrogram();
How can I write this script correctly?
I am trying to encode and decode json using lua using c#.I am using NLUA for executing lua script.
I am using Json.Lua file for json manupulation(encode and decode method) but i am not getting how to make it work with nlua in c#.
code :
static void Main(string[] args)
{
Lua state = new Lua();
var jsonConcate = #"[{ ""firstName"":""John"" , ""lastName"":""Doe"", ""email"":""NHP#123.COM"" },{ ""firstName"":""Anna"", ""lastName"":""Smith"", ""email"":""ASD#123.COM"" },{ ""firstName"":""Peter"" , ""lastName"":""Jones"", ""email"":""ZXC#123.COM""}]";
state.DoString(#"
function ScriptFunc (input)
local json = require('json')
local JSON_string = input
return JSON_string end"
);
var scriptFunc = state["ScriptFunc"] as LuaFunction;
var res = scriptFunc.Call(jsonConcate);//Error here
}
This line var res = scriptFunc.Call(jsonConcate) is throwing error :
When i remove this line local json = require('json') then it is working fine.
I have install lua using this installer also :https://github.com/rjpcomputing/luaforwindows
Project : https://www.dropbox.com/s/hbf04d8kqpenzm0/LuaTest.zip?dl=0
Can anybody please help me this?
I am C# developer and I have to use an IronPython library in the .NET framework. I tested every class in Python and it's working but I am not sure how to call the library in a C# class.
When I try to call the library, I am getting a 'LightException' object has no attribute client error.
I have added lib, -x:Full frame and also all modules in the lib folder.
Here is the C# code I am using to call the Python library:
Console.WriteLine("Press enter to execute the python script!");
Console.ReadLine();
var options = new Dictionary<string, object>();
options["Frames"] = true;
options["FullFrames"] = true;
//var py = Python.CreateEngine(options);
//py.SetSearchPaths(paths);
ScriptEngine engine = Python.CreateEngine(options);
ICollection<string> paths = engine.GetSearchPaths();
string dir = #"C:\Python27\Lib\";
paths.Add(dir);
string dir2 = #"C:\Python27\Lib\site-packages\";
paths.Add(dir2);
engine.SetSearchPaths(paths);
ScriptSource source = engine.CreateScriptSourceFromFile(#"C:\Users\nikunjmange\Source\Workspaces\Visage Payroll\VisagePayrollSystem\VisagePayrollSystem\synapsepayLib\synapse_pay-python-master\synapse_pay\resources\user.py");
ScriptScope scope = engine.CreateScope();
source.Execute(scope);
dynamic Calculator = scope.GetVariable("User");
dynamic calc = Calculator();
string inputCreate = "nik12#gmail.com";
string result = calc.create(inputCreate);
The error is misleading because of a bug in IronPython 2.7.5. It should be an ImportError.
Don't add the normal CPython stdlib; it's not compatible with IronPython. Use IronPython's stdlib instead.
If you have an import of import a.b as c that's probably the culprit; either a or b does not exist but IronPython mucks up the error reporting.