Instrument control package: Difference between revisions
Jump to navigation
Jump to search
→Example: basic use
Line 78: | Line 78: | ||
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. | 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. | ||
{{Code|Serial port example|<syntaxhighlight lang="octave" style="font-size:13px"> | {{Code|Serial port example|<syntaxhighlight lang="octave" style="font-size:13px"> | ||
# Opens serial port ttyUSB1 with baudrate of 115200 (config defaults to 8-N-1) | # Opens serial port ttyUSB1 with baudrate of 115200 (config defaults to 8-N-1) | ||
s1 = serial("/dev/ttyUSB1", 115200) | s1 = serial("/dev/ttyUSB1", 115200) | ||
Line 95: | Line 93: | ||
Chaging some configurations is simple done by calling helper functions | Chaging some configurations is simple done by calling helper functions | ||
{{Code|Serial port example: helper functions|<syntaxhighlight lang="octave" style="font-size:13px"> | {{Code|Serial port example: helper functions|<syntaxhighlight lang="octave" style="font-size:13px"> | ||
set(s1, | set(s1, "baudrate", 9600) # Change baudrate | ||
set(s1, | set(s1, "bytesize", 5) # Change byte size (config becomes 5-N-1) | ||
set(s1, | set(s1, "parity", "E") # Changes parity checking (config becomes 5-E-1), | ||
# possible values [E]ven, [O]dd, [N]one. | # possible values [E]ven, [O]dd, [N]one. | ||
set(s1, | set(s1, "stopbits", 2) # Changes stop bits (config becomes 5-E-2), possible | ||
# values 1, 2. | # values 1, 2. | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 112: | Line 110: | ||
Do not forget to close the ports when you are done! | Do not forget to close the ports when you are done! | ||
{{Code||<syntaxhighlight lang="octave" style="font-size:13px"> | {{Code||<syntaxhighlight lang="octave" style="font-size:13px"> | ||
fclose(s1) # Closes and releases serial interface object | |||
fclose(s2) # Closes and releases serial interface object | |||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | }} |