Matlab和JDDE [英] Matlab and JDDE
问题描述
更新:在MathWorks的帮助下解决了这个问题。我已经发布了以下答案。
Update: The problem was solved with the help of MathWorks. I've published the answer below.
我需要从Matlab控制一个程序(Zemax)。不幸的是,Zemax仅支持DDE进行此类控制,Matlab不再支持这种控制。它工作正常,但在一些(可能的63)DDE调用之后停止在64位平台上工作。
I need to control a program (Zemax) from Matlab. Unfortunately, Zemax only supports DDE for such control, which Matlab does not support any more. It works, but stops working on 64 bit platform after a few (presumable 63) DDE calls.
我想知道是否有工作解决方案。我可以用正确的DDE支持编程DLL,然后通过这个DLL在Matlab中使用DDE。这对我来说是一项重大努力。更合适的解决方案是使用Java DDE方法。在其他帖子之后,我发现了JDDE库。但是我无法使它工作:即使我在DLL和JAR文件的目录中,执行
I wonder if there are working solutions. I could probably program a DLL with correct DDE support and then use DDE in Matlab via this DLL. This is a major effort for me. A more suitable solution would be to use Java DDE methods. Following another post here, I've discovered the JDDE library. However I cannot make it work: Even if I am in the directory with the DLL and JAR files, executing
import pretty-tools.JDDE-2.0.3.*
工作正常但是打电话
a = com.pretty_tools.dde.client.DDEClientConversation()
之后(如此处)结果
Undefined variable "com" or class "com.pretty_tools.dde.client.DDEClientConversation".
我的电脑写作权限非常有限,所以我添加了 javaclasspath.txt
带有jar / dll位置的文件到 prefdir
指示的目录。该文件如下所示:
I have very limited writing privileges on my PC, so I have added the javaclasspath.txt
file with the jar/dll location to the directory indicated by prefdir
. The file looks like this:
C:\Users\xxxxxxxx\Documents\matlab toolbox\jdde\pretty-tools-JDDE-2.0.3.jar
调用 javaclasspath
显示一个长列表,最后一行是:
Calling javaclasspath
shows a long listing with the last lines being:
...
C:\Program Files\MATLAB\R2012b\java\jarext\webservices\ws_client_core\mw-service-client-core.jar
C:\Users\kkarapet\Documents\matlab toolbox\jdde\pretty-tools-JDDE-2.0.3.jar
DYNAMIC JAVA PATH
<empty>
因此路径似乎设置正确。我做错了什么?
So path seems to be set correctly. What am I doing wrong?
推荐答案
在MathWorks支持的帮助下,我找到了答案。以下是如何使 JDDE 与Matlab 2012b协同工作,没有管理员权限:
With the help of MathWorks support, I've found the answer. Here is how to make JDDE work with Matlab 2012b, without admin privileges:
- 将JDDE文件(DLL和JAR)下载并解压缩到某个文件夹中。假设它是
$ path-to-jdde $ \
。 - 在Matlab中,输入
prefdir
。打开生成的目录并在那里创建两个文件,javaclasspath.txt
和javalibrarypath.txt
。 - 在javaclasspath.txt中,添加
$ path-to-jdde $ \ _pretty-tools-JDDE-2.0.3.jar
。 - 在javalibrarypath.txt中,添加
$ path-to-jdde $ \
。 - 重新启动Matlab。
- Download and unpack JDDE files (DLLs and JAR) into some folder. Let's say it's
$path-to-jdde$\
. - In Matlab, type
prefdir
. Open the resulting directory and create two files there,javaclasspath.txt
andjavalibrarypath.txt
. - In javaclasspath.txt, add
$path-to-jdde$\pretty-tools-JDDE-2.0.3.jar
. - In javalibrarypath.txt, add
$path-to-jdde$\
. - Restart Matlab.
现在调用 ddeConv = com.pretty_tools.dde.client.DDEClientConversation;
和按照 JavaDoc 中的说明开始使用创建的对象。例如。连接到Zemax,运行Zemax然后在调用 ddeConv.connect('Zemax','abc')
。
Now call ddeConv = com.pretty_tools.dde.client.DDEClientConversation;
and start using the created object as described in JavaDoc. E.g. to connect to Zemax, run Zemax and then in call ddeConv.connect('Zemax', 'abc')
.
上面的步骤2只能从Matlab版本R2012b开始。对于旧版本,如果您对Matlab安装目录具有写权限,则应该能够通过编辑$ MATLABROOT $ \toolbox \ local中的文件librarypath.txt和classpath.txt来替换步骤2。我无法验证,所以如果您确认,请在下面的评论中告诉我。
Step 2 above can only be done starting Matlab version R2012b. With an older version, if you have the write rights on the Matlab installation directory, you should be able to replace step 2 by editing the files librarypath.txt and classpath.txt in $MATLABROOT$\toolbox\local. I could not verify it so if you confirm it please let me know in the comment below.
这篇关于Matlab和JDDE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!