ScanImage 2019 : ScanImage Remote Control (TCP/IP)

Icon

This feature is only available in ScanImage premium.

Matlab Remote Server

ScanImage includes a TCP/IP server and client that can be used to execute Matlab commands on a remote computer.

To launch the server, execute the following command:

Server startup
>> IPWhitelist = {'127.0.0.1/32'};
>> serverPort = 5555;
>> hServer = most.network.matlabRemote.Server(5555,IPWhitelist);

hServer = 
  Server with properties:
    port: 5555
    IPWhitelist: {'127.0.0.1/32'}

To shut the server down execute

Server shutdown
>> hServer.delete();
Icon

Launching the TCP/IP server allows full control over the computer, including the execution of code. The data between client and server is not encrypted, and no authentication is required. The IP white list allows to reject unknown clients, but only provides a minimal level of security. Only use the server on a private and trusted network.

 

 

Matlab Remote Client

On the remote computer, execute the following commands in the Matlab command window:

>> serverAddress = '127.0.0.1';
>> serverPort = 5555;
>> hClient = most.network.matlabRemote.Client(serverAddress,serverPort);
   Connected to server running Matlab 9.6.0.1072779 (R2019a)

>> hClient.feval('disp','Hello World!'); % Execute a function on the server
>> myData = rand(3) % create a local variable with some data 

myData =
   0.1023 0.7350 0.4641
   0.9614 0.9924 0.6104
   0.1540 0.4698 0.9597

>> myData_server = hClient.upload(myData) % upload data to the server

myData_server =
   ServerVariable on server 127.0.0.1:5555
   Class: double
   Size: [3 3]

>> myData_server = myData_server + 100; % manipulate the data on the server
>> myData = myData_server.download() % retrieve the data from the server

myData =
   100.1023 100.7350 100.4641
   100.9614 100.9924 100.6104
   100.1540 100.4698 100.9597

>> hClient.delete();
Icon

All calls to the server are synchronous. This means the client Matlab console is blocked until the server finishes executing the command.

 

 

ScanImage Control

The TCP/IP server exposes all ScanImage functionality via ScanImage's API calls. To launch ScanImage on a remote computer execute the following command:

(The TCP/IP server needs to be started on the remote computer first)

serverAddress = '127.0.0.1';
serverPort = 5555;
>> hClient = most.network.matlabRemote.Client(serverAddress,serverPort);
   Connected to server running Matlab 9.6.0.1072779 (R2019a)

>> hSI_server = hClient.feval('scanimage','C:\Machine_Data_File.m'); % start ScanImage, provide MDF to suppress startup dialog
>> hSI_server.startFocus();
>> lastFrame_server = hSI_server.hDisplay.lastFrame
   lastFrame_server =
      ServerVariable on server 127.0.0.1:5555
      Class: cell
      Size: [1 1]

>> lastFrame = lastFrame_server.download()
   ans =
      1×1 cell array
      {512×512 double}


>> hSI_server.abort();
>> hSI_server.exit();
>> hClient.delete();

 

To retrieve the hSI handle from an already running ScanImage instance, execute the following command:

(The TCP/IP server needs to be started on the remote computer first)

serverAddress = '127.0.0.1';
serverPort = 5555;
>> hClient = most.network.matlabRemote.Client(serverAddress,serverPort);
   Connected to server running Matlab 9.6.0.1072779 (R2019a)

>> hSI_server = hClient.feval('evalin','base','hSI'); % retrieve hSI handle from server base workspace