Cos'è ElectroYou | Login Iscriviti

ElectroYou - la comunità dei professionisti del mondo elettrico

utilizzare matlab in remoto

Strumenti informatici per la matematica applicata, le simulazioni, il disegno: Mathcad, Matlab, Scilab, Microcap, PSpice, AutoCad ...

Moderatori: Foto Utenteg.schgor, Foto Utentedimaios

0
voti

[1] utilizzare matlab in remoto

Messaggioda Foto Utentejmonty » 3 ago 2012, 18:18

salve,
Ho un motore in cc, controllato tramite scheda dspace che si interfaccia con matlab simulink.Posso controllare il motore in cc tramite linee di comando nel workspace di matlab.Ora il mio quesito è il seguente: come posso inviare line di comando da un PC ad un altro e viceversa tramite matlab???
Avatar utente
Foto Utentejmonty
16 1 2 4
Frequentatore
Frequentatore
 
Messaggi: 232
Iscritto il: 9 ago 2011, 18:58

1
voti

[2] Re: utilizzare matlab in remoto

Messaggioda Foto Utentedimaios » 4 ago 2012, 17:35

Un esempio è quello di utilizzare il Parallel Toolbox in modo improprio.
Per i dettagli leggi questo.
Ingegneria : alternativa intelligente alla droga.
Avatar utente
Foto Utentedimaios
30,2k 7 10 12
G.Master EY
G.Master EY
 
Messaggi: 3381
Iscritto il: 24 ago 2010, 14:12
Località: Behind the scenes

0
voti

[3] Re: utilizzare matlab in remoto

Messaggioda Foto Utentejmonty » 4 ago 2012, 17:39

grazie
Avatar utente
Foto Utentejmonty
16 1 2 4
Frequentatore
Frequentatore
 
Messaggi: 232
Iscritto il: 9 ago 2011, 18:58

0
voti

[4] Re: utilizzare matlab in remoto

Messaggioda Foto Utentejmonty » 9 ago 2012, 11:23

Ho trovato su internet due funzioni matlab una per il server, e l'altra per il client
% SERVER Write a message over the specified port
%
% Usage - server(message, output_port, number_of_retries)
function server(message, output_port, number_of_retries)

import java.net.ServerSocket
import java.io.*

if (nargin < 3)
number_of_retries = 20; % set to -1 for infinite
end
retry = 0;

server_socket = [];
output_socket = [];

while true

retry = retry + 1;

try
if ((number_of_retries > 0) && (retry > number_of_retries))
fprintf(1, 'Too many retries\n');
break;
end

fprintf(1, ['Try %d waiting for client to connect to this ' ...
'host on port : %d\n'], retry, output_port);

% wait for 1 second for client to connect server socket
server_socket = ServerSocket(output_port);
server_socket.setSoTimeout(1000);

output_socket = server_socket.accept;

fprintf(1, 'Client connected\n');

output_stream = output_socket.getOutputStream;
d_output_stream = DataOutputStream(output_stream);

% output the data over the DataOutputStream
% Convert to stream of bytes
fprintf(1, 'Writing %d bytes\n', length(message))
d_output_stream.writeBytes(char(message));
d_output_stream.flush;

% clean up
server_socket.close;
output_socket.close;
break;

catch
if ~isempty(server_socket)
server_socket.close
end

if ~isempty(output_socket)
output_socket.close
end

% pause before retrying
pause(1);
end
end
end

% CLIENT connect to a server and read a message
%
% Usage - message = client(host, port, number_of_retries)
function message = client(host, port, number_of_retries)

import java.net.Socket
import java.io.*

if (nargin < 3)
number_of_retries = 20; % set to -1 for infinite
end

retry = 0;
input_socket = [];
message = [];

while true

retry = retry + 1;
if ((number_of_retries > 0) && (retry > number_of_retries))
fprintf(1, 'Too many retries\n');
break;
end

try
fprintf(1, 'Retry %d connecting to %s:%d\n', ...
retry, host, port);

% throws if unable to connect
input_socket = Socket(host, port);

% get a buffered data input stream from the socket
input_stream = input_socket.getInputStream;
d_input_stream = DataInputStream(input_stream);

fprintf(1, 'Connected to server\n');

% read data from the socket - wait a short time first
pause(0.5);
bytes_available = input_stream.available;
fprintf(1, 'Reading %d bytes\n', bytes_available);

message = zeros(1, bytes_available, 'uint8');
for i = 1:bytes_available
message(i) = d_input_stream.readByte;
end

message = char(message);

% cleanup
input_socket.close;
break;

catch
if ~isempty(input_socket)
input_socket.close;
end

% pause before retrying
pause(1);
end
end
end

Vorrei chiedervi gentilmente, se posso testare contemporaneamente queste due funzioni, per vedere se funzionano.Leggendo la guida matlab dopo aver digitato tcpip ho trovato echotcpip che mi dice come testare un una richiesta remota virtuale.
Avatar utente
Foto Utentejmonty
16 1 2 4
Frequentatore
Frequentatore
 
Messaggi: 232
Iscritto il: 9 ago 2011, 18:58


Torna a Programmi applicativi: simulatori, CAD ed altro

Chi c’è in linea

Visitano il forum: Nessuno e 2 ospiti