Editing Instrument control package

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

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, "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.


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">
fclose(s1) # Closes and releases serial interface object
srl_close(s0) # Closes and releases file descriptor
fclose(s2) # Closes and releases serial interface object
srl_close(s1) # Closes and releases file descriptor
srl_close(s2) # Closes and releases file descriptor
</syntaxhighlight>
</syntaxhighlight>
}}
}}
Please note that all contributions to Octave may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Octave:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)

Template used on this page: