run two program(infinite loop) prallel in matlab

Hello,
how can i run two infinite loop parallel in matlab.
data listening infinite loop
while 1
while ~(iStream.available)
end
readS(iStream);
end
command sending infinite loop
while 1
userInput = input('Server: ', 's');
oStream.sendS(userInput);
end
how can i run this both infinite loop program parallel in matlab plz help me out

 Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de En. de 2014

0 votos

You should probably use a single program, with the input from the robot handled by firing a timer() object, or by using a callback, such as a BytesAvailableFcn.

13 comentarios

Lalji goti
Lalji goti el 16 de En. de 2014
i am sending image file.. find my attachment..i hope which make clear what i want
in my case want to develop chating application between robot controller and and matalab my matlab is server and robot controller is client.. if i send message (0) then robot will stop to send data to matlab and if i send message (1) then it will star to send tool position which i can collect in matlab using my first infinite loop
Do you have the Instrument Control Toolbox ?
For my own future reference:
(These seem to be suggesting that multiple threads would be used if Java is used for the implementation, but that the thread doing I/O would not need to spin on socket availability such as was written in the source files in test.zip )
I can confirm that a timer() object will continue to fire while input() is being waited for.
Lalji goti
Lalji goti el 16 de En. de 2014
Editada: Lalji goti el 16 de En. de 2014
yes i have Instrument Control Toolbox and Parallel Computing Toolbox both
Lalji goti
Lalji goti el 16 de En. de 2014
dou you know in matlab how can i give stop and start functionality to infinite loop?
Lalji goti
Lalji goti el 17 de En. de 2014
Editada: Lalji goti el 17 de En. de 2014
here i am sending other program, which i can not terminate after running this program without help of task manager
how can i terminate infinite loop in matlab?
Lalji goti
Lalji goti el 17 de En. de 2014
in my case robot is sending me data TCP(tool center position) continuously which i am collecting by using my first infinite loop but by using second loop i want to stop the robot and sometime i want to send TCP also..
You cannot stop an infinite loop in MATLAB, not without using control-C to stop the MATLAB program.
Thus, you should avoid writing an infinite loop. Instead write a "while" loop that depends upon something that can change, or write an "if" statement that has a "break" as the body when it detects the change.
You do not need an infinite loop for reading the data: by using a TCP (Transmission Control Protocol) callback when data is detected, you can have MATLAB react to the incoming data without needing to loop to check to see if data is available. You can then have your loop that gets input from the user. When the user signals that the robot should stop sending data, you do not need to do anything special with the data-reading callback: if there is no data coming in, it will simply not be called.
Lalji goti
Lalji goti el 17 de En. de 2014
data-reading callback? i have no idea about this can you send me any link which help me
As I posted above:
and look down to "Defining an Asynchronous Read Callback"
Lalji goti
Lalji goti el 21 de En. de 2014
finally i have achieved.. thanks for your kind help. my project is complete..
thank you very very much

Iniciar sesión para comentar.

Más respuestas (1)

Haiko
Haiko el 16 de En. de 2014

0 votos

Using parfor might be a solution. Your code has to be rewriten a bit. See as well the help function on parfor.

3 comentarios

spmd would be more appropriate than parfor for such a situation.
bsissa soufien
bsissa soufien el 31 de Mayo de 2015
hi I can modify a spin protocol source code in wireless sensor network domain to optimize energy and diminier connsommation and here is the source code of spin protocol:
The source did not end up attached. But this would not be the right Question to attach it to as the Question does not pertain to WSN.

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 16 de En. de 2014

Comentada:

el 31 de Mayo de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by