https://wiki.octave.org/wiki/api.php?action=feedcontributions&user=Lostbard&feedformat=atomOctave - User contributions [en]2024-03-28T10:22:00ZUser contributionsMediaWiki 1.39.2https://wiki.octave.org/wiki/index.php?title=Windows_package&diff=12136Windows package2019-08-06T18:44:36Z<p>Lostbard: </p>
<hr />
<div>The {{Forge|windows}} package is part of the [[Octave Forge]] project and provides a COM interface and additional functionality on Windows<br />
<br />
= Installation =<br />
== Package requirements ==<br />
This package requires Octave 3.6 or later.<br />
<br />
== Octave installation ==<br />
<br />
The package may already be installed if you are using the mxe-octave based installation of windows.<br />
<br />
To verify, from octave commmand line:<br />
<br />
>> pkg install list windows <br />
<br />
<br />
To install from octave commmand line:<br />
<br />
>> pkg install -forge windows<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load windows<br />
<br />
<br />
== Simple example ==<br />
<br />
This example uses the com interface to display the current directory.<br />
<br />
wshell = actxserver ("WScript.Shell");<br />
wshell.CurrentDirectory<br />
<br />
<br />
= Documentation =<br />
<br />
Documentation and reference for the Windows package is available on [https://octave.sourceforge.io/windows/overview.html Octave forge]<br />
<br />
[[Category:Octave Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Windows_package&diff=12135Windows package2019-08-06T18:43:59Z<p>Lostbard: </p>
<hr />
<div>The {{Forge|windows}} package is part of the [[Octave Forge]] project and provides a COM interface and additional functionality on Windows<br />
<br />
= Installation =<br />
== package requirements ==<br />
This package requires Octave 3.6 or later.<br />
<br />
== octave installation ==<br />
<br />
The package may already be installed if you are using the mxe-octave based installation of windows.<br />
<br />
To verify, from octave commmand line:<br />
<br />
>> pkg install list windows <br />
<br />
<br />
To install from octave commmand line:<br />
<br />
>> pkg install -forge windows<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load windows<br />
<br />
<br />
== Simple example ==<br />
<br />
This example uses the com interface to display the current directory.<br />
<br />
wshell = actxserver ("WScript.Shell");<br />
wshell.CurrentDirectory<br />
<br />
<br />
= Documentation =<br />
<br />
Documentation and reference for the Windows package is available on [https://octave.sourceforge.io/windows/overview.html Octave forge]<br />
<br />
[[Category:Octave Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Windows_package&diff=12134Windows package2019-08-06T18:38:59Z<p>Lostbard: Created page with "The {{Forge|windows}} package is part of the Octave Forge project and provides a COM interface and additional functionality on Windows = Installation = == package require..."</p>
<hr />
<div>The {{Forge|windows}} package is part of the [[Octave Forge]] project and provides a COM interface and additional functionality on Windows<br />
<br />
= Installation =<br />
== package requirements ==<br />
This package requires Octave 3.6 or later.<br />
<br />
== octave installation ==<br />
<br />
The package may already be installed if you are using the mxe-octave based installation of windows.<br />
<br />
To verify, from octave commmand line:<br />
<br />
>> pkg install list windows <br />
<br />
<br />
To install from octave commmand line:<br />
<br />
>> pkg install -forge windows<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load windows</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Zeromq_package&diff=12133Zeromq package2019-08-06T18:25:12Z<p>Lostbard: /* The functions */</p>
<hr />
<div>The {{Forge|zeromq}} package is part of the [[Octave Forge]] project and provides Octave bindings to the ZeroMQ library.<br />
<br />
= Installation =<br />
<br />
== package requirements ==<br />
<br />
The {{Forge|zeromq}} package requires the [http://zeromq.org/ ZeroMQ] libraries and include files to be installed in order to compile.<br />
<br />
for fedora: yum install zeromq-devel<br />
<br />
for ubuntu: apt install libzmq-dev<br />
<br />
== octave installation ==<br />
<br />
With the [http://zeromq.org/ ZeroMQ] library installed, from octave commmand line:<br />
<br />
>> pkg install -forge zeromq<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load zeromq<br />
<br />
Look at the quick reference for the package:<br />
<br />
>> help zeromq<br />
<br />
== Differences between C and Octave bindings ==<br />
<br />
The Octave binding is a subset of the C binding of the ZeroMQ library.<br />
<br />
Major differences are:<br />
<br />
1. The octave binding creates a single zeromq context that is used for all zeromq sockets. In the C bindings, the programmer must create a context and use it during socket creation.<br />
<br />
2. only limited zmq_getsockopt and zmq_setsockopt is currently implemented.<br />
<br />
3. functions mostly return true or false for whether they succeeded or failed. In the C binding, 0 signified success.<br />
<br />
== The functions ==<br />
<br />
iszmq<br />
Determine whether H is a zeromq socket object.<br />
<br />
zmq_bind<br />
Bind a zeromq socket to a endpoint.<br />
<br />
zmq_close<br />
Close a zeromq socket.<br />
<br />
zmq_connect<br />
Connect a zeromq socket to a endpoint<br />
<br />
zmq_curve_keypair<br />
Generate a random private/public keypair<br />
<br />
zmq_curve_public<br />
Derive the public key from a private key<br />
<br />
zmq_disconnect<br />
Disconnect a zeromq socket from an endpoint.<br />
<br />
zmq_errno<br />
Get system errno value.<br />
<br />
zmq_getsockopt<br />
Get current value of a zeromq socket option.<br />
<br />
zmq_has<br />
Check if the zmq library supports a given feature.<br />
<br />
zmq_poll<br />
Poll a socket or sockets for a timeout or incoming data<br />
available.<br />
<br />
zmq_recv<br />
Attempt to read data from a zeromq socket.<br />
<br />
zmq_send<br />
Attempt to send data from a zeromq socket.<br />
<br />
zmq_setsockopt<br />
Set a zeromq socket option.<br />
<br />
zmq_socket<br />
Create a zeromq socket.<br />
<br />
zmq_strerror<br />
Get the last zmq error string.<br />
<br />
zmq_unbind<br />
Unbind a previously bound zeromq socket.<br />
<br />
zmq_version<br />
Get the zeromq library version numbers.<br />
<br />
zmq_z85_decode<br />
Decode a z85 encoded string to a binary key.<br />
<br />
zmq_z85_encode<br />
Encode a binary key as Z85 printable text.<br />
<br />
= Examples =<br />
<br />
The zeromq package comes with a number of examples included in it. They can be opened in octave using:<br />
<br />
>> edit examples/zmq_example1.m<br />
<br />
<br />
== basic request/reply pattern ==<br />
<br />
Example based on client/server example from [http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive]<br />
<br />
The client sends a "Hello" to the server which responds back "World". No error checking or data validation is done in the example.<br />
<br />
{{Code|Server code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
printf ("Creating hello world server...\n");<br />
<br />
% create reply socket, and bind it to port 5555<br />
sock = zmq_socket (ZMQ_REP);<br />
<br />
zmq_bind (sock, "tcp://*:5555");<br />
<br />
printf ("Waiting for clients ...\n");<br />
<br />
% loop forever, waiting for client requests and responding back <br />
while (true)<br />
recievedata = zmq_recv (sock, 10, 0);<br />
printf ("Received Hello\n");<br />
zmq_send (sock, "World", 5, 0);<br />
endwhile<br />
</syntaxhighlight>}}<br />
<br />
{{Code|Client code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
printf ("Connecting to hello world server...\n");<br />
<br />
<br />
% Create socket and connect to server<br />
<br />
sock = zmq_socket (ZMQ_REQ);<br />
zmq_connect (sock, "tcp://localhost:5555");<br />
<br />
for request_nbr = [1:10]<br />
printf ("Sending Hello %d...\n", request_nbr);<br />
<br />
zmq_send (sock, uint8("Hello"), 5, 0);<br />
<br />
% try to read up to 10 bytes of reply data.<br />
printf ("Waiting for server response %d... (Ctrl-C to exit)\n", request_nbr); <br />
<br />
recieved = zmq_recv (sock, 10, 0);<br />
printf ("Received World %d\n", request_nbr);<br />
endfor<br />
<br />
zmq_close (sock);<br />
</syntaxhighlight>}}<br />
<br />
== basic publish/subscribe pattern ==<br />
<br />
Example based on client/server example from [http://zguide.zeromq.org/page:all#Getting-the-Message-Out http://zguide.zeromq.org/page:all#Getting-the-Message-Out]<br />
<br />
The server pushes 'weather updates' for random zipcodes. The client subscribes to the server just for zipcode 10001.<br />
<br />
{{Code|Server code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
publisher = zmq_socket (ZMQ_PUB);<br />
<br />
rc = zmq_bind (publisher, "tcp://*:5556");<br />
assert (rc);<br />
<br />
while (true) <br />
% Get values that will fool the boss<br />
zipcode = 10000 + randi (20);<br />
temperature = randi (215) - 80;<br />
relhumidity = randi (50) + 10;<br />
<br />
% Send message to all subscribers<br />
update = sprintf ("%05d %d %d", zipcode, temperature, relhumidity);<br />
<br />
zmq_send (publisher, update);<br />
endwhile<br />
<br />
zmq_close (publisher);<br />
</syntaxhighlight>}}<br />
<br />
{{Code|Client code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
subscriber = zmq_socket (ZMQ_SUB);<br />
rc = zmq_connect (subscriber, "tcp://localhost:5556");<br />
assert (rc);<br />
<br />
% Subscribe to zipcode, default is NYC, 10001<br />
zipfilter = "10001 ";<br />
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, zipfilter);<br />
assert (rc);<br />
<br />
% Process 100 updates<br />
update_nbr = 0;<br />
total_temp = 0;<br />
<br />
for update_nbr = 1:100<br />
string = char( zmq_recv(subscriber, 128) );<br />
<br />
[zipcode, temperature, relhumidity, count, errmsg] = sscanf (string, "%d %d %d", "C");<br />
<br />
fprintf ("recieved a temp for zipcode '%s' of %dF\n", ...<br />
zipfilter, temperature);<br />
<br />
total_temp += temperature;<br />
endfor<br />
<br />
fprintf ("Average temperature for zipcode '%s' was %dF\n", ...<br />
zipfilter, (total_temp / update_nbr));<br />
<br />
zmq_close (subscriber);<br />
</syntaxhighlight>}}<br />
<br />
<br />
[[Category:Octave Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Arduino_package&diff=11264Arduino package2018-12-06T14:16:48Z<p>Lostbard: /* Arduino board hardware setup */</p>
<hr />
<div>The {{Forge|arduino}} package is part of the [[Octave Forge]] project and provides an Octave look-alike implementation of the Arduino extension for Matlab.<br />
<br />
= Installation =<br />
== package requirements ==<br />
This package requires Octave 4.0 or later.<br />
<br />
It needs the Arduino IDE to be installed and functioning on the computer in order to program Arduino boards, however does not need it to control boards that have already been programmed.<br />
<br />
The Arduino package also requires the {{Forge|instrument-control}} package to be installed.<br />
<br />
== octave installation ==<br />
From octave commmand line:<br />
<br />
>> pkg install -forge arduino<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load arduino<br />
<br />
<br />
== Arduino board hardware setup ==<br />
In order to use the arduino hardware with the toolkit, it must be programmed with special firmware.<br />
<br />
From octave commmand line:<br />
<br />
>> arduinosetup<br />
<br />
A temporary Arduino project will be created, with the Arduino toolkit files copied to it and the Arduino IDE will open. <br />
<br />
Set the board type and port correctly for the connected Arduino and press the upload button on the IDE. <br />
<br />
The sources will be compiled and then uploaded to the connected arduino board. <br />
<br />
After successful upload the Arduino IDE should be closed.<br />
<br />
'''NOTE:''' on some versions of Ubuntu, the default installed Arduino IDE / java interface is broken so that the IDE will not detect the serial port and allow the board to be programmed. The solution is installed the Arduino ide as a flatpack, or manually. The Arduino binary must be added to the path in order to be found by arduinosetup. Alternatively, the full path/binary for the ide can be specified to arduinosetup.<br />
<br />
<br />
>> arduinosetup('arduinobinary', '/path_to_the_installed_arduino/arduino')<br />
<br />
== Connecting to an Arduino ==<br />
<br />
Assuming a single arduino device is connected to the computer, creating an arduino object with no arguments will find the connected arduino and connect to it: <br />
<br />
>> a = arduino;<br />
<br />
Where multiple arduinos may be connected to the computer, a specific board can be connected by specifying the name of the port it is connected to: <br />
<br />
>> ar = arduino("/dev/ttyACM0")<br />
<br />
<br />
To list the ports of all programmed available arduinos, the scanForArduinos function can be used: <br />
<br />
>> scanForArduinos<br />
<br />
<br />
This will list information on each detected (programmed with firmware) Arduino board found.<br />
<br />
== Simple example ==<br />
<br />
The following example shows very basic control of the Arduino package to blink the inbuilt LED.<br />
<br />
1. load the Arduino package (if not already done)<br />
<br />
>> pkg load arduino<br />
<br />
<br />
2. create an arduino object<br />
<br />
>> a = arduino;<br />
<br />
3. what pin is the inbuild LED on? On Uno boards, D13.<br />
<br />
>> led_pin = "d13";<br />
<br />
4. turn LED off.<br />
<br />
>> writeDigitalPin (a, led_pin, 0);<br />
<br />
5. turn LED on.<br />
<br />
>> writeDigitalPin (a, led_pin, 1);<br />
<br />
<br />
The full code, with the LED controlled in a loop ti turn it on/off each second is in the following example:<br />
<br />
a = arduino;<br />
led_pin = "d13";<br />
while true<br />
writeDigitalPin (ar, led_pin, 0);<br />
pause (0.5)<br />
writeDigitalPin (ar, led_pin, 1);<br />
pause (0.5)<br />
endwhile<br />
<br />
<br />
= Documentation =<br />
<br />
Documentation and reference for the Arduino package is available as:<br />
<br />
* The [https://octave.sourceforge.io/arduino/package_doc/index.html Online manual]<br />
<br />
* The [https://octave.sourceforge.io/arduino/overview.html Function Reference]<br />
<br />
[[Category:Octave Forge]][[Category:Packages]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Arduino_package&diff=11210Arduino package2018-09-04T16:23:10Z<p>Lostbard: </p>
<hr />
<div>The {{Forge|arduino}} package is part of the [[Octave Forge]] project and provides an Octave look-alike implementation of the Arduino extension for Matlab.<br />
<br />
= Installation =<br />
== package requirements ==<br />
This package requires Octave 4.0 or later.<br />
<br />
It needs the Arduino IDE to be installed and functioning on the computer in order to program Arduino boards, however does not need it to control boards that have already been programmed.<br />
<br />
The Arduino package also requires the {{Forge|instrument-control}} package to be installed.<br />
<br />
== octave installation ==<br />
From octave commmand line:<br />
<br />
>> pkg install -forge arduino<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load arduino<br />
<br />
<br />
== Arduino board hardware setup ==<br />
In order to use the arduino hardware with the toolkit, it must be programmed with special firmware.<br />
<br />
From octave commmand line:<br />
<br />
>> arduinosetup<br />
<br />
A temporary Arduino project will be created, with the Arduino toolkit files copied to it and the Arduino IDE will open. <br />
<br />
Set the board type and port correctly for the connected Arduino and press the upload button on the IDE. <br />
<br />
The sources will be compiled and then uploaded to the connected arduino board. <br />
<br />
After successful upload the Arduino IDE should be closed.<br />
<br />
== Connecting to an Arduino ==<br />
<br />
Assuming a single arduino device is connected to the computer, creating an arduino object with no arguments will find the connected arduino and connect to it: <br />
<br />
>> a = arduino;<br />
<br />
Where multiple arduinos may be connected to the computer, a specific board can be connected by specifying the name of the port it is connected to: <br />
<br />
>> ar = arduino("/dev/ttyACM0")<br />
<br />
<br />
To list the ports of all programmed available arduinos, the scanForArduinos function can be used: <br />
<br />
>> scanForArduinos<br />
<br />
<br />
This will list information on each detected (programmed with firmware) Arduino board found.<br />
<br />
== Simple example ==<br />
<br />
The following example shows very basic control of the Arduino package to blink the inbuilt LED.<br />
<br />
1. load the Arduino package (if not already done)<br />
<br />
>> pkg load arduino<br />
<br />
<br />
2. create an arduino object<br />
<br />
>> a = arduino;<br />
<br />
3. what pin is the inbuild LED on? On Uno boards, D13.<br />
<br />
>> led_pin = "d13";<br />
<br />
4. turn LED off.<br />
<br />
>> writeDigitalPin (a, led_pin, 0);<br />
<br />
5. turn LED on.<br />
<br />
>> writeDigitalPin (a, led_pin, 1);<br />
<br />
<br />
The full code, with the LED controlled in a loop ti turn it on/off each second is in the following example:<br />
<br />
a = arduino;<br />
led_pin = "d13";<br />
while true<br />
writeDigitalPin (ar, led_pin, 0);<br />
pause (0.5)<br />
writeDigitalPin (ar, led_pin, 1);<br />
pause (0.5)<br />
endwhile<br />
<br />
<br />
= Documentation =<br />
<br />
Documentation and reference for the Arduino package is available as:<br />
<br />
* The [https://octave.sourceforge.io/arduino/package_doc/index.html Online manual]<br />
<br />
* The [https://octave.sourceforge.io/arduino/overview.html Function Reference]<br />
<br />
[[Category:Octave Forge]][[Category:Packages]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Arduino_package&diff=11209Arduino package2018-09-04T16:21:33Z<p>Lostbard: </p>
<hr />
<div>The {{Forge|arduino}} package is part of the [[Octave Forge]] project and provides an Octave look-alike implementation of the Arduino extension for Matlab.<br />
<br />
= Installation =<br />
== package requirements ==<br />
This package requires Octave 4.0 or later.<br />
<br />
It needs the Arduino IDE to be installed and functioning on the computer in order to program Arduino boards, however does not need it to control boards that have already been programmed.<br />
<br />
The Arduino package also requires the {{Forge|instrument-control}} package to be installed.<br />
<br />
== octave installation ==<br />
From octave commmand line:<br />
<br />
>> pkg install -forge arduino<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load arduino<br />
<br />
<br />
== Arduino board hardware setup ==<br />
In order to use the arduino hardware with the toolkit, it must be programmed with special firmware.<br />
<br />
From octave commmand line:<br />
<br />
>> arduinosetup<br />
<br />
A temporary Arduino project will be created, with the Arduino toolkit files copied to it and the Arduino IDE will open. <br />
<br />
Set the board type and port correctly for the connected Arduino and press the upload button on the IDE. <br />
<br />
The sources will be compiled and then uploaded to the connected arduino board. <br />
<br />
After successful upload the Arduino IDE should be closed.<br />
<br />
== Connecting to an Arduino ==<br />
<br />
Assuming a single arduino device is connected to the computer, creating an arduino object with no arguments will find the connected arduino and connect to it: <br />
<br />
>> a = arduino;<br />
<br />
Where multiple arduinos may be connected to the computer, a specific board can be connected by specifying the name of the port it is connected to: <br />
<br />
>> ar = arduino("/dev/ttyACM0")<br />
<br />
<br />
To list the ports of all programmed available arduinos, the scanForArduinos function can be used: <br />
<br />
>> scanForArduinos<br />
<br />
<br />
This will list information on each detected (programmed with firmware) Arduino board found.<br />
<br />
== Simple example ==<br />
<br />
The following example shows very basic control of the Arduino package to blink the inbuilt LED.<br />
<br />
1. load the Arduino package (if not already done)<br />
<br />
>> pkg load arduino<br />
<br />
<br />
2. create an arduino object<br />
<br />
>> a = arduino;<br />
<br />
3. what pin is the inbuild LED on? On Uno boards, D13.<br />
<br />
>> led_pin = "d13";<br />
<br />
4. turn LED off.<br />
<br />
>> writeDigitalPin (a, led_pin, 0);<br />
<br />
5. turn LED on.<br />
<br />
>> writeDigitalPin (a, led_pin, 1);<br />
<br />
<br />
The full code, with the LED controlled in a loop ti turn it on/off each second is in the following example:<br />
<br />
a = arduino;<br />
led_pin = "d13";<br />
while true<br />
writeDigitalPin (ar, led_pin, 0);<br />
pause (0.5)<br />
writeDigitalPin (ar, led_pin, 1);<br />
pause (0.5)<br />
endwhile<br />
<br />
<br />
= Documentation =<br />
<br />
Documentation and reference for the Arduino package is available as:<br />
<br />
* The [https://octave.sourceforge.io/arduino/package_doc/index.html Online manual]<br />
<br />
* The [https://octave.sourceforge.io/arduino/overview.html Function Reference]<br />
<br />
[[Category:Octave Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Arduino_package&diff=11208Arduino package2018-09-04T16:12:53Z<p>Lostbard: </p>
<hr />
<div>The {{Forge|arduino}} package is part of the [[Octave Forge]] project and provides an Octave look-alike implementation of the Arduino extension for Matlab.<br />
<br />
= Installation =<br />
== package requirements ==<br />
This package requires Octave 4.0 or later.<br />
<br />
It needs the Arduino IDE to be installed and functioning on the computer in order to program Arduino boards, however does not need it to control boards that have already been programmed.<br />
<br />
The Arduino package also requires the {{Forge|instrument-control}} package to be installed.<br />
<br />
== octave installation ==<br />
From octave commmand line:<br />
<br />
>> pkg install -forge arduino<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load arduino<br />
<br />
<br />
== Arduino board hardware setup ==<br />
In order to use the arduino hardware with the toolkit, it must be programmed with special firmware.<br />
<br />
From octave commmand line:<br />
<br />
>> arduinosetup<br />
<br />
A temporary Arduino project will be created, with the Arduino toolkit files copied to it and the Arduino IDE will open. <br />
<br />
Set the board type and port correctly for the connected Arduino and press the upload button on the IDE. <br />
<br />
The sources will be compiled and then uploaded to the connected arduino board. <br />
<br />
After successful upload the Arduino IDE should be closed.<br />
<br />
== Connecting to an Arduino ==<br />
<br />
Assuming a single arduino device is connected to the computer, creating an arduino object with no arguments will find the connected arduino and connect to it: <br />
<br />
>> a = arduino;<br />
<br />
Where multiple arduinos may be connected to the computer, a specific board can be connected by specifying the name of the port it is connected to: <br />
<br />
>> ar = arduino("/dev/ttyACM0")<br />
<br />
<br />
To list the ports of all programmed available arduinos, the scanForArduinos function can be used: <br />
<br />
>> scanForArduinos<br />
<br />
<br />
This will list information on each detected (programmed with firmware) Arduino board found.<br />
<br />
== Simple example ==<br />
<br />
The following example shows very basic control of the Arduino package to blink the inbuilt LED.<br />
<br />
1. load the Arduino package (if not already done)<br />
<br />
>> pkg load arduino<br />
<br />
<br />
2. create an arduino object<br />
<br />
>> a = arduino;<br />
<br />
3. what pin is the inbuild LED on? On Uno boards, D13.<br />
<br />
>> led_pin = "d13";<br />
<br />
4. turn LED off.<br />
<br />
>> writeDigitalPin (a, led_pin, 0);<br />
<br />
5. turn LED on.<br />
<br />
>> writeDigitalPin (a, led_pin, 1);<br />
<br />
<br />
The full code, with the LED controlled in a loop ti turn it on/off each second is in the following example:<br />
<br />
a = arduino;<br />
led_pin = "d13";<br />
while true<br />
writeDigitalPin (ar, led_pin, 0);<br />
pause (0.5)<br />
writeDigitalPin (ar, led_pin, 1);<br />
pause (0.5)<br />
endwhile<br />
<br />
<br />
= Documentation =<br />
<br />
Documentation and reference for the Arduino package is available as:<br />
<br />
* The [https://octave.sourceforge.io/arduino/package_doc/index.html Online manual]<br />
<br />
* The [https://octave.sourceforge.io/arduino/overview.html Function Reference]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Arduino_package&diff=11207Arduino package2018-09-04T16:11:17Z<p>Lostbard: /* Documentation */</p>
<hr />
<div>The {{Forge|arduino}} package is part of the [[Octave Forge]] project and provides an Octave look-alike implementation of the Arduino extension for Matlab.<br />
<br />
= Installation =<br />
== package requirements ==<br />
This package requires Octave 4.0 or later.<br />
<br />
It needs the Arduino IDE to be installed and functioning on the computer in order to program Arduino boards, however does not need it to control boards that have already been programmed.<br />
<br />
The Arduino package also requires the instrument-control package to be installed.<br />
<br />
== octave installation ==<br />
From octave commmand line:<br />
<br />
>> pkg install -forge arduino<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load arduino<br />
<br />
<br />
== Arduino board hardware setup ==<br />
In order to use the arduino hardware with the toolkit, it must be programmed with special firmware.<br />
<br />
From octave commmand line:<br />
<br />
>> arduinosetup<br />
<br />
A temporary Arduino project will be created, with the Arduino toolkit files copied to it and the Arduino IDE will open. <br />
<br />
Set the board type and port correctly for the connected Arduino and press the upload button on the IDE. <br />
<br />
The sources will be compiled and then uploaded to the connected arduino board. <br />
<br />
After successful upload the Arduino IDE should be closed.<br />
<br />
== Connecting to an Arduino ==<br />
<br />
Assuming a single arduino device is connected to the computer, creating an arduino object with no arguments will find the connected arduino and connect to it: <br />
<br />
>> a = arduino;<br />
<br />
Where multiple arduinos may be connected to the computer, a specific board can be connected by specifying the name of the port it is connected to: <br />
<br />
>> ar = arduino("/dev/ttyACM0")<br />
<br />
<br />
To list the ports of all programmed available arduinos, the scanForArduinos function can be used: <br />
<br />
>> scanForArduinos<br />
<br />
<br />
This will list information on each detected (programmed with firmware) Arduino board found.<br />
<br />
== Simple example ==<br />
<br />
The following example shows very basic control of the Arduino package to blink the inbuilt LED.<br />
<br />
1. load the Arduino package (if not already done)<br />
<br />
>> pkg load arduino<br />
<br />
<br />
2. create an arduino object<br />
<br />
>> a = arduino;<br />
<br />
3. what pin is the inbuild LED on? On Uno boards, D13.<br />
<br />
>> led_pin = "d13";<br />
<br />
4. turn LED off.<br />
<br />
>> writeDigitalPin (a, led_pin, 0);<br />
<br />
5. turn LED on.<br />
<br />
>> writeDigitalPin (a, led_pin, 1);<br />
<br />
<br />
The full code, with the LED controlled in a loop ti turn it on/off each second is in the following example:<br />
<br />
a = arduino;<br />
led_pin = "d13";<br />
while true<br />
writeDigitalPin (ar, led_pin, 0);<br />
pause (0.5)<br />
writeDigitalPin (ar, led_pin, 1);<br />
pause (0.5)<br />
endwhile<br />
<br />
<br />
= Documentation =<br />
<br />
Documentation and reference for the Arduino package is available as:<br />
<br />
* The [https://octave.sourceforge.io/arduino/package_doc/index.html Online manual]<br />
<br />
* The [https://octave.sourceforge.io/arduino/overview.html Function Reference]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Arduino_package&diff=11206Arduino package2018-09-04T16:10:45Z<p>Lostbard: </p>
<hr />
<div>The {{Forge|arduino}} package is part of the [[Octave Forge]] project and provides an Octave look-alike implementation of the Arduino extension for Matlab.<br />
<br />
= Installation =<br />
== package requirements ==<br />
This package requires Octave 4.0 or later.<br />
<br />
It needs the Arduino IDE to be installed and functioning on the computer in order to program Arduino boards, however does not need it to control boards that have already been programmed.<br />
<br />
The Arduino package also requires the instrument-control package to be installed.<br />
<br />
== octave installation ==<br />
From octave commmand line:<br />
<br />
>> pkg install -forge arduino<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load arduino<br />
<br />
<br />
== Arduino board hardware setup ==<br />
In order to use the arduino hardware with the toolkit, it must be programmed with special firmware.<br />
<br />
From octave commmand line:<br />
<br />
>> arduinosetup<br />
<br />
A temporary Arduino project will be created, with the Arduino toolkit files copied to it and the Arduino IDE will open. <br />
<br />
Set the board type and port correctly for the connected Arduino and press the upload button on the IDE. <br />
<br />
The sources will be compiled and then uploaded to the connected arduino board. <br />
<br />
After successful upload the Arduino IDE should be closed.<br />
<br />
== Connecting to an Arduino ==<br />
<br />
Assuming a single arduino device is connected to the computer, creating an arduino object with no arguments will find the connected arduino and connect to it: <br />
<br />
>> a = arduino;<br />
<br />
Where multiple arduinos may be connected to the computer, a specific board can be connected by specifying the name of the port it is connected to: <br />
<br />
>> ar = arduino("/dev/ttyACM0")<br />
<br />
<br />
To list the ports of all programmed available arduinos, the scanForArduinos function can be used: <br />
<br />
>> scanForArduinos<br />
<br />
<br />
This will list information on each detected (programmed with firmware) Arduino board found.<br />
<br />
== Simple example ==<br />
<br />
The following example shows very basic control of the Arduino package to blink the inbuilt LED.<br />
<br />
1. load the Arduino package (if not already done)<br />
<br />
>> pkg load arduino<br />
<br />
<br />
2. create an arduino object<br />
<br />
>> a = arduino;<br />
<br />
3. what pin is the inbuild LED on? On Uno boards, D13.<br />
<br />
>> led_pin = "d13";<br />
<br />
4. turn LED off.<br />
<br />
>> writeDigitalPin (a, led_pin, 0);<br />
<br />
5. turn LED on.<br />
<br />
>> writeDigitalPin (a, led_pin, 1);<br />
<br />
<br />
The full code, with the LED controlled in a loop ti turn it on/off each second is in the following example:<br />
<br />
a = arduino;<br />
led_pin = "d13";<br />
while true<br />
writeDigitalPin (ar, led_pin, 0);<br />
pause (0.5)<br />
writeDigitalPin (ar, led_pin, 1);<br />
pause (0.5)<br />
endwhile<br />
<br />
<br />
= Documentation =<br />
<br />
Documentation and reference for the Arduino toolkit is available as:<br />
<br />
* The [https://octave.sourceforge.io/arduino/package_doc/index.html Online manual]<br />
<br />
* The [https://octave.sourceforge.io/arduino/overview.html Function Reference]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Arduino_package&diff=11205Arduino package2018-09-04T16:10:00Z<p>Lostbard: /* package requirements */</p>
<hr />
<div>The {{Forge|arduino}} package is part of the [[Octave Forge]] project and provides an Octave look-alike implementation of the Arduino extension for Matlab.<br />
<br />
= Installation =<br />
== package requirements ==<br />
This package requires Octave 4.0 or later.<br />
<br />
It needs the Arduino IDE to be installed and functioning on the computer in order to program Arduino boards, however does not need it to control boards that have already been programmed.<br />
<br />
The Arduino package also requires the instrument-control package to be installed.<br />
<br />
== octave installation ==<br />
From octave commmand line:<br />
<br />
>> pkg install -forge arduino<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load arduino<br />
<br />
<br />
== Arduino board hardware setup ==<br />
In order to use the arduino hardware with the toolkit, it must be programmed with special firmware.<br />
<br />
From octave commmand line:<br />
<br />
>> arduinosetup<br />
<br />
A temporary Arduino project will be created, with the Arduino toolkit files copied to it and the Arduino IDE will open. <br />
<br />
Set the board type and port correctly for the connected Arduino and press the upload button on the IDE. <br />
<br />
The sources will be compiled and then uploaded to the connected arduino board. <br />
<br />
After successful upload the Arduino IDE should be closed.<br />
<br />
== Connecting to an Arduino ==<br />
<br />
Assuming a single arduino device is connected to the computer, creating an arduino object with no arguments will find the connected arduino and connect to it: <br />
<br />
>> a = arduino;<br />
<br />
Where multiple arduinos may be connected to the computer, a specific board can be connected by specifying the name of the port it is connected to: <br />
<br />
>> ar = arduino("/dev/ttyACM0")<br />
<br />
<br />
To list the ports of all programmed available arduinos, the scanForArduinos function can be used: <br />
<br />
>> scanForArduinos<br />
<br />
<br />
This will list information on each detected (programmed with firmware) Arduino board found.<br />
<br />
== Simple example ==<br />
<br />
The following example shows very basic control of the Arduino package to blink the inbuilt LED.<br />
<br />
1. load the Arduino package (if not already done)<br />
<br />
>> pkg load arduino<br />
<br />
<br />
2. create an arduino object<br />
<br />
>> a = arduino;<br />
<br />
3. what pin is the inbuild LED on? On Uno boards, D13.<br />
<br />
>> led_pin = "d13";<br />
<br />
4. turn LED off.<br />
<br />
>> writeDigitalPin (a, led_pin, 0);<br />
<br />
5. turn LED on.<br />
<br />
>> writeDigitalPin (a, led_pin, 1);<br />
<br />
<br />
The full code, with the LED controlled in a loop ti turn it on/off each second is in the following example:<br />
<br />
a = arduino;<br />
led_pin = "d13";<br />
while true<br />
writeDigitalPin (ar, led_pin, 0);<br />
pause (0.5)<br />
writeDigitalPin (ar, led_pin, 1);<br />
pause (0.5)<br />
endwhile<br />
<br />
<br />
== Documentation ==<br />
<br />
Documentation and reference for the Arduino toolkit is available as:<br />
<br />
* The [https://octave.sourceforge.io/arduino/package_doc/index.html Online manual]<br />
<br />
* The [https://octave.sourceforge.io/arduino/overview.html Function Reference]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=GNU_Octave_Wiki&diff=11204GNU Octave Wiki2018-09-04T16:08:08Z<p>Lostbard: /* Octave Forge */</p>
<hr />
<div>[https://www.gnu.org/software/octave/ GNU Octave] is a high-level interpreted language, primarily intended for numerical computations. It provides capabilities for the numerical solution of linear and nonlinear problems, and for performing other numerical experiments. It also provides extensive graphics capabilities for data visualization and manipulation. GNU Octave is normally used through its interactive interface ([https://en.wikipedia.org/wiki/Command-line_interface CLI] and [https://en.wikipedia.org/wiki/Graphical_user_interface GUI]), but it can also be used to write non-interactive programs. The GNU Octave language is quite similar to Matlab so that most programs are easily portable.<br />
<br />
== [[:Category:Installation|Installing]] ==<br />
<br />
* Get installers and sources from https://www.octave.org/download<br />
** [[Octave for macOS|macOS installation instructions]]<br />
** [[Octave for GNU/Linux|GNU/Linux installation instructions]] and for [[Octave for other Unix systems|other Unix systems]]<br />
** [[Octave_for_Microsoft_Windows|Microsoft Windows installation instructions]]<br />
** [[Octave_and_separate_toolchain|Build Octave using a separate toolchain]] (custom built gcc version)<br />
<br />
{{Note|GNU Octave {{Release}} is the current stable release}}<br />
<br />
Are you using an old version of Octave? Check the [[Release History]] page to see how old it is.<br />
<br />
== [https://www.gnu.org/software/octave/news.html News] ==<br />
<br />
* {{Release Date}} '''GNU Octave {{Release}}''' has been released (see above)!<br />
<br />
* GNU Octave is a mentor organization for [https://summerofcode.withgoogle.com/organizations/4797252556554240/ Google Summer of Code 2018]. Congratulations to our [[Summer_of_Code#GSoC_2018|three students]] for being elected and happy coding this summer!<br />
<br />
== Getting help ==<br />
<br />
* Read the [https://www.gnu.org/software/octave/doc/interpreter GNU Octave documentation]<br />
* The [[FAQ|frequently asked questions (FAQ)]] list is good place to start with answers to questions regarding [[FAQ#General|what is Octave]], [[FAQ#Licensing_issues|licensing]], [[FAQ#What.27s_new_in_Octave|new features]], [[FAQ#What_documentation_exists_for_Octave.3F|documentation]], [[FAQ#Installation_issues_and_problems|installation]], [[FAQ#Coding|coding]], [[FAQ#How_can_I_get_involved_in_Octave_development.3F|contributing to Octave]], and more, are found there.<br />
* Continue reading this wiki and feel free to add further content (please check that it is not already part of, or belongs in, the documentation and read the [[Contribution guidelines]]).<br />
* [https://www.gnu.org/software/octave/support.html Other support options]<br />
<br />
== [[Using Octave|Getting started]] ==<br />
<br />
* [[Publications using Octave#Books|Books]]<br />
* [[Video tutorials|Videos]]<br />
* [https://bagustris.github.io/octave-tutorial Short course]<br />
<br><br />
<br />
__TOC__<br />
<br />
== Advanced topics ==<br />
<br />
Below is a temporary attempt to organize the "most wanted" pages of the Wiki. A list of all pages on the wiki can be seen [[Special:AllPages|here]]. To locate something specific, try the wiki's search box, or prepend {{Codeline|<nowiki>site:wiki.octave.org</nowiki>}} to a [https://www.google.com/search?&q=site%3Awiki.octave.org Google search]. Please read the [[Contribution guidelines]] first, if you want to contribute to this Wiki.<br />
<br />
=== [[:Category:Packages|Packages]] ===<br />
<br />
* [[OEP:pkg|Installing packages]]<br />
* [[Creating packages]]<br />
<br />
==== [[Octave Forge]] ====<br />
<br />
See also the list of Forge Wiki pages: [[:Category:Octave Forge]]<br />
* [[Arduino_package|arduino package]] Control arduino devices from Octave<br />
* [[bim_package|bim package]] Solve Partial Differential Equations with a Finite Element method<br />
* [[Control_package|Control package]]<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/CGI_programming_with_Octave CGI] Common Gateway Interface for Octave<br />
* [[Dataframe_package|Dataframe package]] cell arrays on steroids<br />
* [[Dicom_package|Dicom package]]<br />
* [[Fem-fenics|fem-fenics]] Interface to [http://fenicsproject.org/ FEnics] FEM library<br />
* [[Geometry_package|Geometry package]]<br />
* [[Image package]]<br />
* [[Image_acquisition_package|Image acquisition package]] Capture images, for example from v4l2 hardware like webcams<br />
* [[Instrument_control__package|Instrument control package]]<br />
* [[Interval_package|Interval package]] Real-valued interval arithmetic<br />
* [[IO_package|I/O package]]<br />
* [[Java_package|Java package]]<br />
* [[Mechanics_package|Mechanics package]]<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/NcArray ncArray] High-level interface of accessing a single or a collection of NetCDF files as a multi-dimensional array<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/Octave-netcdf netcdf] matlab-compatible NetCDF package<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/NetCDF_toolbox_for_Octave octcdf] NetCDF package (old)<br />
* [[ocs_package|OCS package]] Octave Circuit Simulator<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/Optimal_interpolation_Fortran_module_with_Octave_interface optiminterp] Optimal interpolation<br />
* [[Parallel_package|Parallel package]]<br />
* [[Sockets_package|Sockets package]]<br />
* [[Symbolic package|Symbolic package]]<br />
* [[TISEAN_package|TISEAN package]]<br />
* [[Video_package|Video package]]<br />
* [[sci_cosim|Scilab co-simulation package]]<br />
* [[Zeromq_package|Zeromq package]] Zeromq bindings for Octave.<br />
<br />
=== [[:Category:Resources|Tutorials/Examples]] ===<br />
<br />
* [[Octave Basics]] - A short reference card to get started.<br />
* [[:Category:Plotting tutorials|Plotting tutorials]]<br />
* [[Tips and tricks]] - Guidelines to improve your coding skills.<br />
* [[Cookbook]] - Several simple and useful examples.<br />
* [[Octave load]] - Use liboctave functions to load variables from a file in Octave's binary format. <br />
* [[Fortran]] - Accessing liboctave from a Fortran 2003 program.<br />
* [[Octave fun]] - Coding can be fun -- miscellaneous more or less funny scripts<br />
* [http://www.amiq.com/consulting/2014/11/21/how-to-connect-systemverilog-with-octave/ How to Connect SystemVerilog with Octave]<br />
<br />
<br />
=== [[:Category:Development|Development]] ===<br />
<br />
Find a longer list of relevant links for developers at the [[Developers]] page.<br />
<br />
* [[Contribution guidelines]]<br />
* [[Doxygen]] - Internal C++ code documentation<br />
* [[International Characters Support]] - Using Octave in your own language.<br />
* [[:Category:Editors|Editors]] - A list of editors supporting Octave syntax highlighting.<br />
* [[4.4.0 Release Checklist]]<br />
<br />
==== [[:Category:Building|Building]] ====<br />
<br />
* [[Building]]<br />
* [[Continuous Build]]<br />
* [[Enable large arrays: Build octave such that it can use arrays larger than 2Gb.|Building Octave to use large arrays]]<br />
<br />
==== [[:Category:Testing|Testing]] ====<br />
<br />
* [[Tests|Testing source code]]<br />
<br />
==== [[:Category:Packaging|Packaging]] ====<br />
<br />
* [[Create a MacOS X App Bundle Using MacPorts]]<br />
* [[Windows_Installer|Create a Windows Installer using MXE]]<br />
<br />
=== [[:Category:Academia|Academia]] ===<br />
<br />
* [[Publications using Octave]] - A compilation of scientific publications making reference to GNU Octave (add yours!).<br />
<br />
=== [[:Category:Project Ideas|Project Ideas]] ===<br />
<br />
* [[Projects]]<br />
* [[Summer of Code Project Ideas]]<br />
<br />
== External Links ==<br />
<br />
* [https://www.gnu.org/software/octave/ Octave Homepage]<br />
* [https://octave.sourceforge.io/ Octave Forge]<br />
* [https://savannah.gnu.org/bugs/?group=octave GNU Octave - Bug Tracker]<br />
* [https://savannah.gnu.org/task/?group=octave GNU Octave - Task Tracker]<br />
* [https://savannah.gnu.org/patch/?group=octave GNU Octave - Patch Tracker]<br />
* [https://savannah.gnu.org/hg/?group=octave GNU Octave - Mercurial Repositories]<br />
* [https://planet.octave.org/ Planet Octave] (collection of blog feeds featuring Octave developers and Summer of Code students)</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Arduino_package&diff=11203Arduino package2018-09-04T16:05:43Z<p>Lostbard: Created page with "The {{Forge|arduino}} package is part of the Octave Forge project and provides an Octave look-alike implementation of the Arduino extension for Matlab. = Installation = =..."</p>
<hr />
<div>The {{Forge|arduino}} package is part of the [[Octave Forge]] project and provides an Octave look-alike implementation of the Arduino extension for Matlab.<br />
<br />
= Installation =<br />
== package requirements ==<br />
The Arduino package needs the Arduino IDE to be installed and functioning on the computer in order to program Arduino boards, however does not need it to control boards that have already been programmed.<br />
<br />
The Arduino package also requires the instrument-control package to be installed.<br />
<br />
== octave installation ==<br />
From octave commmand line:<br />
<br />
>> pkg install -forge arduino<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load arduino<br />
<br />
<br />
== Arduino board hardware setup ==<br />
In order to use the arduino hardware with the toolkit, it must be programmed with special firmware.<br />
<br />
From octave commmand line:<br />
<br />
>> arduinosetup<br />
<br />
A temporary Arduino project will be created, with the Arduino toolkit files copied to it and the Arduino IDE will open. <br />
<br />
Set the board type and port correctly for the connected Arduino and press the upload button on the IDE. <br />
<br />
The sources will be compiled and then uploaded to the connected arduino board. <br />
<br />
After successful upload the Arduino IDE should be closed.<br />
<br />
== Connecting to an Arduino ==<br />
<br />
Assuming a single arduino device is connected to the computer, creating an arduino object with no arguments will find the connected arduino and connect to it: <br />
<br />
>> a = arduino;<br />
<br />
Where multiple arduinos may be connected to the computer, a specific board can be connected by specifying the name of the port it is connected to: <br />
<br />
>> ar = arduino("/dev/ttyACM0")<br />
<br />
<br />
To list the ports of all programmed available arduinos, the scanForArduinos function can be used: <br />
<br />
>> scanForArduinos<br />
<br />
<br />
This will list information on each detected (programmed with firmware) Arduino board found.<br />
<br />
== Simple example ==<br />
<br />
The following example shows very basic control of the Arduino package to blink the inbuilt LED.<br />
<br />
1. load the Arduino package (if not already done)<br />
<br />
>> pkg load arduino<br />
<br />
<br />
2. create an arduino object<br />
<br />
>> a = arduino;<br />
<br />
3. what pin is the inbuild LED on? On Uno boards, D13.<br />
<br />
>> led_pin = "d13";<br />
<br />
4. turn LED off.<br />
<br />
>> writeDigitalPin (a, led_pin, 0);<br />
<br />
5. turn LED on.<br />
<br />
>> writeDigitalPin (a, led_pin, 1);<br />
<br />
<br />
The full code, with the LED controlled in a loop ti turn it on/off each second is in the following example:<br />
<br />
a = arduino;<br />
led_pin = "d13";<br />
while true<br />
writeDigitalPin (ar, led_pin, 0);<br />
pause (0.5)<br />
writeDigitalPin (ar, led_pin, 1);<br />
pause (0.5)<br />
endwhile<br />
<br />
<br />
== Documentation ==<br />
<br />
Documentation and reference for the Arduino toolkit is available as:<br />
<br />
* The [https://octave.sourceforge.io/arduino/package_doc/index.html Online manual]<br />
<br />
* The [https://octave.sourceforge.io/arduino/overview.html Function Reference]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Instrument_control_package&diff=10472Instrument control package2017-08-10T11:57:08Z<p>Lostbard: /* Compatibility */</p>
<hr />
<div>Instrument-Control is a package for interfacing the outside world of hardware via Serial, i2c or Parallel interfaces. It is currently under development by Andrius Sutas and Stefan Mahr, you can browse the [https://sourceforge.net/p/octave/instrument-control/ci/default/tree/ mercurial repository here] and download the package [http://octave.sourceforge.net/instrument-control/index.html here].<br />
<br />
= Compatibility =<br />
<br />
Below is a table showing package compatibility with various platforms:<br />
<br />
{| class="wikitable" style="text-align:center"<br />
|-<br />
! !! Linux !! Windows (Cygwin) !! Windows (native) !! FreeBSD !! Mac OS X <br />
|-<br />
! Serial<br />
| bgcolor="green" | v0.1.0 || bgcolor="green" | v0.2.0 || bgcolor="green" | v0.2.1 || bgcolor="skyblue" | stalled || bgcolor="green" | v0.2.2<br />
|-<br />
! Parallel<br />
| bgcolor="green" | v0.1.0 || - || - || bgcolor="skyblue" | stalled || -<br />
|-<br />
! i2c<br />
| bgcolor="green" | v0.1.0 || - || - || bgcolor="skyblue" | stalled || - <br />
|-<br />
! TCP<br />
| bgcolor="green" | v0.2.0 || bgcolor="green" | v0.2.0 || bgcolor="green" | v0.2.0 || bgcolor="skyblue" | stalled || bgcolor="green" | v0.2.2<br />
|-<br />
! UDP<br />
| bgcolor="green" | v0.3.0 || bgcolor="green" | v0.3.0 || bgcolor="green" | v0.3.0 || - || bgcolor="green" | v0.3.0<br />
|-<br />
! USBTMC<br />
| bgcolor="green" | v0.2.0 || - || - || - || - <br />
|-<br />
! GPIB<br />
| bgcolor="green" | v0.2.0 [[#Linux|(*)]] || - || - ||- || - <br />
|-<br />
! VXI11<br />
| bgcolor="green" | v0.2.0|| bgcolor="green" | v0.2.0 [[#Windows_.28cygwin.29|(*)]] || - || - || bgcolor="yellow" | WIP [[#MacOS|(*)]]<br />
|}<br />
<br />
Where: <span style="background:green">(VER)</span> - Included since VER version; <span style="background:yellow">(WIP)</span> - Work In Progress and will probably be included in next release; <span style="background:skyblue">(stalled)</span> - Some work has been done, but it's not tested and no one is actively contributing; (-) - Not supported / Untested.<br />
<br />
You might see errors while doing "pkg install", which mean that package is unable to support related interface on your platform (e.g. due to missing header files), therefore one should <b>always</b> check for the supported interfaces before trying to use them:<br />
<br />
{{Code|Check for interface support|<syntaxhighlight lang="octave" style="font-size:13px"><br />
pkg load instrument-control<br />
<br />
if (exist("serial") == 3)<br />
disp("Serial: Supported")<br />
else<br />
disp("Serial: Unsupported")<br />
endif<br />
<br />
#similarly with:<br />
#exist("parallel") == 3<br />
#exist("i2c") == 3<br />
</syntaxhighlight>}}<br />
<br />
= Requirements =<br />
== Linux ==<br />
<br />
For GPIB support, please install [http://linux-gpib.sourceforge.net linux-gpib] before installing instrument-control.<br />
<br />
== Windows (cygwin) ==<br />
<br />
For VXI11 support, please install 'rpcgen', 'libtirpc-devel', and 'libtirpc1' before installing instrument-control.<br />
<br />
== MacOS ==<br />
<br />
You need to build rpcgen from source [http://mirror.ancl.hawaii.edu/pub/FreeBSD/FreeBSD-current/src/usr.bin/rpcgen].<br />
<br />
= Examples =<br />
== Serial ==<br />
=== Configuring interface ===<br />
You might want to configure interface in a loopback mode for testing.<br />
* If you have a Serial adapter, then simply connect pins 3 (Tx) and 2 (Rx) together (assuming your adapter is [http://en.wikipedia.org/wiki/File:DE9_D-subminiature_RS-232_pinout.png RS-232 DE9], otherwise check before doing anything). One can also insert an LED in series to view the actual bitstream.<br />
* If you do not have a Serial adapter then create a virtual port using:<br />
<pre><br />
$ socat PTY,link=/dev/ttyS15 PTY,link=/dev/ttyS16<br />
</pre><br />
<br />
which will open two interconnected interfaces, where one (e.g. /dev/ttyS15) can be opened in Octave and second (e.g. /dev/ttyS16) using something like GNU screen:<br />
<pre><br />
$ screen /dev/ttyS16 <baudrate><br />
</pre><br />
<br />
do not forget to change interface permissions if you want to use them with Octave/screen without root privileges.<br />
<br />
=== Example: basic use ===<br />
Here is a simple example to get started with the serial package. It tests the RxD and TxD lines. Make sure you have defined a loopback or connected the pins of your adapter.<br />
{{Code|Serial port example|<syntaxhighlight lang="octave" style="font-size:13px"><br />
# Opens serial port ttyUSB1 with baudrate of 115200 (config defaults to 8-N-1)<br />
s1 = serial("/dev/ttyUSB1", 115200) <br />
# Flush input and output buffers<br />
srl_flush(s1); <br />
# Blocking write call, currently only accepts strings<br />
srl_write(s1, "Hello world!") <br />
# Blocking read call, returns uint8 array of exactly 12 bytes read<br />
data = srl_read(s1, 12) <br />
# Convert uint8 array to string, <br />
char(data) <br />
</syntaxhighlight><br />
}}<br />
<br />
Chaging some configurations is simple done by calling helper functions<br />
{{Code|Serial port example: helper functions|<syntaxhighlight lang="octave" style="font-size:13px"><br />
set(s1, "baudrate", 9600) # Change baudrate<br />
set(s1, "bytesize", 5) # Change byte size (config becomes 5-N-1)<br />
set(s1, "parity", "E") # Changes parity checking (config becomes 5-E-1),<br />
# possible values [E]ven, [O]dd, [N]one.<br />
set(s1, "stopbits", 2) # Changes stop bits (config becomes 5-E-2), possible<br />
# values 1, 2.<br />
<br />
set(s1, "dataterminalready", "on") # Enables DTR line<br />
set(s1, "requesttosend", "on") # Enables RTS line<br />
# possible values "on", "off". <br />
<br />
</syntaxhighlight><br />
}}<br />
Some properties can be set at opening time<br />
{{Code|Serial port example: constructor call|<syntaxhighlight lang="octave" style="font-size:13px"><br />
s2 = serial("/dev/ttyS0", 9600, 10) # Opens serial port ttyS0 in<br />
# 9600 baudrate with 1s read timeout<br />
</syntaxhighlight><br />
}}<br />
<br />
Do not forget to close the ports when you are done!<br />
{{Code||<syntaxhighlight lang="octave" style="font-size:13px"><br />
fclose(s1) # Closes and releases serial interface object<br />
fclose(s2) # Closes and releases serial interface object<br />
</syntaxhighlight><br />
}}<br />
<br />
=== Example: Windows, serial port >COM9 ===<br />
Opening a serial port higher than COM9 requires special syntax. [https://support.microsoft.com/en-us/kb/115831]<br />
{{Code|open Windows higher serial port example|<syntaxhighlight lang="octave" style="font-size:13px"><br />
# Opens serial port COM10<br />
s1 = serial("\\\\.\\COM10");<br />
</syntaxhighlight><br />
}}<br />
<br />
== Parallel ==<br />
=== Configuring interface ===<br />
You will need to load following modules:<br />
<pre><br />
# modprobe parport<br />
# modprobe ppdev<br />
</pre><br />
<br />
Now you should see devices like "/dev/parport0". In case you do not, you will need to create them manually and give sufficient privileges for your user:<br />
<br />
<pre><br />
# mknod /dev/parport0 c 99 0 -m 666<br />
</pre><br />
<br />
=== Example 1: LED trace ===<br />
For this example you will need to connect 8 LEDs to Parallel interface Data port as shown below:<br />
<br />
[[File:parport_schematic.png|300px|text-bottom]]<br />
<br />
And then the actual script:<br />
{{Code|trace.m|<syntaxhighlight lang="octave" style="font-size:13px"><br />
delay = 0.1;<br />
<br />
pp = parallel("/dev/parport0", 0);<br />
pp_data(pp, 0);<br />
<br />
pins = pow2([0, 1, 2, 3, 4, 5, 6, 7]);<br />
<br />
while 1<br />
for p = pins<br />
pp_data(pp, p);<br />
sleep(delay);<br />
endfor <br />
<br />
# Reverse the order<br />
pins = pins(end:-1:1);<br />
endwhile<br />
<br />
pp_close(pp);<br />
</syntaxhighlight>}}<br />
<br />
Run it and you should see LEDs "tracing" forwards and backwards.<br />
<br />
<br />
=== Example 2: LED dimming a.k.a. PWM control ===<br />
Use the same schematic as in Example 1.<br />
<br />
{{Code|dim.m|<syntaxhighlight lang="octave" style="font-size:13px"><br />
delay = 0.00005;<br />
<br />
pp = parallel("/dev/parport0", 0);<br />
pp_data(pp, 0);<br />
<br />
dRange = 0:100;<br />
while 1<br />
for duty = dRange<br />
pp_data(pp, 255); <br />
<br />
for dOn = 0:duty<br />
sleep(delay);<br />
endfor <br />
<br />
pp_data(pp, 0);<br />
<br />
for dOff = 0:(100-duty)<br />
sleep(delay);<br />
endfor<br />
endfor<br />
<br />
# Reverse order<br />
dRange = dRange(end:-1:1);<br />
endwhile<br />
<br />
pp_close(pp);<br />
</syntaxhighlight>}}<br />
<br />
Run it and you should see LEDs changing brightness from lowest to maximum.<br />
<br />
<br />
=== Example 3: Logic analyzer ===<br />
We can surely make something more interesting, right? Enter basic logic analyzer.<br />
<br />
Assume you are working with [[http://datasheets.maximintegrated.com/en/ds/MAX31855.pdf this]] temperature sensor. Something is not right. You do not have one of those expensive logic analyzers, but you do have a Parallel port! You remember that someone made a package for interfacing it with GNU Octave. So you connect your probes to appropriate Data port terminals and change settings accordingly. In this example: <br />
{| class="wikitable"<br />
|-<br />
! Probe !! Port terminal<br />
|-<br />
| !CS || DATA0<br />
|-<br />
| SCK || DATA1<br />
|-<br />
| SO || DATA2<br />
|}<br />
NB: Parallel ports usually have weak pull-ups to +5V even when in "input" mode, so do not do this if unsure.<br />
One could potentially use different terminals in Control/Status ports to get true high-impedance inputs.<br />
<br />
And write a simple script below:<br />
<br />
{{Code|logic_analyzer.m|<syntaxhighlight lang="octave" style="font-size:13px"><br />
#####################################################################<br />
# Settings<br />
#####################################################################<br />
<br />
# Channels to capture<br />
#channels = [0, 1, 2, 3, 4, 5, 6, 7];<br />
channels = [2, 1, 0];<br />
<br />
# Channel labels<br />
#channel = {"CH0"; "CH1"; "CH2"; "CH3"; "CH4"; "CH5"; "CH6"; "CH7"};<br />
channel = {"SO"; "SCK"; "!CS"};<br />
<br />
# Trigger channel<br />
triggerCh = 0;<br />
<br />
# When to trigger<br />
trigger = 0; # Capture on low. For high - 1<br />
<br />
#####################################################################<br />
<br />
samplesTime = [];<br />
samplesValue = [];<br />
<br />
#pp_close(pp);<br />
pp = parallel("/dev/parport0", 1);<br />
<br />
printf("Waiting for trigger...\n");<br />
fflush(stdout);<br />
<br />
data = pp_data(pp);<br />
while (bitget(data, triggerCh + 1) != trigger)<br />
oldData = data;<br />
data = pp_data(pp);<br />
endwhile<br />
<br />
printf("Capturing...\n");<br />
fflush(stdout);<br />
<br />
startTime = time();<br />
samplesTime(end + 1) = 0;<br />
samplesValue(end + 1) = oldData;<br />
<br />
while (bitget(data, triggerCh + 1) == trigger)<br />
data = pp_data(pp);<br />
samplesTime(end + 1) = time() - startTime;<br />
samplesValue(end + 1) = data;<br />
endwhile<br />
<br />
# Statistics<br />
printf("Average sample rate: %f kHz\n", size(samplesValue)(2) / samplesTime(end) / 1000.0);<br />
<br />
pp_close(pp);<br />
<br />
# Plotting<br />
<br />
figure;<br />
for p = 1:size(channels)(2)<br />
subplot (size(channels)(2), 1, p)<br />
plot(samplesTime, bitget(samplesValue, channels(p) + 1))<br />
<br />
ylabel(channel{p});<br />
axis([-0.01, samplesTime(end)+ 0.01, -1, 2], "manual");<br />
set(gca(), 'ytick', -1:2);<br />
set(gca(), 'yticklabel', {''; '0'; '1'; ''});<br />
endfor<br />
xlabel ("t");<br />
</syntaxhighlight>}}<br />
<br />
If connections and settings are correct you should see something like this:<br />
<br />
[[File:logic_analyzer.png|600px|text-bottom]]<br />
<br />
Now you can fully debug what is going with your hardware from comfort of GNU Octave.<br />
<br />
== i2c ==<br />
i2c<br />
<br />
== TCP ==<br />
=== Example: basic use ===<br />
For testing you could start a tcp listener<br />
<pre><br />
$ socat TCP-LISTEN:8000 -<br />
</pre><br />
<br />
Now you can connect your listener.<br />
<br />
{{Code|TCP example|<syntaxhighlight lang="octave" style="font-size:13px"><br />
# Open TCP connection to 127.0.0.1:8000<br />
t0 = tcp("127.0.0.1",8000)<br />
# write to listener<br />
tcp_write(t0, "Hello world!") <br />
# Blocking read call, returns uint8 array of exactly 12 bytes read<br />
data = tcp_read(t0, 12) <br />
# Convert uint8 array to string, <br />
char(data) <br />
</syntaxhighlight><br />
}}<br />
There are several ways to set timeout of read call.<br />
{{Code|set TCP timeout|<syntaxhighlight lang="octave" style="font-size:13px"><br />
# Open TCP connection to 127.0.0.1:8000 with timeout of 100 ms<br />
t0 = tcp("127.0.0.1",8000,100)<br />
# set timeout to blocking<br />
tcp_timeout(t0, -1) <br />
# the timeout can be overwritten for single read call, in this case 1000ms<br />
data = tcp_read(t0, 12, 1000) <br />
# close tcp session<br />
tcp_close(t0)<br />
</syntaxhighlight><br />
}}<br />
<br />
== USBTMC ==<br />
=== Configuring interface ===<br />
Recent linux kernels support USBTMC out of the box. Connect your instrument and check if /dev/usbtmc* exists. Set appropriate permissions to /dev/usbtmc*<br />
=== Example: basic use ===<br />
{{Code|USBTMC example|<syntaxhighlight lang="octave" style="font-size:13px"><br />
# Open interface to USB instrument<br />
t0 = usbtmc('/dev/usbtmc0')<br />
# write to listener<br />
usbtmc_write(t0, '*IDN?') <br />
# Blocking read call, returns uint8 array<br />
data = usbtmc_read(t0, 10000) <br />
# Convert uint8 array to string, <br />
char(data) <br />
# close usbtmc session<br />
usbtmc_close(t0)<br />
</syntaxhighlight><br />
}}<br />
<br />
== VXI11 ==<br />
=== Example: basic use ===<br />
{{Code|VXI11 example|<syntaxhighlight lang="octave" style="font-size:13px"><br />
# Open VXI11 connection to 192.168.100.100<br />
t0 = vxi11('192.168.100.100')<br />
# write to listener<br />
vxi11_write(t0, '*IDN?') <br />
# read from instrument, returns uint8 array<br />
data = vxi11_read(t0, 10000) <br />
# Convert uint8 array to string, <br />
char(data) <br />
# close usbtmc session<br />
vxi11_close(t0)<br />
</syntaxhighlight><br />
}}<br />
=== Limitations ===<br />
For now,<br />
* it's not possible to connect more than one instrument per IP address (e.g. VXI11-GPIB gateways)<br />
* only instrument ''inst0'' can be connected<br />
* setting timeout is not implemented (defaults: 10 seconds global timeout, 2 seconds read timeout)<br />
<br />
== GPIB ==<br />
=== Configuring interface ===<br />
For using GPIB you need to install and configure the linux-gpib kernel modules and libraries.<br />
=== Example: basic use ===<br />
{{Code|GPIB example|<syntaxhighlight lang="octave" style="font-size:13px"><br />
# Open GPIB instrument with ID 7 and set timeout to 1 second (see ibtmo / NI-488.2 Function Reference)<br />
t0 = gpib(7,11)<br />
# write to listener<br />
gpib_write(t0, '*IDN?') <br />
# read from instrument, returns uint8 array<br />
data = gpib_read(t0, 10000)<br />
# Convert uint8 array to string, <br />
char(data) <br />
# close usbtmc session<br />
gpib_close(t0)<br />
</syntaxhighlight><br />
}}<br />
=== Limitations ===<br />
* Setting minor, sad, send_eoi and eos_mode is not implemented yet.<br />
* Every read or write command opens and closes a new gpib session, since the linux-gpib session pointer is only valid for single command.<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=GNU_Octave_Wiki&diff=10471GNU Octave Wiki2017-08-08T17:28:16Z<p>Lostbard: /* Octave-Forge */</p>
<hr />
<div>[https://www.gnu.org/software/octave/ GNU Octave] is a high-level interpreted language, primarily intended for numerical computations. It provides capabilities for the numerical solution of linear and nonlinear problems, and for performing other numerical experiments. It also provides extensive graphics capabilities for data visualization and manipulation. GNU Octave is normally used through its interactive interface ([https://en.wikipedia.org/wiki/Command-line_interface CLI] and [https://en.wikipedia.org/wiki/Graphical_user_interface GUI]), but it can also be used to write non-interactive programs. The GNU Octave language is quite similar to Matlab so that most programs are easily portable.<br />
<br />
== [[:Category:Installation|Installing]] ==<br />
<br />
* Get installers and sources from http://octave.org/download<br />
** [[Octave_for_MacOS_X#Installing_a_Mac_OS_X_Bundle|Beta installer for macOS]]<br />
** [[Octave for GNU/Linux|GNU/Linux installation instructions]]<br />
** [[Octave_for_Microsoft_Windows|Microsoft Windows installation instructions]]<br />
** [[Octave_and_separate_toolchain|Build Octave using a separate toolchain]] (custom built gcc version)<br />
<br />
{{Note|GNU Octave {{Release}} is the current stable release}}<br />
<br />
Are you using an old version of Octave? Check the [[Release History]] page to see how old it is.<br />
<br />
== News ==<br />
<br />
* '''[[OctConf_2018|OctConf 2018]]''' at CERN<br />
<br />
* {{Release Date}} '''GNU Octave {{Release}}''' has been released (see above)!<br />
<br />
* GNU Octave mentors four students at the [https://summerofcode.withgoogle.com/organizations/6259279704096768/ Google Summer of Code 2017].<br />
<br />
== Getting help with GNU Octave ==<br />
<br />
* Read the [https://www.gnu.org/software/octave/doc/interpreter GNU Octave documentation]<br />
* The [[FAQ|frequently asked questions (FAQ)]] list is good place to start with answers to questions regarding [[FAQ#General|what is Octave]], [[FAQ#Licensing_issues|licensing]], [[FAQ#What.27s_new_in_Octave|new features]], [[FAQ#What_documentation_exists_for_Octave.3F|documentation]], [[FAQ#Installation_issues_and_problems|installation]], [[FAQ#Coding|coding]], [[FAQ#How_can_I_get_involved_in_Octave_development.3F|contributing to Octave]], and more, are found there.<br />
* Continue reading this wiki and feel free to add further content (please check that it is not already part of, or belongs in, the documentation and read the [[Contribution guidelines]]).<br />
* [https://www.gnu.org/software/octave/support.html Other support options]<br />
<br><br />
<br />
__TOC__<br />
<br />
== Advanced topics ==<br />
<br />
Below is a temporary attempt to organize the "most wanted" pages of the Wiki. A list of all pages on the wiki can be seen [[Special:AllPages|here]]. To locate something specific, try the wiki's search box, or prepend {{Codeline|<nowiki>site:wiki.octave.org</nowiki>}} to a [https://www.google.com/search?&q=site%3Awiki.octave.org Google search]. Please read the [[Contribution guidelines]] first, if you want to contribute to this Wiki.<br />
<br />
=== [[:Category:Packages|Packages]] ===<br />
* [[OEP:pkg|Installing packages]]<br />
* [[Creating packages]]<br />
<br />
==== [[Octave-Forge]] ====<br />
<br />
See also the list of Forge Wiki pages: [[:Category:Octave-Forge]]<br />
<br />
* [[bim_package|bim package]] Solve Partial Differential Equations with a Finite Element method<br />
* [[Control_package|Control package]]<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/CGI_programming_with_Octave CGI] Common Gateway Interface for Octave<br />
* [[Dataframe_package|Dataframe package]] cell arrays on steroids<br />
* [[Dicom_package|Dicom package]]<br />
* [[Fem-fenics|fem-fenics]] Interface to [http://fenicsproject.org/ FEnics] FEM library<br />
* [[Geometry_package|Geometry package]]<br />
* [[Image package]]<br />
* [[Image_acquisition_package|Image acquisition package]] Capture images, for example from v4l2 hardware like webcams<br />
* [[Instrument_control__package|Instrument control package]]<br />
* [[Interval_package|Interval package]] Real-valued interval arithmetic<br />
* [[IO_package|I/O package]]<br />
* [[Java_package|Java package]]<br />
* [[Mechanics_package|Mechanics package]]<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/NcArray ncArray] High-level interface of accessing a single or a collection of NetCDF files as a multi-dimensional array<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/Octave-netcdf netcdf] matlab-compatible NetCDF package<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/NetCDF_toolbox_for_Octave octcdf] NetCDF package (old)<br />
* [[ocs_package|OCS package]] Octave Circuit Simulator<br />
* [http://modb.oce.ulg.ac.be/mediawiki/index.php/Optimal_interpolation_Fortran_module_with_Octave_interface optiminterp] Optimal interpolation<br />
* [[Parallel_package|Parallel package]]<br />
* [[Sockets_package|Sockets package]]<br />
* [[Symbolic package|Symbolic package]]<br />
* [[TISEAN_package|TISEAN package]]<br />
* [[Video_package|Video package]]<br />
* [[sci_cosim|Scilab co-simulation package]]<br />
* [[Zeromq_package|Zeromq package]] Zeromq bindings for Octave.<br />
<br />
=== [[:Category:Editors|Editors]] ===<br />
* [[Gedit]]<br />
* [[Emacs]]<br />
* [[Nano]]<br />
* [[Vim]]<br />
* [[Kate]]<br />
* [http://octclipse.sourceforge.net Octclipse] (Windows and GNU/Linux only. The Octclipse developers are seeking individuals to assist with macOS support.)<br />
* [https://sites.google.com/site/domainmathide/ DomainMath IDE] (Windows, GNU/Linux and macOS.)<br />
* [https://bitbucket.org/jgpallero/octave-sh GNU Octave syntax highlight files] (Syntax highlight definitions for some editors. Contributions are welcome)<br />
<br />
=== [[:Category:Resources|Tutorials/Examples]] ===<br />
* [[Using Octave]] - For those just getting started.<br />
* [[Octave Basics]] - A short reference card to get started.<br />
* [https://staff.ti.bfh.ch/sha1/Labs/PWF/Documentation/OctaveAtBFH.pdf Octave introduction script]<br />
* [[Tips and tricks]] - Guidelines to improve your coding skills.<br />
* [[Cookbook]] - Several simple and useful examples.<br />
* [[Octave load]] - Use liboctave functions to load variables from a file in Octave's binary format. <br />
* [[Fortran]] - Accessing liboctave from a Fortran 2003 program.<br />
* [[Octave fun]] - Coding can be fun -- miscellaneous more or less funny scripts<br />
* [[Video tutorials]]<br />
* [[:Category:Plotting tutorials|Plotting tutorials]]<br />
* [http://www.amiq.com/consulting/2014/11/21/how-to-connect-systemverilog-with-octave/ How to Connect SystemVerilog with Octave]<br />
<br />
=== [[:Category:Development|Development]] ===<br />
In addition to these links, there is a longer list of links relevant to (especially novice) developers at the page [[Developers]].<br />
<br />
* [[4.2.0 Release Checklist]]<br />
* [[Bug Fix List - 4.2.0 Release]]<br />
* [[Doxygen]] - C++ code documentation<br />
* [[International Characters Support]] - Using Octave in your own language.<br />
* [[Octave for Microsoft Windows]]<br />
* [[Octave for MacOS X]]<br />
* [[Octave for GNU/Linux]] and [[Octave for other Unix systems|other Unix systems]]<br />
* [[Contribution guidelines]]<br />
<br />
==== [[:Category:Building|Building]] ====<br />
* [[Building]]<br />
* [[Continuous Build]]<br />
* [[Enable large arrays: Build octave such that it can use arrays larger than 2Gb.|Building Octave to use large arrays]]<br />
<br />
==== [[:Category:Testing|Testing]] ====<br />
* [[Tests|Testing source code]]<br />
==== [[:Category:Packaging|Packaging]] ====<br />
* [[Create a MacOS X App Bundle Using MacPorts]]<br />
* [[Windows_Installer|Create a Windows Installer using MXE]]<br />
<br />
=== [[:Category:Academia|Academia]] ===<br />
* [[Publications using Octave]] - A compilation of scientific publications making reference to GNU Octave (add yours!).<br />
<br />
=== [[:Category:Project Ideas|Project Ideas]] ===<br />
* [[Projects]]<br />
* [[Summer of Code Project Ideas]]<br />
<br />
== External Links ==<br />
* [https://www.gnu.org/software/octave/ Octave Homepage]<br />
* [https://octave.sourceforge.io/ Octave Forge]<br />
* [https://savannah.gnu.org/bugs/?group=octave GNU Octave - Bug Tracker]<br />
* [https://savannah.gnu.org/task/?group=octave GNU Octave - Task Tracker]<br />
* [https://savannah.gnu.org/patch/?group=octave GNU Octave - Patch Tracker]<br />
* [https://savannah.gnu.org/hg/?group=octave GNU Octave - Mercurial Repositories]<br />
* [https://planet.octave.org/ Planet Octave] (collection of blog feeds featuring Octave developers and Summer of Code students)</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Dicom_package&diff=10470Dicom package2017-08-08T17:23:26Z<p>Lostbard: /* Platforms */</p>
<hr />
<div>At an early development stage. [http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/extra/dicom/ octave-forge svn]<br />
*Maintainer: Andy Buckle [http://sourceforge.net/sendmessage.php?touser=1760416contact] <br />
*Contributors: Judd Storrs, Kris Thielemans<br />
<br />
Auto-generated docs from the current package: {{Forge|dicom}}<br />
<br />
== What is the aim of this package? ==<br />
Digital communications in medicine (DICOM) is an information standard. Originally created for image transfer, the standard now deals with an large range of medical data. See http://medical.nema.org/ for more info.<br />
<br />
This package provides functions to read and (eventually) write DICOM files. The functions in the package are intended to have similar usage as<br />
the dicom functions in the Matlab Image Processing Toolbox. In Octave they are separate: most image package users will not use dicom, and its dependency might be considered troublesome.<br />
<br />
== Platforms ==<br />
*Linux. Tested on OpenSuSE 11.4 and Ubuntu. No known issues. GDCM is required: see below.<br />
*mingw <br />
**Ben Lindner's Octave 3.2.4 and the mingw build environment (gcc 4.4.0): dicom package 0.1.1 does not build against this older version of the Octave API.<br />
**Tatsuro/Nitzan's Octave 3.4.3 and mingw build environment (gcc 4.5.2): gdcm and dicom package build OK. Get segfault in ntdll.dll when one of the dicom*.oct files calls something from a gdcm*.dll.<br />
**mxe-octave: dicom and gdcm distributed as part of the installed package.<br />
*Cygwin: Panic when oct file called (or maybe when oct file uses gdcm dll). Need to try rebaseall<br />
<br />
==Supporting library==<br />
[http://sourceforge.net/apps/mediawiki/gdcm/index.php?title=Main_Page GDCM]. You can usually get this via your package manager, e.g. on Ubuntu<br />
<br />
sudo apt-get install libgdcm2.0<br />
<br />
Alternatively, build it yourself. Get the source with subversion.<br />
<br />
svn co https://gdcm.svn.sourceforge.net/svnroot/gdcm/branches/gdcm-2-0<br />
<br />
cmake and g++ are required. create a gdcmbin directory parallel to the gdcm-2-0 directory. Change to gdcmbin and then run cmake (Linux/cygwin).<br />
<br />
> mkdir gdcmbin<br />
> ls<br />
gdcmbin gdcm-2-0<br />
> cd gdcmbin<br />
> cmake -DGDCM_BUILD_SHARED_LIBS=ON ../gdcm-2-0/<br />
<br />
This creates a Makefile in your gdcmbin directory. You can easily edit cmake options with "make edit_cache", for example to build applications like gdcmdump. "make help" is also very useful.<br />
<br />
make install<br />
<br />
On my system, I also had to add this to my ~/.bashrc.<br />
<br />
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib<br />
<br />
Mingw32 is similar. Get openSSL: [http://www.slproweb.com/products/Win32OpenSSL.html Win32 Openssl v1.0.0a Light]<br />
<br />
cmake -G "MinGW Makefile" -DGDCM_BUILD_SHARED_LIBS=ON ..\gdcm-2-0<br />
mingw32-make all<br />
<br />
On Cygwin gdcm 2.0.18 (and maybe some other versions) may have a problem with newer cmake. This kludge persuades cmake to define WIN32.<br />
<br />
cmake -DGDCM_BUILD_SHARED_LIBS=ON -DCMAKE_CXX_COMPILER=g++.exe -DCMAKE_LEGACY_CYGWIN_WIN32=1 ../gdcm-2.0.18/<br />
<br />
==Features==<br />
All of these still need work, but they exist, and are usable to some extent.<br />
*dicomdict (load different dict - file follows same format as Matlab's)<br />
*dicominfo (load metadata into octave struct. possible bug in SQ loading)<br />
*dicomlookup (keyword <-> tag)<br />
*dicomread (load pixel data, 2D or 3D int types. Does not yield colormaps, yet.)<br />
*dicomwrite (write pixel data to a DICOM format file)<br />
*dicomuid (generate a DICOM unique id)<br />
*isdicom (verify if a file is a DICOM formatted file)<br />
<br />
==Todo==<br />
<br />
*dicomanon<br />
<br />
==Questions==<br />
I don't have a Matlab license available. I would like to make this package compatible with the dicom functions in Matlab's image processing toolbox, as far as possible.<br />
<br />
*Octave (and Matlab) stores images (y,x) and DICOM is intrinsically (x,y). Does Matlab transpose images when it loads them?<br />
**matlab reads the data from the dicom file as if it's a raw block of numbers (and then converts if necessary). We think that current Octave/dicom behaviour is compatible with matlab. <br />
*I would like people to try m-files that worked with Matlab to let me know of problems.<br />
*(not necessarily) Matlab related: I need examples of odd DICOM files. I have plenty with complex metadata, but I need some with unusual images.<br />
**More than one sample per pixel<br />
**Colour<br />
**Float types <br />
*DA (date) VR: does Matlab turn them into a string?<br />
*if the user supplies metadata (eg HighBit?, BitsStored?) that describe the type of the pixels and this is not in agreement with the type of the image matrix supplied, does Matlab<br />
**silently convert the image pixel type to match the metadata?<br />
**silently convert the metadata to match the pixel type?<br />
**error and do nothing? <br />
<br />
== Answered ==<br />
*dicominfo: Items in sequences are not necessarily the same, so are stored as nested structs like dcm.RTDoseROISequence.Item_1.DoseUnits(as Matlab)<br />
*What does dicominfo do when a tag is not in its dictionary? Answer: assign to a field like Private_3243_0010 (as Matlab)<br />
<br />
== See also ==<br />
* {{Forge|dicom}} at [[Octave Forge]].<br />
* [http://sourceforge.net/projects/gdcm/ Grassroots DICOM].<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Dicom_package&diff=10469Dicom package2017-08-08T17:21:00Z<p>Lostbard: /* Todo */</p>
<hr />
<div>At an early development stage. [http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/extra/dicom/ octave-forge svn]<br />
*Maintainer: Andy Buckle [http://sourceforge.net/sendmessage.php?touser=1760416contact] <br />
*Contributors: Judd Storrs, Kris Thielemans<br />
<br />
Auto-generated docs from the current package: {{Forge|dicom}}<br />
<br />
== What is the aim of this package? ==<br />
Digital communications in medicine (DICOM) is an information standard. Originally created for image transfer, the standard now deals with an large range of medical data. See http://medical.nema.org/ for more info.<br />
<br />
This package provides functions to read and (eventually) write DICOM files. The functions in the package are intended to have similar usage as<br />
the dicom functions in the Matlab Image Processing Toolbox. In Octave they are separate: most image package users will not use dicom, and its dependency might be considered troublesome.<br />
<br />
== Platforms ==<br />
*Linux. Tested on OpenSuSE 11.4 and Ubuntu. No known issues. GDCM is required: see below.<br />
*mingw <br />
**Ben Lindner's Octave 3.2.4 and the mingw build environment (gcc 4.4.0): dicom package 0.1.1 does not build against this older version of the Octave API.<br />
**Tatsuro/Nitzan's Octave 3.4.3 and mingw build environment (gcc 4.5.2): gdcm and dicom package build OK. Get segfault in ntdll.dll when one of the dicom*.oct files calls something from a gdcm*.dll.<br />
*Cygwin: Panic when oct file called (or maybe when oct file uses gdcm dll). Need to try rebaseall<br />
<br />
==Supporting library==<br />
[http://sourceforge.net/apps/mediawiki/gdcm/index.php?title=Main_Page GDCM]. You can usually get this via your package manager, e.g. on Ubuntu<br />
<br />
sudo apt-get install libgdcm2.0<br />
<br />
Alternatively, build it yourself. Get the source with subversion.<br />
<br />
svn co https://gdcm.svn.sourceforge.net/svnroot/gdcm/branches/gdcm-2-0<br />
<br />
cmake and g++ are required. create a gdcmbin directory parallel to the gdcm-2-0 directory. Change to gdcmbin and then run cmake (Linux/cygwin).<br />
<br />
> mkdir gdcmbin<br />
> ls<br />
gdcmbin gdcm-2-0<br />
> cd gdcmbin<br />
> cmake -DGDCM_BUILD_SHARED_LIBS=ON ../gdcm-2-0/<br />
<br />
This creates a Makefile in your gdcmbin directory. You can easily edit cmake options with "make edit_cache", for example to build applications like gdcmdump. "make help" is also very useful.<br />
<br />
make install<br />
<br />
On my system, I also had to add this to my ~/.bashrc.<br />
<br />
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib<br />
<br />
Mingw32 is similar. Get openSSL: [http://www.slproweb.com/products/Win32OpenSSL.html Win32 Openssl v1.0.0a Light]<br />
<br />
cmake -G "MinGW Makefile" -DGDCM_BUILD_SHARED_LIBS=ON ..\gdcm-2-0<br />
mingw32-make all<br />
<br />
On Cygwin gdcm 2.0.18 (and maybe some other versions) may have a problem with newer cmake. This kludge persuades cmake to define WIN32.<br />
<br />
cmake -DGDCM_BUILD_SHARED_LIBS=ON -DCMAKE_CXX_COMPILER=g++.exe -DCMAKE_LEGACY_CYGWIN_WIN32=1 ../gdcm-2.0.18/<br />
<br />
==Features==<br />
All of these still need work, but they exist, and are usable to some extent.<br />
*dicomdict (load different dict - file follows same format as Matlab's)<br />
*dicominfo (load metadata into octave struct. possible bug in SQ loading)<br />
*dicomlookup (keyword <-> tag)<br />
*dicomread (load pixel data, 2D or 3D int types. Does not yield colormaps, yet.)<br />
*dicomwrite (write pixel data to a DICOM format file)<br />
*dicomuid (generate a DICOM unique id)<br />
*isdicom (verify if a file is a DICOM formatted file)<br />
<br />
==Todo==<br />
<br />
*dicomanon<br />
<br />
==Questions==<br />
I don't have a Matlab license available. I would like to make this package compatible with the dicom functions in Matlab's image processing toolbox, as far as possible.<br />
<br />
*Octave (and Matlab) stores images (y,x) and DICOM is intrinsically (x,y). Does Matlab transpose images when it loads them?<br />
**matlab reads the data from the dicom file as if it's a raw block of numbers (and then converts if necessary). We think that current Octave/dicom behaviour is compatible with matlab. <br />
*I would like people to try m-files that worked with Matlab to let me know of problems.<br />
*(not necessarily) Matlab related: I need examples of odd DICOM files. I have plenty with complex metadata, but I need some with unusual images.<br />
**More than one sample per pixel<br />
**Colour<br />
**Float types <br />
*DA (date) VR: does Matlab turn them into a string?<br />
*if the user supplies metadata (eg HighBit?, BitsStored?) that describe the type of the pixels and this is not in agreement with the type of the image matrix supplied, does Matlab<br />
**silently convert the image pixel type to match the metadata?<br />
**silently convert the metadata to match the pixel type?<br />
**error and do nothing? <br />
<br />
== Answered ==<br />
*dicominfo: Items in sequences are not necessarily the same, so are stored as nested structs like dcm.RTDoseROISequence.Item_1.DoseUnits(as Matlab)<br />
*What does dicominfo do when a tag is not in its dictionary? Answer: assign to a field like Private_3243_0010 (as Matlab)<br />
<br />
== See also ==<br />
* {{Forge|dicom}} at [[Octave Forge]].<br />
* [http://sourceforge.net/projects/gdcm/ Grassroots DICOM].<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Dicom_package&diff=10468Dicom package2017-08-08T17:20:39Z<p>Lostbard: /* Features */</p>
<hr />
<div>At an early development stage. [http://octave.svn.sourceforge.net/viewvc/octave/trunk/octave-forge/extra/dicom/ octave-forge svn]<br />
*Maintainer: Andy Buckle [http://sourceforge.net/sendmessage.php?touser=1760416contact] <br />
*Contributors: Judd Storrs, Kris Thielemans<br />
<br />
Auto-generated docs from the current package: {{Forge|dicom}}<br />
<br />
== What is the aim of this package? ==<br />
Digital communications in medicine (DICOM) is an information standard. Originally created for image transfer, the standard now deals with an large range of medical data. See http://medical.nema.org/ for more info.<br />
<br />
This package provides functions to read and (eventually) write DICOM files. The functions in the package are intended to have similar usage as<br />
the dicom functions in the Matlab Image Processing Toolbox. In Octave they are separate: most image package users will not use dicom, and its dependency might be considered troublesome.<br />
<br />
== Platforms ==<br />
*Linux. Tested on OpenSuSE 11.4 and Ubuntu. No known issues. GDCM is required: see below.<br />
*mingw <br />
**Ben Lindner's Octave 3.2.4 and the mingw build environment (gcc 4.4.0): dicom package 0.1.1 does not build against this older version of the Octave API.<br />
**Tatsuro/Nitzan's Octave 3.4.3 and mingw build environment (gcc 4.5.2): gdcm and dicom package build OK. Get segfault in ntdll.dll when one of the dicom*.oct files calls something from a gdcm*.dll.<br />
*Cygwin: Panic when oct file called (or maybe when oct file uses gdcm dll). Need to try rebaseall<br />
<br />
==Supporting library==<br />
[http://sourceforge.net/apps/mediawiki/gdcm/index.php?title=Main_Page GDCM]. You can usually get this via your package manager, e.g. on Ubuntu<br />
<br />
sudo apt-get install libgdcm2.0<br />
<br />
Alternatively, build it yourself. Get the source with subversion.<br />
<br />
svn co https://gdcm.svn.sourceforge.net/svnroot/gdcm/branches/gdcm-2-0<br />
<br />
cmake and g++ are required. create a gdcmbin directory parallel to the gdcm-2-0 directory. Change to gdcmbin and then run cmake (Linux/cygwin).<br />
<br />
> mkdir gdcmbin<br />
> ls<br />
gdcmbin gdcm-2-0<br />
> cd gdcmbin<br />
> cmake -DGDCM_BUILD_SHARED_LIBS=ON ../gdcm-2-0/<br />
<br />
This creates a Makefile in your gdcmbin directory. You can easily edit cmake options with "make edit_cache", for example to build applications like gdcmdump. "make help" is also very useful.<br />
<br />
make install<br />
<br />
On my system, I also had to add this to my ~/.bashrc.<br />
<br />
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib<br />
<br />
Mingw32 is similar. Get openSSL: [http://www.slproweb.com/products/Win32OpenSSL.html Win32 Openssl v1.0.0a Light]<br />
<br />
cmake -G "MinGW Makefile" -DGDCM_BUILD_SHARED_LIBS=ON ..\gdcm-2-0<br />
mingw32-make all<br />
<br />
On Cygwin gdcm 2.0.18 (and maybe some other versions) may have a problem with newer cmake. This kludge persuades cmake to define WIN32.<br />
<br />
cmake -DGDCM_BUILD_SHARED_LIBS=ON -DCMAKE_CXX_COMPILER=g++.exe -DCMAKE_LEGACY_CYGWIN_WIN32=1 ../gdcm-2.0.18/<br />
<br />
==Features==<br />
All of these still need work, but they exist, and are usable to some extent.<br />
*dicomdict (load different dict - file follows same format as Matlab's)<br />
*dicominfo (load metadata into octave struct. possible bug in SQ loading)<br />
*dicomlookup (keyword <-> tag)<br />
*dicomread (load pixel data, 2D or 3D int types. Does not yield colormaps, yet.)<br />
*dicomwrite (write pixel data to a DICOM format file)<br />
*dicomuid (generate a DICOM unique id)<br />
*isdicom (verify if a file is a DICOM formatted file)<br />
<br />
==Todo==<br />
<br />
*dicomanon<br />
*dicomuid<br />
*dicomwrite<br />
*isdicom<br />
<br />
==Questions==<br />
I don't have a Matlab license available. I would like to make this package compatible with the dicom functions in Matlab's image processing toolbox, as far as possible.<br />
<br />
*Octave (and Matlab) stores images (y,x) and DICOM is intrinsically (x,y). Does Matlab transpose images when it loads them?<br />
**matlab reads the data from the dicom file as if it's a raw block of numbers (and then converts if necessary). We think that current Octave/dicom behaviour is compatible with matlab. <br />
*I would like people to try m-files that worked with Matlab to let me know of problems.<br />
*(not necessarily) Matlab related: I need examples of odd DICOM files. I have plenty with complex metadata, but I need some with unusual images.<br />
**More than one sample per pixel<br />
**Colour<br />
**Float types <br />
*DA (date) VR: does Matlab turn them into a string?<br />
*if the user supplies metadata (eg HighBit?, BitsStored?) that describe the type of the pixels and this is not in agreement with the type of the image matrix supplied, does Matlab<br />
**silently convert the image pixel type to match the metadata?<br />
**silently convert the metadata to match the pixel type?<br />
**error and do nothing? <br />
<br />
== Answered ==<br />
*dicominfo: Items in sequences are not necessarily the same, so are stored as nested structs like dcm.RTDoseROISequence.Item_1.DoseUnits(as Matlab)<br />
*What does dicominfo do when a tag is not in its dictionary? Answer: assign to a field like Private_3243_0010 (as Matlab)<br />
<br />
== See also ==<br />
* {{Forge|dicom}} at [[Octave Forge]].<br />
* [http://sourceforge.net/projects/gdcm/ Grassroots DICOM].<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Zeromq_package&diff=8260Zeromq package2016-03-05T16:17:06Z<p>Lostbard: /* basic publish subscribe pattern */</p>
<hr />
<div>The {{Forge|zeromq}} package is part of the [[Octave Forge]] project and provides Octave bindings to the ZeroMQ library.<br />
<br />
= Installation =<br />
<br />
== package requirements ==<br />
<br />
The {{Forge|zeromq}} package requires the [http://zeromq.org/ ZeroMQ] libraries and include files to be installed in order to compile.<br />
<br />
for fedora: yum install zeromq-devel<br />
<br />
for ubuntu: apt install libzmq-dev<br />
<br />
== octave installation ==<br />
<br />
With the [http://zeromq.org/ ZeroMQ] library installed, from octave commmand line:<br />
<br />
>> pkg install -forge zeromq<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load zeromq<br />
<br />
Look at the quick reference for the package:<br />
<br />
>> help zeromq<br />
<br />
== Differences between C and Octave bindings ==<br />
<br />
The Octave binding is a subset of the C binding of the ZeroMQ library.<br />
<br />
Major differences are:<br />
<br />
1. The octave binding creates a single zeromq context that is used for all zeromq sockets. In the C bindings, the programmer must create a context and use it during socket creation.<br />
<br />
2. only limited zmq_getsockopt and zmq_setsockopt is currently implemented.<br />
<br />
3. functions mostly return true or false for whether they succeeded or failed. In the C binding, 0 signified success.<br />
<br />
== The functions ==<br />
<br />
zmq_bind<br />
Bind a zeromq socket to a endpoint.<br />
<br />
zmq_close<br />
Close a zeromq socket.<br />
<br />
zmq_connect<br />
Connect a zeromq socket to a endpoint<br />
<br />
zmq_errno<br />
Get system errno value.<br />
<br />
zmq_getsockopt<br />
Get current value of a zeromq socket option.<br />
<br />
zmq_poll<br />
Poll a socket or sockets for a timeout or incoming data<br />
available.<br />
<br />
zmq_recv<br />
Attempt to read data from a zeromq socket.<br />
<br />
zmq_send<br />
Attempt to send data from a zeromq socket.<br />
<br />
zmq_setsockopt<br />
Set a zeromq socket option.<br />
<br />
zmq_strerror<br />
Get the last zmq error string.<br />
<br />
zmq_unbind<br />
Unbind a previously bound zeromq socket.<br />
<br />
zmq_version<br />
Get the zeromq library version numbers.<br />
<br />
= Examples =<br />
<br />
The zeromq package comes with a number of examples included in it. They can be opened in octave using:<br />
<br />
>> edit examples/zmq_example1.m<br />
<br />
<br />
== basic request/reply pattern ==<br />
<br />
Example based on client/server example from [http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive]<br />
<br />
The client sends a "Hello" to the server which responds back "World". No error checking or data validation is done in the example.<br />
<br />
{{Code|Server code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
printf ("Creating hello world server...\n");<br />
<br />
% create reply socket, and bind it to port 5555<br />
sock = zmq_socket (ZMQ_REP);<br />
<br />
zmq_bind (sock, "tcp://*:5555");<br />
<br />
printf ("Waiting for clients ...\n");<br />
<br />
% loop forever, waiting for client requests and responding back <br />
while (true)<br />
recievedata = zmq_recv (sock, 10, 0);<br />
printf ("Received Hello\n");<br />
zmq_send (sock, "World", 5, 0);<br />
endwhile<br />
</syntaxhighlight>}}<br />
<br />
{{Code|Client code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
printf ("Connecting to hello world server...\n");<br />
<br />
<br />
% Create socket and connect to server<br />
<br />
sock = zmq_socket (ZMQ_REQ);<br />
zmq_connect (sock, "tcp://localhost:5555");<br />
<br />
for request_nbr = [1:10]<br />
printf ("Sending Hello %d...\n", request_nbr);<br />
<br />
zmq_send (sock, uint8("Hello"), 5, 0);<br />
<br />
% try to read up to 10 bytes of reply data.<br />
printf ("Waiting for server response %d... (Ctrl-C to exit)\n", request_nbr); <br />
<br />
recieved = zmq_recv (sock, 10, 0);<br />
printf ("Received World %d\n", request_nbr);<br />
endfor<br />
<br />
zmq_close (sock);<br />
</syntaxhighlight>}}<br />
<br />
== basic publish/subscribe pattern ==<br />
<br />
Example based on client/server example from [http://zguide.zeromq.org/page:all#Getting-the-Message-Out http://zguide.zeromq.org/page:all#Getting-the-Message-Out]<br />
<br />
The server pushes 'weather updates' for random zipcodes. The client subscribes to the server just for zipcode 10001.<br />
<br />
{{Code|Server code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
publisher = zmq_socket (ZMQ_PUB);<br />
<br />
rc = zmq_bind (publisher, "tcp://*:5556");<br />
assert (rc);<br />
<br />
while (true) <br />
% Get values that will fool the boss<br />
zipcode = 10000 + randi (20);<br />
temperature = randi (215) - 80;<br />
relhumidity = randi (50) + 10;<br />
<br />
% Send message to all subscribers<br />
update = sprintf ("%05d %d %d", zipcode, temperature, relhumidity);<br />
<br />
zmq_send (publisher, update);<br />
endwhile<br />
<br />
zmq_close (publisher);<br />
</syntaxhighlight>}}<br />
<br />
{{Code|Client code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
subscriber = zmq_socket (ZMQ_SUB);<br />
rc = zmq_connect (subscriber, "tcp://localhost:5556");<br />
assert (rc);<br />
<br />
% Subscribe to zipcode, default is NYC, 10001<br />
zipfilter = "10001 ";<br />
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, zipfilter);<br />
assert (rc);<br />
<br />
% Process 100 updates<br />
update_nbr = 0;<br />
total_temp = 0;<br />
<br />
for update_nbr = 1:100<br />
string = char( zmq_recv(subscriber, 128) );<br />
<br />
[zipcode, temperature, relhumidity, count, errmsg] = sscanf (string, "%d %d %d", "C");<br />
<br />
fprintf ("recieved a temp for zipcode '%s' of %dF\n", ...<br />
zipfilter, temperature);<br />
<br />
total_temp += temperature;<br />
endfor<br />
<br />
fprintf ("Average temperature for zipcode '%s' was %dF\n", ...<br />
zipfilter, (total_temp / update_nbr));<br />
<br />
zmq_close (subscriber);<br />
</syntaxhighlight>}}<br />
<br />
<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Zeromq_package&diff=8259Zeromq package2016-03-05T16:15:11Z<p>Lostbard: /* Examples */</p>
<hr />
<div>The {{Forge|zeromq}} package is part of the [[Octave Forge]] project and provides Octave bindings to the ZeroMQ library.<br />
<br />
= Installation =<br />
<br />
== package requirements ==<br />
<br />
The {{Forge|zeromq}} package requires the [http://zeromq.org/ ZeroMQ] libraries and include files to be installed in order to compile.<br />
<br />
for fedora: yum install zeromq-devel<br />
<br />
for ubuntu: apt install libzmq-dev<br />
<br />
== octave installation ==<br />
<br />
With the [http://zeromq.org/ ZeroMQ] library installed, from octave commmand line:<br />
<br />
>> pkg install -forge zeromq<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load zeromq<br />
<br />
Look at the quick reference for the package:<br />
<br />
>> help zeromq<br />
<br />
== Differences between C and Octave bindings ==<br />
<br />
The Octave binding is a subset of the C binding of the ZeroMQ library.<br />
<br />
Major differences are:<br />
<br />
1. The octave binding creates a single zeromq context that is used for all zeromq sockets. In the C bindings, the programmer must create a context and use it during socket creation.<br />
<br />
2. only limited zmq_getsockopt and zmq_setsockopt is currently implemented.<br />
<br />
3. functions mostly return true or false for whether they succeeded or failed. In the C binding, 0 signified success.<br />
<br />
== The functions ==<br />
<br />
zmq_bind<br />
Bind a zeromq socket to a endpoint.<br />
<br />
zmq_close<br />
Close a zeromq socket.<br />
<br />
zmq_connect<br />
Connect a zeromq socket to a endpoint<br />
<br />
zmq_errno<br />
Get system errno value.<br />
<br />
zmq_getsockopt<br />
Get current value of a zeromq socket option.<br />
<br />
zmq_poll<br />
Poll a socket or sockets for a timeout or incoming data<br />
available.<br />
<br />
zmq_recv<br />
Attempt to read data from a zeromq socket.<br />
<br />
zmq_send<br />
Attempt to send data from a zeromq socket.<br />
<br />
zmq_setsockopt<br />
Set a zeromq socket option.<br />
<br />
zmq_strerror<br />
Get the last zmq error string.<br />
<br />
zmq_unbind<br />
Unbind a previously bound zeromq socket.<br />
<br />
zmq_version<br />
Get the zeromq library version numbers.<br />
<br />
= Examples =<br />
<br />
The zeromq package comes with a number of examples included in it. They can be opened in octave using:<br />
<br />
>> edit examples/zmq_example1.m<br />
<br />
<br />
== basic request/reply pattern ==<br />
<br />
Example based on client/server example from [http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive]<br />
<br />
The client sends a "Hello" to the server which responds back "World". No error checking or data validation is done in the example.<br />
<br />
{{Code|Server code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
printf ("Creating hello world server...\n");<br />
<br />
% create reply socket, and bind it to port 5555<br />
sock = zmq_socket (ZMQ_REP);<br />
<br />
zmq_bind (sock, "tcp://*:5555");<br />
<br />
printf ("Waiting for clients ...\n");<br />
<br />
% loop forever, waiting for client requests and responding back <br />
while (true)<br />
recievedata = zmq_recv (sock, 10, 0);<br />
printf ("Received Hello\n");<br />
zmq_send (sock, "World", 5, 0);<br />
endwhile<br />
</syntaxhighlight>}}<br />
<br />
{{Code|Client code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
printf ("Connecting to hello world server...\n");<br />
<br />
<br />
% Create socket and connect to server<br />
<br />
sock = zmq_socket (ZMQ_REQ);<br />
zmq_connect (sock, "tcp://localhost:5555");<br />
<br />
for request_nbr = [1:10]<br />
printf ("Sending Hello %d...\n", request_nbr);<br />
<br />
zmq_send (sock, uint8("Hello"), 5, 0);<br />
<br />
% try to read up to 10 bytes of reply data.<br />
printf ("Waiting for server response %d... (Ctrl-C to exit)\n", request_nbr); <br />
<br />
recieved = zmq_recv (sock, 10, 0);<br />
printf ("Received World %d\n", request_nbr);<br />
endfor<br />
<br />
zmq_close (sock);<br />
</syntaxhighlight>}}<br />
<br />
== basic publish subscribe pattern ==<br />
<br />
Example based on client/server example from [http://zguide.zeromq.org/page:all#Getting-the-Message-Out http://zguide.zeromq.org/page:all#Getting-the-Message-Out]<br />
<br />
The server pushes 'weather updates' for random zipcodes. The client subscribes to the server just for zipcode 10001.<br />
<br />
{{Code|Server code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
publisher = zmq_socket (ZMQ_PUB);<br />
<br />
rc = zmq_bind (publisher, "tcp://*:5556");<br />
assert (rc);<br />
<br />
while (true) <br />
% Get values that will fool the boss<br />
zipcode = 10000 + randi (20);<br />
temperature = randi (215) - 80;<br />
relhumidity = randi (50) + 10;<br />
<br />
% Send message to all subscribers<br />
update = sprintf ("%05d %d %d", zipcode, temperature, relhumidity);<br />
<br />
zmq_send (publisher, update);<br />
endwhile<br />
<br />
zmq_close (publisher);<br />
</syntaxhighlight>}}<br />
<br />
{{Code|Client code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
subscriber = zmq_socket (ZMQ_SUB);<br />
rc = zmq_connect (subscriber, "tcp://localhost:5556");<br />
assert (rc);<br />
<br />
% Subscribe to zipcode, default is NYC, 10001<br />
zipfilter = "10001 ";<br />
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, zipfilter);<br />
assert (rc);<br />
<br />
% Process 100 updates<br />
update_nbr = 0;<br />
total_temp = 0;<br />
<br />
for update_nbr = 1:100<br />
string = char( zmq_recv(subscriber, 128) );<br />
<br />
[zipcode, temperature, relhumidity, count, errmsg] = sscanf (string, "%d %d %d", "C");<br />
<br />
fprintf ("recieved a temp for zipcode '%s' of %dF\n", ...<br />
zipfilter, temperature);<br />
<br />
total_temp += temperature;<br />
endfor<br />
<br />
fprintf ("Average temperature for zipcode '%s' was %dF\n", ...<br />
zipfilter, (total_temp / update_nbr));<br />
<br />
zmq_close (subscriber);<br />
</syntaxhighlight>}}<br />
<br />
<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Zeromq_package&diff=8251Zeromq package2016-03-05T12:28:38Z<p>Lostbard: /* Differences between C and Octave bindings */</p>
<hr />
<div>The {{Forge|zeromq}} package is part of the [[Octave Forge]] project and provides Octave bindings to the ZeroMQ library.<br />
<br />
= Installation =<br />
<br />
== package requirements ==<br />
<br />
The {{Forge|zeromq}} package requires the [http://zeromq.org/ ZeroMQ] libraries and include files to be installed in order to compile.<br />
<br />
for fedora: yum install zeromq-devel<br />
<br />
for ubuntu: apt install libzmq-dev<br />
<br />
== octave installation ==<br />
<br />
With the [http://zeromq.org/ ZeroMQ] library installed, from octave commmand line:<br />
<br />
>> pkg install -forge zeromq<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load zeromq<br />
<br />
Look at the quick reference for the package:<br />
<br />
>> help zeromq<br />
<br />
== Differences between C and Octave bindings ==<br />
<br />
The Octave binding is a subset of the C binding of the ZeroMQ library.<br />
<br />
Major differences are:<br />
<br />
1. The octave binding creates a single zeromq context that is used for all zeromq sockets. In the C bindings, the programmer must create a context and use it during socket creation.<br />
<br />
2. only limited zmq_getsockopt and zmq_setsockopt is currently implemented.<br />
<br />
3. functions mostly return true or false for whether they succeeded or failed. In the C binding, 0 signified success.<br />
<br />
== The functions ==<br />
<br />
zmq_bind<br />
Bind a zeromq socket to a endpoint.<br />
<br />
zmq_close<br />
Close a zeromq socket.<br />
<br />
zmq_connect<br />
Connect a zeromq socket to a endpoint<br />
<br />
zmq_errno<br />
Get system errno value.<br />
<br />
zmq_getsockopt<br />
Get current value of a zeromq socket option.<br />
<br />
zmq_poll<br />
Poll a socket or sockets for a timeout or incoming data<br />
available.<br />
<br />
zmq_recv<br />
Attempt to read data from a zeromq socket.<br />
<br />
zmq_send<br />
Attempt to send data from a zeromq socket.<br />
<br />
zmq_setsockopt<br />
Set a zeromq socket option.<br />
<br />
zmq_strerror<br />
Get the last zmq error string.<br />
<br />
zmq_unbind<br />
Unbind a previously bound zeromq socket.<br />
<br />
zmq_version<br />
Get the zeromq library version numbers.<br />
<br />
= Examples =<br />
<br />
== basic request/reply pattern ==<br />
<br />
Example based on client/server example from [http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive]<br />
<br />
The client sends a "Hello" to the server which responds back "World". No error checking or data validation is done in the example.<br />
<br />
{{Code|Server code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
printf ("Creating hello world server...\n");<br />
<br />
% create reply socket, and bind it to port 5555<br />
sock = zmq_socket (ZMQ_REP);<br />
<br />
zmq_bind (sock, "tcp://*:5555");<br />
<br />
printf ("Waiting for clients ...\n");<br />
<br />
% loop forever, waiting for client requests and responding back <br />
while (true)<br />
recievedata = zmq_recv (sock, 10, 0);<br />
printf ("Received Hello\n");<br />
zmq_send (sock, "World", 5, 0);<br />
endwhile<br />
</syntaxhighlight>}}<br />
<br />
{{Code|Client code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
printf ("Connecting to hello world server...\n");<br />
<br />
<br />
% Create socket and connect to server<br />
<br />
sock = zmq_socket (ZMQ_REQ);<br />
zmq_connect (sock, "tcp://localhost:5555");<br />
<br />
for request_nbr = [1:10]<br />
printf ("Sending Hello %d...\n", request_nbr);<br />
<br />
zmq_send (sock, uint8("Hello"), 5, 0);<br />
<br />
% try to read up to 10 bytes of reply data.<br />
printf ("Waiting for server response %d... (Ctrl-C to exit)\n", request_nbr); <br />
<br />
recieved = zmq_recv (sock, 10, 0);<br />
printf ("Received World %d\n", request_nbr);<br />
endfor<br />
<br />
zmq_close (sock);<br />
</syntaxhighlight>}}<br />
<br />
== basic publish subscribe pattern ==<br />
<br />
Example based on client/server example from [http://zguide.zeromq.org/page:all#Getting-the-Message-Out http://zguide.zeromq.org/page:all#Getting-the-Message-Out]<br />
<br />
The server pushes 'weather updates' for random zipcodes. The client subscribes to the server just for zipcode 10001.<br />
<br />
{{Code|Server code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
publisher = zmq_socket (ZMQ_PUB);<br />
<br />
rc = zmq_bind (publisher, "tcp://*:5556");<br />
assert (rc);<br />
<br />
while (true) <br />
% Get values that will fool the boss<br />
zipcode = 10000 + randi (20);<br />
temperature = randi (215) - 80;<br />
relhumidity = randi (50) + 10;<br />
<br />
% Send message to all subscribers<br />
update = sprintf ("%05d %d %d", zipcode, temperature, relhumidity);<br />
<br />
zmq_send (publisher, update);<br />
endwhile<br />
<br />
zmq_close (publisher);<br />
</syntaxhighlight>}}<br />
<br />
{{Code|Client code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
subscriber = zmq_socket (ZMQ_SUB);<br />
rc = zmq_connect (subscriber, "tcp://localhost:5556");<br />
assert (rc);<br />
<br />
% Subscribe to zipcode, default is NYC, 10001<br />
zipfilter = "10001 ";<br />
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, zipfilter);<br />
assert (rc);<br />
<br />
% Process 100 updates<br />
update_nbr = 0;<br />
total_temp = 0;<br />
<br />
for update_nbr = 1:100<br />
string = char( zmq_recv(subscriber, 128) );<br />
<br />
[zipcode, temperature, relhumidity, count, errmsg] = sscanf (string, "%d %d %d", "C");<br />
<br />
fprintf ("recieved a temp for zipcode '%s' of %dF\n", ...<br />
zipfilter, temperature);<br />
<br />
total_temp += temperature;<br />
endfor<br />
<br />
fprintf ("Average temperature for zipcode '%s' was %dF\n", ...<br />
zipfilter, (total_temp / update_nbr));<br />
<br />
zmq_close (subscriber);<br />
</syntaxhighlight>}}<br />
<br />
<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Zeromq_package&diff=8245Zeromq package2016-03-05T04:23:51Z<p>Lostbard: </p>
<hr />
<div>The {{Forge|zeromq}} package is part of the [[Octave Forge]] project and provides Octave bindings to the ZeroMQ library.<br />
<br />
= Installation =<br />
<br />
== package requirements ==<br />
<br />
The {{Forge|zeromq}} package requires the [http://zeromq.org/ ZeroMQ] libraries and include files to be installed in order to compile.<br />
<br />
for fedora: yum install zeromq-devel<br />
<br />
for ubuntu: apt install libzmq-dev<br />
<br />
== octave installation ==<br />
<br />
With the [http://zeromq.org/ ZeroMQ] library installed, from octave commmand line:<br />
<br />
>> pkg install -forge zeromq<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load zeromq<br />
<br />
Look at the quick reference for the package:<br />
<br />
>> help zeromq<br />
<br />
== Differences between C and Octave bindings ==<br />
<br />
The Octave binding is a subset of the C binding of the ZeroMQ library.<br />
<br />
Major differences are:<br />
<br />
1. The octave binding creates a single zeromq context that is used for all zeromq sockets. In the C bindings, the programmer must create a context and use it during socket creation.<br />
<br />
2. only limited zmq_getsockopt and zmq_setsockopt is currently implemented.<br />
<br />
3. functions mostly return true or false for whether they succeeded or failed. In the C binding, 0 signififed success.<br />
<br />
== The functions ==<br />
<br />
zmq_bind<br />
Bind a zeromq socket to a endpoint.<br />
<br />
zmq_close<br />
Close a zeromq socket.<br />
<br />
zmq_connect<br />
Connect a zeromq socket to a endpoint<br />
<br />
zmq_errno<br />
Get system errno value.<br />
<br />
zmq_getsockopt<br />
Get current value of a zeromq socket option.<br />
<br />
zmq_poll<br />
Poll a socket or sockets for a timeout or incoming data<br />
available.<br />
<br />
zmq_recv<br />
Attempt to read data from a zeromq socket.<br />
<br />
zmq_send<br />
Attempt to send data from a zeromq socket.<br />
<br />
zmq_setsockopt<br />
Set a zeromq socket option.<br />
<br />
zmq_strerror<br />
Get the last zmq error string.<br />
<br />
zmq_unbind<br />
Unbind a previously bound zeromq socket.<br />
<br />
zmq_version<br />
Get the zeromq library version numbers.<br />
<br />
= Examples =<br />
<br />
== basic request/reply pattern ==<br />
<br />
Example based on client/server example from [http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive]<br />
<br />
The client sends a "Hello" to the server which responds back "World". No error checking or data validation is done in the example.<br />
<br />
{{Code|Server code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
printf ("Creating hello world server...\n");<br />
<br />
% create reply socket, and bind it to port 5555<br />
sock = zmq_socket (ZMQ_REP);<br />
<br />
zmq_bind (sock, "tcp://*:5555");<br />
<br />
printf ("Waiting for clients ...\n");<br />
<br />
% loop forever, waiting for client requests and responding back <br />
while (true)<br />
recievedata = zmq_recv (sock, 10, 0);<br />
printf ("Received Hello\n");<br />
zmq_send (sock, "World", 5, 0);<br />
endwhile<br />
</syntaxhighlight>}}<br />
<br />
{{Code|Client code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
printf ("Connecting to hello world server...\n");<br />
<br />
<br />
% Create socket and connect to server<br />
<br />
sock = zmq_socket (ZMQ_REQ);<br />
zmq_connect (sock, "tcp://localhost:5555");<br />
<br />
for request_nbr = [1:10]<br />
printf ("Sending Hello %d...\n", request_nbr);<br />
<br />
zmq_send (sock, uint8("Hello"), 5, 0);<br />
<br />
% try to read up to 10 bytes of reply data.<br />
printf ("Waiting for server response %d... (Ctrl-C to exit)\n", request_nbr); <br />
<br />
recieved = zmq_recv (sock, 10, 0);<br />
printf ("Received World %d\n", request_nbr);<br />
endfor<br />
<br />
zmq_close (sock);<br />
</syntaxhighlight>}}<br />
<br />
== basic publish subscribe pattern ==<br />
<br />
Example based on client/server example from [http://zguide.zeromq.org/page:all#Getting-the-Message-Out http://zguide.zeromq.org/page:all#Getting-the-Message-Out]<br />
<br />
The server pushes 'weather updates' for random zipcodes. The client subscribes to the server just for zipcode 10001.<br />
<br />
{{Code|Server code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
publisher = zmq_socket (ZMQ_PUB);<br />
<br />
rc = zmq_bind (publisher, "tcp://*:5556");<br />
assert (rc);<br />
<br />
while (true) <br />
% Get values that will fool the boss<br />
zipcode = 10000 + randi (20);<br />
temperature = randi (215) - 80;<br />
relhumidity = randi (50) + 10;<br />
<br />
% Send message to all subscribers<br />
update = sprintf ("%05d %d %d", zipcode, temperature, relhumidity);<br />
<br />
zmq_send (publisher, update);<br />
endwhile<br />
<br />
zmq_close (publisher);<br />
</syntaxhighlight>}}<br />
<br />
{{Code|Client code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
subscriber = zmq_socket (ZMQ_SUB);<br />
rc = zmq_connect (subscriber, "tcp://localhost:5556");<br />
assert (rc);<br />
<br />
% Subscribe to zipcode, default is NYC, 10001<br />
zipfilter = "10001 ";<br />
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, zipfilter);<br />
assert (rc);<br />
<br />
% Process 100 updates<br />
update_nbr = 0;<br />
total_temp = 0;<br />
<br />
for update_nbr = 1:100<br />
string = char( zmq_recv(subscriber, 128) );<br />
<br />
[zipcode, temperature, relhumidity, count, errmsg] = sscanf (string, "%d %d %d", "C");<br />
<br />
fprintf ("recieved a temp for zipcode '%s' of %dF\n", ...<br />
zipfilter, temperature);<br />
<br />
total_temp += temperature;<br />
endfor<br />
<br />
fprintf ("Average temperature for zipcode '%s' was %dF\n", ...<br />
zipfilter, (total_temp / update_nbr));<br />
<br />
zmq_close (subscriber);<br />
</syntaxhighlight>}}<br />
<br />
<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Zeromq_package&diff=8244Zeromq package2016-03-05T04:22:45Z<p>Lostbard: </p>
<hr />
<div>The {{Forge|zeromq}} package is part of the [[Octave Forge]] project and provides Octave bindings to the ZeroMQ library.<br />
<br />
= Installation =<br />
<br />
== package requirements ==<br />
<br />
The {{Forge|zeromq}} package requires the [http://zeromq.org/ ZeroMQ] libraries and include files to be installed in order to compile.<br />
<br />
for fedora: yum install zeromq-devel<br />
<br />
for ubuntu: apt install libzmq-dev<br />
<br />
== octave installation ==<br />
<br />
With the [http://zeromq.org/ ZeroMQ] library installed, from octave commmand line:<br />
<br />
>> pkg install -forge zeromq<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load zeromq<br />
<br />
Look at the quick reference for the package:<br />
<br />
>> help zeromq<br />
<br />
== Differences between C and Octave bindings ==<br />
<br />
The Octave binding is a subset of the C binding of the ZeroMQ library.<br />
<br />
Major differences are:<br />
<br />
1. The octave binding creates a single zeromq context that is used for all zeromq sockets. In the C bindings, the programmer must create a context and use it during socket creation.<br />
<br />
2. only limited zmq_getsockopt and zmq_setsockopt is currently implemented.<br />
<br />
3. functions mostly return true or false for whether they succeeded or failed. In the C binding, 0 signififed success.<br />
<br />
== The functions ==<br />
<br />
zmq_bind<br />
Bind a zeromq socket to a endpoint.<br />
<br />
zmq_close<br />
Close a zeromq socket.<br />
<br />
zmq_connect<br />
Connect a zeromq socket to a endpoint<br />
<br />
zmq_errno<br />
Get system errno value.<br />
<br />
zmq_getsockopt<br />
Get current value of a zeromq socket option.<br />
<br />
zmq_poll<br />
Poll a socket or sockets for a timeout or incoming data<br />
available.<br />
<br />
zmq_recv<br />
Attempt to read data from a zeromq socket.<br />
<br />
zmq_send<br />
Attempt to send data from a zeromq socket.<br />
<br />
zmq_setsockopt<br />
Set a zeromq socket option.<br />
<br />
zmq_strerror<br />
Get the last zmq error string.<br />
<br />
zmq_unbind<br />
Unbind a previously bound zeromq socket.<br />
<br />
zmq_version<br />
Get the zeromq library version numbers.<br />
<br />
= Examples =<br />
<br />
== basic request/reply pattern ==<br />
<br />
Example based on client/server example from [http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive http://zguide.zeromq.org/page:all#Ask-and-Ye-Shall-Receive]<br />
<br />
The client sends a "Hello" to the server which responds back "World". No error checking or data validation is done in the example.<br />
<br />
{{Code|Server code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
printf ("Creating hello world server...\n");<br />
<br />
% create reply socket, and bind it to port 5555<br />
sock = zmq_socket (ZMQ_REP);<br />
<br />
zmq_bind (sock, "tcp://*:5555");<br />
<br />
printf ("Waiting for clients ...\n");<br />
<br />
% loop forever, waiting for client requests and responding back <br />
while (true)<br />
recievedata = zmq_recv (sock, 10, 0);<br />
printf ("Received Hello\n");<br />
zmq_send (sock, "World", 5, 0);<br />
endwhile<br />
</syntaxhighlight>}}<br />
<br />
{{Code|Client code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
printf ("Connecting to hello world server...\n");<br />
<br />
<br />
% Create socket and connect to server<br />
<br />
sock = zmq_socket (ZMQ_REQ);<br />
zmq_connect (sock, "tcp://localhost:5555");<br />
<br />
for request_nbr = [1:10]<br />
printf ("Sending Hello %d...\n", request_nbr);<br />
<br />
zmq_send (sock, uint8("Hello"), 5, 0);<br />
<br />
% try to read up to 10 bytes of reply data.<br />
printf ("Waiting for server response %d... (Ctrl-C to exit)\n", request_nbr); <br />
<br />
recieved = zmq_recv (sock, 10, 0);<br />
printf ("Received World %d\n", request_nbr);<br />
endfor<br />
<br />
zmq_close (sock);<br />
</syntaxhighlight>}}<br />
<br />
== basic publish subscribe ==<br />
<br />
Example based on client/server example from [http://zguide.zeromq.org/page:all#Getting-the-Message-Out http://zguide.zeromq.org/page:all#Getting-the-Message-Out]<br />
<br />
The server pushes 'weather updates' for random zipcodes. The client subscribes to the server just for zipcode 10001.<br />
<br />
{{Code|Server code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
publisher = zmq_socket (ZMQ_PUB);<br />
<br />
rc = zmq_bind (publisher, "tcp://*:5556");<br />
assert (rc);<br />
<br />
while (true) <br />
% Get values that will fool the boss<br />
zipcode = 10000 + randi (20);<br />
temperature = randi (215) - 80;<br />
relhumidity = randi (50) + 10;<br />
<br />
% Send message to all subscribers<br />
update = sprintf ("%05d %d %d", zipcode, temperature, relhumidity);<br />
<br />
zmq_send (publisher, update);<br />
endwhile<br />
<br />
zmq_close (publisher);<br />
</syntaxhighlight>}}<br />
<br />
{{Code|Client code|<syntaxhighlight lang="octave" style="font-size:13px"><br />
% zeromq package must be installed and loaded to work<br />
pkg load zeromq<br />
<br />
% dont buffer output<br />
more off<br />
<br />
subscriber = zmq_socket (ZMQ_SUB);<br />
rc = zmq_connect (subscriber, "tcp://localhost:5556");<br />
assert (rc);<br />
<br />
% Subscribe to zipcode, default is NYC, 10001<br />
zipfilter = "10001 ";<br />
rc = zmq_setsockopt (subscriber, ZMQ_SUBSCRIBE, zipfilter);<br />
assert (rc);<br />
<br />
% Process 100 updates<br />
update_nbr = 0;<br />
total_temp = 0;<br />
<br />
for update_nbr = 1:100<br />
string = char( zmq_recv(subscriber, 128) );<br />
<br />
[zipcode, temperature, relhumidity, count, errmsg] = sscanf (string, "%d %d %d", "C");<br />
<br />
fprintf ("recieved a temp for zipcode '%s' of %dF\n", ...<br />
zipfilter, temperature);<br />
<br />
total_temp += temperature;<br />
endfor<br />
<br />
fprintf ("Average temperature for zipcode '%s' was %dF\n", ...<br />
zipfilter, (total_temp / update_nbr));<br />
<br />
zmq_close (subscriber);<br />
</syntaxhighlight>}}<br />
<br />
<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Zeromq_package&diff=8243Zeromq package2016-03-05T00:12:00Z<p>Lostbard: </p>
<hr />
<div>The {{Forge|zeromq}} package is part of the [[Octave Forge]] project and provides Octave bindings to the ZeroMQ library.<br />
<br />
= Installation =<br />
<br />
== package requirements ==<br />
<br />
The {{Forge|zeromq}} package requires the [http://zeromq.org/ ZeroMQ] libraries and include files to be installed in order to compile.<br />
<br />
for fedora: yum install zeromq-devel<br />
<br />
for ubuntu: apt install libzmq-dev<br />
<br />
== octave installation ==<br />
<br />
With the [http://zeromq.org/ ZeroMQ] library installed, from octave commmand line:<br />
<br />
>> pkg install -forge zeromq<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load zeromq<br />
<br />
<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Zeromq_package&diff=8242Zeromq package2016-03-05T00:11:11Z<p>Lostbard: /* package requirements */</p>
<hr />
<div>The {{Forge|zeromq}} package is part of the [[Octave Forge]] project and provides Octave bindings to the ZeroMQ library.<br />
<br />
= Installation =<br />
<br />
== package requirements ==<br />
<br />
The {{Forge|zeromq}} package requires the [http://http://zeromq.org/ ZeroMQ] libraries and include files to be installed in order to compile.<br />
<br />
for fedora: yum install zeromq-devel<br />
<br />
for ubuntu: apt install libzmq-dev<br />
<br />
== octave installation ==<br />
<br />
With the ZeroMQ library installed, from octave commmand line:<br />
<br />
>> pkg install -forge zeromq<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load zeromq<br />
<br />
<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Zeromq_package&diff=8241Zeromq package2016-03-05T00:08:17Z<p>Lostbard: </p>
<hr />
<div>The {{Forge|zeromq}} package is part of the [[Octave Forge]] project and provides Octave bindings to the ZeroMQ library.<br />
<br />
= Installation =<br />
<br />
== package requirements ==<br />
<br />
The {{Forge|zeromq}} package requires the zeromq libraries and include files to be installed in order to compile.<br />
<br />
for fedora: yum install zeromq-devel<br />
<br />
for ubuntu: apt install libzmq-dev<br />
<br />
== octave installation ==<br />
<br />
With the ZeroMQ library installed, from octave commmand line:<br />
<br />
>> pkg install -forge zeromq<br />
<br />
= Using it =<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load zeromq<br />
<br />
<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Zeromq_package&diff=8240Zeromq package2016-03-05T00:07:43Z<p>Lostbard: /* package requirements */</p>
<hr />
<div>The {{Forge|zeromq}} package is part of the [[Octave Forge]] project and provides Octave bindings to the ZeroMQ library.<br />
<br />
= Installation =<br />
<br />
== package requirements ==<br />
<br />
The {{Forge|zeromq}} package requires the zeromq libraries and include files to be installed in order to compile.<br />
<br />
for fedora: yum install zeromq-devel<br />
<br />
for ubuntu: apt install libzmq-dev<br />
<br />
== octave installation ==<br />
<br />
With the ZeroMQ library installed, from octave commmand line:<br />
<br />
>> pkg install -forge zeromq<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load zeromq<br />
<br />
<br />
<br />
[[Category:Octave-Forge]]</div>Lostbardhttps://wiki.octave.org/wiki/index.php?title=Zeromq_package&diff=8239Zeromq package2016-03-05T00:07:00Z<p>Lostbard: Created page with "The {{Forge|zeromq}} package is part of the Octave Forge project and provides Octave bindings to the ZeroMQ library. = Installation = == package requirements == The {{F..."</p>
<hr />
<div>The {{Forge|zeromq}} package is part of the [[Octave Forge]] project and provides Octave bindings to the ZeroMQ library.<br />
<br />
= Installation =<br />
<br />
== package requirements ==<br />
<br />
The {{Forge|zeromq}} package requires the zeromq libraries and include files to be installed in order to compile.<br />
<br />
for fedora: yum install zeromq-devel<br />
for ubuntu: apt install libzmq-dev<br />
<br />
== octave installation ==<br />
<br />
With the ZeroMQ library installed, from octave commmand line:<br />
<br />
>> pkg install -forge zeromq<br />
<br />
Load it before any usage:<br />
<br />
>> pkg load zeromq<br />
<br />
<br />
<br />
[[Category:Octave-Forge]]</div>Lostbard