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

 Accepted Answer

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 Comments

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.
yes i have Instrument Control Toolbox and Parallel Computing Toolbox both
dou you know in matlab how can i give stop and start functionality to infinite loop?
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?
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.
data-reading callback? i have no idea about this can you send me any link which help me
finally i have achieved.. thanks for your kind help. my project is complete..
thank you very very much

Sign in to comment.

More Answers (1)

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

3 Comments

spmd would be more appropriate than parfor for such a situation.
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!