For a Udp connection, while loop does not work. Code gives no error.

I am extratcing data from a file and receiving it on matlab via udp connection. I have written doen a code which works perfectly fine when I run it step by step. BUt when I run it as a whole while loop doesn't seem to work. Here is the code:
port=50021;
smartmeter = smartHES(port);
smartmeter.InitiateSocket();
dataAmount=0;
dataHistory=[];
pause(0.1)
byteav=smartmeter.smart.BytesAvailable;
while byteav
[smt]=smartmeter.readDATA();
dataHistory=[dataHistory smt];
fprintf('data is being read on port %d amount now %d\n',port,dataAmount);
end
What should I do to get this code running by just pressing run button. Further I will use this code for several ports using spmd.

5 件のコメント

Walter Roberson
Walter Roberson 2021 年 6 月 15 日
編集済み: Walter Roberson 2021 年 6 月 15 日
you do not update, byteav in your loop, or dataAmount
Asma Farooq
Asma Farooq 2021 年 6 月 15 日
Ports=[50021,50661];
n=2;
parpool('local',2,'AttachedFiles',{'smartHES.m'})
port = Composite(n);
for i=1:2
port{i}=Ports(i);
end
dataAmount=0;
dataHistory=[];
spmd
smartmeter = smartHES(port);
smartmeter.InitiateSocket();
byteav=smartmeter.smart.BytesAvailable;
while byteav
[smt]=smartmeter.readDATA();
dataHistory=[dataHistory smt];
fprintf('data is being read on port %d amount now %d\n',port,dataAmount);
dataAmount= dataAmount+1;
if byteav==0
disp('no data available to be read')
end
completedata = dataHistory;
end
smartmeter.NetworkDispose();
end
Asma Farooq
Asma Farooq 2021 年 6 月 15 日
I tried the above code but still it does not work. Even if I don't use spmd, and run only for 1 loop, I have to run it section by section then it starts running and I have to stop it manually.
Walter Roberson
Walter Roberson 2021 年 6 月 15 日
you still do not update byteav
Asma Farooq
Asma Farooq 2021 年 6 月 17 日
I got it now. Thank you.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeParallel Computing についてさらに検索

質問済み:

2021 年 6 月 14 日

コメント済み:

2021 年 6 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by