Editing Instrument control package
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 143: | Line 143: | ||
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"> | ||
# Open default serial port ttyUSB0 in default configuration of 115200, 8-N-1 | |||
s0 = serial() | |||
# 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 158: | Line 160: | ||
Changing some configurations is simply done by calling helper functions | Changing some configurations is simply 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. | ||
Line 180: | Line 182: | ||
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"> | ||
srl_close(s0) # Closes and releases file descriptor | |||
srl_close(s1) # Closes and releases file descriptor | |||
srl_close(s2) # Closes and releases file descriptor | |||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | }} |