Instrument control package: Difference between revisions
Jump to navigation
Jump to search
no edit summary
No edit summary |
|||
Line 284: | Line 284: | ||
== i2c == | == i2c == | ||
i2c | i2c | ||
== TCP == | |||
=== Example: basic use === | |||
For testing you could start a tcp listener | |||
<pre> | |||
$ socat TCP-LISTEN:8000 - | |||
</pre> | |||
Now you can connect your listener. | |||
{{Code|TCP example|<syntaxhighlight lang="octave" style="font-size:13px"> | |||
# Open TCP connection to 127.0.0.1:8000 | |||
t0 = tcp("127.0.0.1",8000) | |||
# write to listener | |||
tcp_write(t0, "Hello world!") | |||
# Blocking read call, returns uint8 array of exactly 12 bytes read | |||
data = tcp_read(t0, 12) | |||
# Convert uint8 array to string, | |||
char(data) | |||
</syntaxhighlight> | |||
}} | |||
There are several ways to set timeout of read call. | |||
{{Code|set TCP timeout|<syntaxhighlight lang="octave" style="font-size:13px"> | |||
# Open TCP connection to 127.0.0.1:8000 with timeout of 100 ms | |||
t0 = tcp("127.0.0.1",8000,100) | |||
# set timeout to blocking | |||
tcp_timeout(t0, -1) | |||
# the timeout can be overwritten for single read call, in this case 1000ms | |||
data = tcp_read(t0, 12, 1000) | |||
</syntaxhighlight> | |||
}} | |||
[[Category:OctaveForge]] | [[Category:OctaveForge]] | ||
[[Category:Packages]] | [[Category:Packages]] |