From: Walter Roberson on
Hooman wrote:

> This is something that I am very much interested in. I haven't started
> to play with this idea, but it has been on my mind for a long time.
> Since my knowledge of UDP and TCP/IP is next to none, it would be very
> helpful if one you guys can post a simple example to the list or
> directly to me. I am interested in doing something like Karan
> explained; two computers, one has a GUI to change the parameters and
> such, the other one where MATLAB/Simulink resides and the simulation
> will happen.
>
> Would it be possible for the Simulink model to send data back to a GUI
> plot element? And if yes, will this happen while the simulation is
> running or one has to wait until simulation is completed?

Yes, this can happen while the simulation is going on. Reading and writing of
these kind of objects can be asynchronous (and is by default... at least
within Matlab itself; I am not familiar with how the blocks are handled in
Simulink but they are generally faster in Simulink.)
From: Karan on
Walter Roberson <roberson(a)hushmail.com> wrote in message <hvr21h$k0a$1(a)canopus.cc.umanitoba.ca>...
> Hooman wrote:
>
> > This is something that I am very much interested in. I haven't started
> > to play with this idea, but it has been on my mind for a long time.
> > Since my knowledge of UDP and TCP/IP is next to none, it would be very
> > helpful if one you guys can post a simple example to the list or
> > directly to me. I am interested in doing something like Karan
> > explained; two computers, one has a GUI to change the parameters and
> > such, the other one where MATLAB/Simulink resides and the simulation
> > will happen.
> >
> > Would it be possible for the Simulink model to send data back to a GUI
> > plot element? And if yes, will this happen while the simulation is
> > running or one has to wait until simulation is completed?
>
> Yes, this can happen while the simulation is going on. Reading and writing of
> these kind of objects can be asynchronous (and is by default... at least
> within Matlab itself; I am not familiar with how the blocks are handled in
> Simulink but they are generally faster in Simulink.)

Like Walter said, it is possible to read and write data while simulation is running. You can use To Workspace block to write data in. Update you workspace block every one second or depends on how fast u want the data to be read. Read data from workspace block. I did that and it worked fine except when I stop the simulation my Matlab kept crashing. So I am not sure if the problem was with the way I used the block or my matlab. Let me know how is goes for you.

Hey Walter, So like you said I tried sending a command but I got an error.
First I opened two udp ports (Remote and Local) on the local machine, did the same on remote machine. After that use fopen command to open each other for communication.
To make sure connection works, I did fwrite(remote,2+2) on local machine and on remote machine fread(local), worked fine I got ans 4.
After that I tried fwrite(remote,set_param('WiFiTCP_IP/Constant','value','num'))
I get this error - Invalid Simulink object name: WiFiTCP_IP/Constant.

Remote computer has a simulink file name WiFiTCP_IP and it is open. ! !
any idea what I did wrong?

Thanks
Karan
From: Walter Roberson on
Karan wrote:

> After that I tried
> fwrite(remote,set_param('WiFiTCP_IP/Constant','value','num'))
> I get this error - Invalid Simulink object name: WiFiTCP_IP/Constant.
>
> Remote computer has a simulink file name WiFiTCP_IP and it is open. ! !
> any idea what I did wrong?

That would try to set the parameter *locally* and send the return result to
the other system. You have to send the parameters to the other system and have
it make the call.

fwrite(remote, sprintf('%s\n%s\n', 'WiFiTCP_IP/Constant', 'num'));

remote side:

param_name = fgetl(remote);
param_val = fgetl(remote);
set_param(param_name, 'Value', param_val);


except that because you are using UDP and _any_ packet can go missing, you
have to guard against the possibility that the parameter packet didn't make it.
From: Karan on
Walter Roberson <roberson(a)hushmail.com> wrote in message <hvr76j$saa$1(a)canopus.cc.umanitoba.ca>...
> Karan wrote:
>
> > After that I tried
> > fwrite(remote,set_param('WiFiTCP_IP/Constant','value','num'))
> > I get this error - Invalid Simulink object name: WiFiTCP_IP/Constant.
> >
> > Remote computer has a simulink file name WiFiTCP_IP and it is open. ! !
> > any idea what I did wrong?
>
> That would try to set the parameter *locally* and send the return result to
> the other system. You have to send the parameters to the other system and have
> it make the call.
>
> fwrite(remote, sprintf('%s\n%s\n', 'WiFiTCP_IP/Constant', 'num'));
>
> remote side:
>
> param_name = fgetl(remote);
> param_val = fgetl(remote);
> set_param(param_name, 'Value', param_val);
>
>
> except that because you are using UDP and _any_ packet can go missing, you
> have to guard against the possibility that the parameter packet didn't make it.

Hey, Walter again you are amazing and thank you very much for the help ! !
I can now set variable on remote machine using my gui on local machine. One thing I changed was on remote side when you do param_name = fgetl(local), it will read both strings. Therefore when param_val is done, you get an error because there is nothing to receive.
Once that is done, I read param_name using textscan and converted into string so that I can use both words separately. And it worked. =)

Again, thank you so much ! !
From: Hooman on
On Jun 22, 7:47 pm, "Karan " <karan7...(a)gmail.com> wrote:
> Walter Roberson <rober...(a)hushmail.com> wrote in message <hvr76j$sa...(a)canopus.cc.umanitoba.ca>...
> > Karan wrote:
>
> > > After that I tried
> > > fwrite(remote,set_param('WiFiTCP_IP/Constant','value','num'))
> > > I get this error - Invalid Simulink object name: WiFiTCP_IP/Constant.
>
> > > Remote computer has a simulink file name WiFiTCP_IP and it is open. ! !
> > > any idea what I did wrong?
>
> > That would try to set the parameter *locally* and send the return result to
> > the other system. You have to send the parameters to the other system and have
> > it make the call.
>
> > fwrite(remote, sprintf('%s\n%s\n', 'WiFiTCP_IP/Constant', 'num'));
>
> > remote side:
>
> > param_name = fgetl(remote);
> > param_val = fgetl(remote);
> > set_param(param_name, 'Value', param_val);
>
> > except that because you are using UDP and _any_ packet can go missing, you
> > have to guard against the possibility that the parameter packet didn't make it.
>
> Hey, Walter again you are amazing and thank you very much for the help ! !
> I can now set variable on remote machine using my gui on local machine. One thing I changed was on remote side when you do param_name = fgetl(local), it will read both strings. Therefore when param_val is done, you get an error because there is nothing to receive.
> Once that is done, I read param_name using textscan and converted into string so that I can use both words separately. And it worked. =)
>
> Again, thank you so much ! !

Hello Karan and Walter,

I am closely following the discussion that's going on between you too,
but unfortunately I don't get most of it. Can you point me to some
documentation regarding these types of things? Specifically, sending
and receiving data through TCP or UDP and the blocks that should be
used in a Simulink model to achieve this. Do you have to use a toolbox
or blockset for that?

Again, if there is an example it can prove very helpful.

Regards,
Hooman