Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have been using some basic MathLink programming in my work and wanted to create some more sophisticated MathLink programs. I came across the book "MathLink: Network Programming with Mathematica", which was written around the era of Mathematica version 4, which has some neat interactive gui examples using mathlink, based around a piece of mathlink code created by the author of that book called Serializer.exe. Its essentially a mathlink template program designed to sit in between the kernel and the front end as they communicate so you can modify how that communication works.

I can almost run it on my machine, using Mathematica 8, up to one little sticking point that maybe someone can help me with. To give you an idea of whats going on:

The starting point is a mathlink template program (compiled using c, as such things are) called Serializer.exe. This program is added as a custom evaluator in mathematica via the "Kernel Configuration Options", and the code is run with that kernel (i.e. it runs through serializer.exe before being sent to the actual kernel.)

Then this program spawns a raw mathlink program which is added to the list of evaluators (Options[$FrontEnd,EvaluatorNames]) and tries to set up a mathlink connection between it and the front end.

After going through the code step by step, the place where its stuck is a pair of lines of code that look like:

FrontEndExecute[EvaluatorStart[nameofrawMathLinkEvaluator]];
MessageLinkActivate[];

Now MessageLinkActivate[] is a custom function defined in the c code, but it seems that it should be similar to LinkActivate[], the usual math link activation function. Users of mathlink will know that once LinkActivate is called on a kernel, it blocks evaluation until the other end of the program activates as well. The program hangs if the activate is never answered. However, EvaluatorStart is not defined anywhere, and it throws an error message that is does not recognize the packet "EvaluatorStart", and then waits forever for a return linkactivation that never happens. I'll give exact instructions for recreating the error in the comments below, but I should say that the exact same error comes up if EvaluatorStart is changed to a random string of letters- so I'm sure the program really has no definition for EvaluatorStart.

I am trying to deduce the right line of code to put here - after some googling, it seems that there is a FrontEnd Token called EvaluatorStart, which would be called something like this:

FrontEndExecute[FrontEndToken[nb,"EvaluatorStart",nameofrawMathLinkEvaluator];
MessageLinkActivate[];

where nb is an argument that must refer to some notebook, which I'm not sure what to put (I tried EvaluationNotebook[] with no luck).

Any help would be appreciated on the following questions:

  • In Mathematica 4, what did FrontEndExecute[EvaluatorStart[name]] do?
  • How could I recreate that functionality in Mathematica 8 or 9?
  • Does anyone use serializer.exe with a modern version of mathematica?
  • Has anyone else created advanced interactive mathlink programs, like the interactive graphics system featured in "MathLink: Network Programming with Mathematica", with publically available code?

Edit: To recreate this would require adding serializer.exe to your mathematica $LaunchDirectory, and then running some very short code in Mathematica. I can provide this file and code if anyone actually wants to help try to solve this.

share|improve this question
    
Welcome our Mathematica site and thanks for this clearly written question. First, do you really want/need to use C/C++ or would Java do it too? The reason is, that with JLink you can do the same things but it's a log easier to set up. Please have a look at JLink/guide/CallingMathematicaFromJava in your help browswer. There are a lot of examples and especially, you find a thing called LinkSnooper which lets you monitor the communication between front end and kernel. –  halirutan Aug 26 '13 at 22:20
    
One of the advantages of Java is, that you don't have to compile your program for every system and the final jar can just be loaded from within Mathematica like you would do it with LinkConnect and friends. Additionally, Java is (due to its design) not so hard to get bug-free and easier to debug. The code for the LinkSnooper can be found in the install path of Mathematica. –  halirutan Aug 26 '13 at 22:24
    
If you really need to stick to C, then I could probably have a look at the code since I own the book, but it's very unlikely, that I manage to do this soon. –  halirutan Aug 26 '13 at 22:25
    
Thanks for the comment halirutan. I will take a look at JLink - I mostly tried MathLink because I was very interested in the interactive graphics example from that book. My own projects (which are in Mathematica code) need an interactive way to modify the geometry of physics problems (say drawing and moving circles around in a box). –  user2694879 Aug 27 '13 at 17:36
    
I like that example because: - it is asynchronous - it is object oriented - it has the master/slave hiearchy, i.e. moving a vertex of a triangle can cause all the edges to move with it. I'm sure Java would be fine for this too - my main issue is finding examples of compilable programs so I'm not working from scratch. It seems that the setup in this book allows most of the mathlink work to be done by Serializer.exe, and writing new applications is just a matter of writing new templates and coding in mathematica. Are there similar examples in J/Link? –  user2694879 Aug 27 '13 at 17:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.