Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,26 @@ xx, yy = mxcall(:meshgrid, 2, x, y)

``mxcall`` puts the input arguments to the MATLAB workspace (using mangled names), evaluates the function call in MATLAB, and retrievs the variable from the MATLAB session. This function is mainly provided for convenience. However, you should keep in mind that it may incur considerable overhead due to the communication between MATLAB and Julia domain.

#### Viewing the MATLAB Session
#### Viewing the MATLAB Session (Windows only)

To open an interactive window for the MATLAB session, use the command `show_msession()`. To hide the window, use `hide_msession()`. Note that closing this window will result in an error, so it is advised that one uses the `hide_msession()` command instead.
To open an interactive window for the MATLAB session, use the command `show_msession()` and to hide the window, use `hide_msession()`. *Warning: manually closing this window will result in an error or result in a segfault; it is advised that you only use the `hide_msession()` command to hide the interactive window.*

Note that this feature only works on Windows.

```julia
# default
show_msession() # open the default MATLAB session interactive window
get_msession_visiblity() # get the session's visibility state
hide_msession() # hide the default MATLAB session interactive window

# similarily
s = MSession()
show_msession(s)
get_msession_visiblity(a)
hide_msession(s)
```


#### Advanced use of MATLAB Engines

This package provides a series of functions for users to control the communication with MATLAB sessions.
Expand Down
7 changes: 5 additions & 2 deletions src/MATLAB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export MSession, MatFile,
eval_string, get_mvariable, get_variable, put_variable, put_variables,
variable_names, read_matfile, write_matfile,
mxcall,
@mput, @mget, @matlab, @mat_str,
show_msession, hide_msession
@mput, @mget, @matlab, @mat_str

if is_windows()
export show_msession, hide_msession, get_msession_visiblity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these only exist on Windows?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end

# exceptions
type MEngineError <: Exception
Expand Down Expand Up @@ -65,6 +67,7 @@ function __init__()
eng_open[] = engfunc(:engOpen)
eng_close[] = engfunc(:engClose)
eng_set_visible[] = engfunc(:engSetVisible)
eng_get_visible[] = engfunc(:engGetVisible)
eng_output_buffer[] = engfunc(:engOutputBuffer)
eng_eval_string[] = engfunc(:engEvalString)
eng_put_variable[] = engfunc(:engPutVariable)
Expand Down
27 changes: 17 additions & 10 deletions src/engine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,25 @@ function close_default_msession()
return nothing
end

function show_msession(m::MSession = get_default_msession())
ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 1)
ret != 0 && throw(MEngineError("failed to show MATLAB engine session (err = $ret)"))
return nothing
end
if is_windows()
function show_msession(m::MSession = get_default_msession())
ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 1)
ret != 0 && throw(MEngineError("failed to show MATLAB engine session (err = $ret)"))
return nothing
end

function hide_msession(m::MSession = get_default_msession())
ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 0)
ret != 0 && throw(MEngineError("failed to hide MATLAB engine session (err = $ret)"))
return nothing
end
function hide_msession(m::MSession = get_default_msession())
ret = ccall(eng_set_visible[], Cint, (Ptr{Void}, Cint), m, 0)
ret != 0 && throw(MEngineError("failed to hide MATLAB engine session (err = $ret)"))
return nothing
end

function get_msession_visiblity(m::MSession = get_default_msession())
vis = Ref{Cint}(true)
ccall(eng_get_visible[], Int, (Ptr{Void}, Ptr{Cint}), m, vis)
return vis[] == 1 ? true : false
end
end

###########################################################
#
Expand Down
3 changes: 2 additions & 1 deletion src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const libmat = Ref{Ptr{Void}}()
const eng_open = Ref{Ptr{Void}}()
const eng_close = Ref{Ptr{Void}}()
const eng_set_visible = Ref{Ptr{Void}}()
const eng_get_visible = Ref{Ptr{Void}}()
const eng_output_buffer = Ref{Ptr{Void}}()
const eng_eval_string = Ref{Ptr{Void}}()
const eng_put_variable = Ref{Ptr{Void}}()
Expand Down Expand Up @@ -84,7 +85,7 @@ const mx_set_field = Ref{Ptr{Void}}()
const mx_get_field_bynum = Ref{Ptr{Void}}()
const mx_get_fieldname = Ref{Ptr{Void}}()

const mx_get_string = Ref{Ptr{Void}}(0)
const mx_get_string = Ref{Ptr{Void}}()

# load I/O mat functions

Expand Down