What is best way to trigger Octave via ethernet?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

What is best way to trigger Octave via ethernet?

Vision
Hey,

My project is about an Octave program that needs to run (without delay) when triggered by a Siemens PLC via ethernet.
Now I'm wondering what the best way is to achieve this.

I'm able to read data from the Siemens PLC using an .oct function that I created, but the drawback is that I need to call it everytime in a loop to check if some parameter changed (trigger), this is looks for me like unnecessary network traffic.

Now this is what I've in my mind.
I'm able to send TCP packets from the PLC to a specific IP and port.
Is there an option in octave to listen to this specific port and get triggered when data is transferred. I also think that avoiding a loop is better?

Thank you
Reply | Threaded
Open this post in threaded view
|

Re: What is best way to trigger Octave via ethernet?

Olaf Till-2
On Thu, Mar 31, 2016 at 07:54:21AM -0700, Vision wrote:
> I'm able to send TCP packets from the PLC to a specific IP and port.
> Is there an option in octave to listen to this specific port and get
> triggered when data is transferred. I also think that avoiding a loop is
> better?

If you already have an .oct file which can read from the port, you can
use the unix 'select()' call (see 'man 2 select') on this port.  It is
just there for such a purpouse; it can be used in a way that it
returns when data is readable.

Olaf

--
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: What is best way to trigger Octave via ethernet?

Olaf Till-2
On Thu, Mar 31, 2016 at 06:36:46PM +0200, Olaf Till wrote:

> On Thu, Mar 31, 2016 at 07:54:21AM -0700, Vision wrote:
> > I'm able to send TCP packets from the PLC to a specific IP and port.
> > Is there an option in octave to listen to this specific port and get
> > triggered when data is transferred. I also think that avoiding a loop is
> > better?
>
> If you already have an .oct file which can read from the port, you can
> use the unix 'select()' call (see 'man 2 select') on this port.  It is
> just there for such a purpouse; it can be used in a way that it
> returns when data is readable.
But since you have only one port to read from, reading in blocking
mode could suffice for you without select.

Olaf

--
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave

signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: What is best way to trigger Octave via ethernet?

Przemek Klosowski-7
In reply to this post by Vision
On 03/31/2016 10:54 AM, Vision wrote:

I'm able to send TCP packets from the PLC to a specific IP and port.
Is there an option in octave to listen to this specific port and get
triggered when data is transferred. I also think that avoiding a loop is
better?
There's even a way of doing what you want by calling an external network listener from your .m code:

   system("nc -l localhost 8080")

will sit there waiting until the netcat (nc) program returns, which will happen when you connect to localhost:8080; you can test that by executing

   echo test | nc localhost 8080

from another terminal. 'nc -l'  opens a socket in a listening mode and does a select() on it;  as others have pointed out, you can write an equivalent code in your .oct file.


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: What is best way to trigger Octave via ethernet?

Vision
In reply to this post by Olaf Till-2
Olaf Till-2 wrote
On Thu, Mar 31, 2016 at 06:36:46PM +0200, Olaf Till wrote:
But since you have only one port to read from, reading in blocking
mode could suffice for you without select.
I think I succeed to let it work with the receive function, but I need to accept the connection everytime (and disconnect for safety to I suppose).
I use following code at the moment:

%initialisation
s=socket();
bind(s,12345);

%loop
b=accept(s)
len=10;
[data,count]=recv(b,len);
disconnect(b);

Is this a reliable way when you take a power cut into account for instance?

Thank you