我用Julia以MATLAB为中介调用C#的dll是成功的(using MATLAB; eval_string(“NET.addAssembly(fullfile(pwd, ‘drivers’, ‘visaDlls’, ‘visaLibFwk.dll’))”);),但是MATLAB要付费,所以换成以Python为中介。
Python用“pip install pythonnet”添加一个模块,即可调用C# dll,但是,在Julia环境下运行这些Python语句,却找不到动态链接库dll文件。
有没有办法解决?
或者有没有更好的、免费的方式调用C# dll?
import clr
clr.AddReference(‘Drivers/visaDlls/visaLibFwk’)
<System.Reflection.RuntimeAssembly object at 0x0000000002C7E588>
julia> using PyCall
julia> pyversion
v"3.7.3"
julia> py"“”
import clr
print(clr.FindAssembly(‘serialLib.dll’))
clr.AddReference(‘Drivers/visaDlls/visaLibFwk’)
“”"
None
ERROR: PyError ($(Expr(:escape, :(ccall(#= C:\Users\Hao.julia\packages\PyCall\ttONZ\src\pyeval.jl:39 =# @pysym(:PyEval_EvalCode), PyPtr, (PyPtr, PyPt
r, PyPtr), o, globals, locals))))) <class ‘System.IO.FileNotFoundException’>
FileNotFoundException(“Unable to find assembly ‘Drivers/visaDlls/visaLibFwk’.”)
File “C:\Users\Hao.julia\packages\PyCall\ttONZ\src\pyeval.jl”, line 3, in
const Py_eval_input = 258
Stacktrace:
[1] pyerr_check at C:\Users\Hao.julia\packages\PyCall\ttONZ\src\exception.jl:60 [inlined]
[2] pyerr_check at C:\Users\Hao.julia\packages\PyCall\ttONZ\src\exception.jl:64 [inlined]
[3] macro expansion at C:\Users\Hao.julia\packages\PyCall\ttONZ\src\exception.jl:84 [inlined]
[4] pyeval_(::String, ::PyDict{String,PyObject,true}, ::PyDict{String,PyObject,true}, ::Int64, ::String) at C:\Users\Hao.julia\packages\PyCall\ttONZ
\src\pyeval.jl:39
[5] top-level scope at C:\Users\Hao.julia\packages\PyCall\ttONZ\src\pyeval.jl:232
julia> versioninfo()
Julia Version 1.0.4
Commit 38e9fb7f80 (2019-05-16 03:38 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core™ i7-6700 CPU @ 3.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
julia> using Pkg; Pkg.status()
Status C:\Users\Hao\.julia\environments\v1.0\Project.toml
[7a1cc6ca] FFTW v0.2.4
[28b8d3ca] GR v0.40.0
[10e44e05] MATLAB v0.7.3
[e0fc9d43] PkgMirrors v1.2.0 #master (https://mirrors.zju.edu.cn/julia/PkgMirrors.jl.git)
[91a5bcdd] Plots v0.25.2
[438e738f] PyCall v1.91.2
[8bb1440f] DelimitedFiles
[8f399da3] Libdl
[10745b16] Statistics