Instrument control package: Difference between revisions

Jump to navigation Jump to search
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">
# 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 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, 'baudrate', 9600) # Change baudrate
set(s1, "baudrate", 9600) # Change baudrate
set(s1, 'bytesize', 5)    # Change byte size (config becomes 5-N-1)
set(s1, "bytesize", 5)    # Change byte size (config becomes 5-N-1)
set(s1, 'parity', "E")    # Changes parity checking (config becomes 5-E-1),
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, 'stopbits', 2)    # Changes stop bits (config becomes 5-E-2), possible
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">
srl_close(s0) # Closes and releases file descriptor
fclose(s1) # Closes and releases serial interface object
srl_close(s1) # Closes and releases file descriptor
fclose(s2) # Closes and releases serial interface object
srl_close(s2) # Closes and releases file descriptor
</syntaxhighlight>
</syntaxhighlight>
}}
}}
Anonymous user

Navigation menu