![]() |
RobWorkProject
25.2.11-
|
Implementation of the Wolfram Symbolic Transfer Protocol (WSTP) to allow communication with Mathematica. More...
#include <Mathematica.hpp>
Classes | |
class | Array |
An Array primitive. More... | |
class | AutoExpression |
Convenience class for automatic Expression deduction. More... | |
class | Expression |
A representation of a Mathematica expression. More... | |
class | Function |
A user definable function expression. More... | |
class | FunctionBase |
A base interface for function expressions. More... | |
class | Integer |
An integer primitive. More... | |
struct | Link |
Representation of a link. More... | |
class | Packet |
A Packet expression. More... | |
class | Real |
A real primitive. More... | |
class | String |
A string primitive. More... | |
class | Symbol |
A symbol primitive. More... | |
Public Types | |
enum | LinkProtocol { SharedMemory , TCP_IP } |
Available link protocols. More... | |
enum | PacketType { EnterExpression , EnterText , Evaluate , InputName , Message , OutputName , ReturnExpression , Return , ReturnText , Text } |
Packet types. More... | |
typedef rw::core::Ptr< Mathematica > | Ptr |
Smart pointer. | |
Public Member Functions | |
Mathematica () | |
Constructor. | |
virtual | ~Mathematica () |
Destructor. | |
bool | initialize () |
Initialize the WSTP framework. More... | |
Link::Ptr | createLink (const std::string &name="", LinkProtocol protocol=SharedMemory) |
Create a new link. More... | |
Link::Ptr | connectToLink (const std::string &name) |
Connect to an existing link. More... | |
Link::Ptr | launchKernel () |
Launch a kernel. More... | |
bool | closeLink (Link::Ptr link) |
Close a link. More... | |
void | finalize () |
Close all open links, and deinitialize the WSTP framework. | |
Implementation of the Wolfram Symbolic Transfer Protocol (WSTP) to allow communication with Mathematica.
Example of basic usage:
Construction of a Mathematica environment, m, makes it possible to create WSTP links (Mathematica::Link). Please note that the Mathematica object automatically closes all links at destruction. WSTP links can be used for different types of interprocess communication with Wolfram Symbolic expressions. In this example we launch and connect to a kernel.
The first expression (the In[1]:= prompt) is received from the kernel with the stream operator *l >> result. We simply ignore this value, and send the first command to be evaluated with the stream operator. The result is then retrieved and printed:
ReturnPacket[ List[ List[ Rule[x, 15], Rule[y, 12]], List[ Rule[x, 41], Rule[y, 10]], List[ Rule[x, 57], Rule[y, 6]]]]
Streaming of a string to the link will implicitly create a ToExpression expression and wrap it in an EvaluatePacket. The kernel will evaluate the expression in the packet and send back a ReturnPacket with the result (as an expression). Many different types of packets can be sent and received on the link (see Mathematica::PacketType). It is up to the user to deal with the different packet types, and to parse the results received.
enum LinkProtocol |
enum PacketType |
Packet types.
Enumerator | |
---|---|
EnterExpression | |
EnterText | |
Evaluate | |
InputName | |
Message | |
OutputName | |
ReturnExpression | |
Return | |
ReturnText | |
Text |
bool closeLink | ( | Link::Ptr | link | ) |
Close a link.
link | [in] the link to close. |
Link::Ptr connectToLink | ( | const std::string & | name | ) |
Connect to an existing link.
name | [in] the name of the link to connect to. |
Link::Ptr createLink | ( | const std::string & | name = "" , |
LinkProtocol | protocol = SharedMemory |
||
) |
Create a new link.
name | [in] (optional) a named link allows other programs to connect to it. |
protocol | [in] (optional) the type of LinkProtocol to use - default is shared memory. |
bool initialize | ( | ) |
Initialize the WSTP framework.
Link::Ptr launchKernel | ( | ) |
Launch a kernel.