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

 採用された回答

Walter Roberson
Walter Roberson 2014 年 1 月 16 日

0 投票

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 件のコメント

Lalji goti
Lalji goti 2014 年 1 月 16 日
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
Walter Roberson
Walter Roberson 2014 年 1 月 16 日
Do you have the Instrument Control Toolbox ?
Walter Roberson
Walter Roberson 2014 年 1 月 16 日
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 )
Walter Roberson
Walter Roberson 2014 年 1 月 16 日
I can confirm that a timer() object will continue to fire while input() is being waited for.
Lalji goti
Lalji goti 2014 年 1 月 16 日
編集済み: Lalji goti 2014 年 1 月 16 日
yes i have Instrument Control Toolbox and Parallel Computing Toolbox both
Walter Roberson
Walter Roberson 2014 年 1 月 16 日
Lalji goti
Lalji goti 2014 年 1 月 16 日
dou you know in matlab how can i give stop and start functionality to infinite loop?
Lalji goti
Lalji goti 2014 年 1 月 17 日
編集済み: Lalji goti 2014 年 1 月 17 日
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 2014 年 1 月 17 日
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..
Walter Roberson
Walter Roberson 2014 年 1 月 17 日
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 2014 年 1 月 17 日
data-reading callback? i have no idea about this can you send me any link which help me
Walter Roberson
Walter Roberson 2014 年 1 月 17 日
As I posted above:
and look down to "Defining an Asynchronous Read Callback"
Lalji goti
Lalji goti 2014 年 1 月 21 日
finally i have achieved.. thanks for your kind help. my project is complete..
thank you very very much

サインインしてコメントする。

その他の回答 (1 件)

Haiko
Haiko 2014 年 1 月 16 日

0 投票

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

3 件のコメント

Walter Roberson
Walter Roberson 2014 年 1 月 16 日
spmd would be more appropriate than parfor for such a situation.
bsissa soufien
bsissa soufien 2015 年 5 月 31 日
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:
Walter Roberson
Walter Roberson 2015 年 5 月 31 日
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.

サインインしてコメントする。

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by