haiku-website/static/legacy-docs/bebook/BSerialPort.html

246 lines
33 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The Be Book - Classes And Methods - The Device Kit</title><link rel="stylesheet" href="be_book.css" type="text/css" media="all" /><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="./images/favicon.ico" /><!--[if IE]>
<link rel="stylesheet" type="text/css" href="be_book_ie.css" />
<![endif]--><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="Access, BeOS, BeBook, API" /><link rel="start" href="index.html" title="The Be Book" /><link rel="up" href="TheDeviceKit.html" title="The Device Kit" /><link rel="prev" href="BJoystick.html" title="BJoystick" /><link rel="next" href="TheGameKit.html" title="The Game Kit" /></head><body><div id="header"><div id="headerT"><div id="headerTL"><a accesskey="p" href="BJoystick.html" title="BJoystick"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a accesskey="u" href="TheDeviceKit.html" title="The Device Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a accesskey="n" href="TheGameKit.html" title="The Game Kit"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="headerTR"><div id="navigpeople"><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div><div class="navigboxed" id="navigindex"><a accesskey="i" href="ClassIndex.html" title="Index">I</a></div><div class="navigboxed" id="naviglang" title="English">en</div></div><div id="headerTC">The Be Book - Classes And Methods - The Device Kit</div></div><div id="headerB">Prev: <a href="BJoystick.html">BJoystick</a>  Up: <a href="TheDeviceKit.html">The Device Kit</a>  Next: <a href="TheGameKit.html">The Game Kit</a></div><hr /></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h2 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort"></a>BSerialPort</h2></div></div></div><a id="id944606" class="indexterm"></a><div class="classheader"><table border="0"><colgroup><col /><col /></colgroup><tbody><tr><td><table width="100%" border="0"><colgroup><col /><col /></colgroup><tbody><tr><td>Derived From:</td><td></td></tr><tr><td>Mix-in Classes:</td><td></td></tr><tr><td>Declared In:</td><td><code class="filename">device/SerialPort.h</code></td></tr><tr><td>Library:</td><td><code class="filename">libdevice.so</code></td></tr><tr><td>Allocation:</td><td></td></tr></tbody></table></td><td>
<a class="link overview" href="BSerialPort_Overview.html" title="BSerialPort">Class Overview</a>
<div class="toc"><ul><li><span class="section"><a href="BSerialPort.html#BSerialPort_ConstructorDestructor">Constructor and Destructor</a></span></li><li><span class="section"><a href="BSerialPort.html#BSerialPort_MemberFunctions">Member Functions</a></span></li></ul></div>
</td></tr></tbody></table></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_ConstructorDestructor"></a>Constructor and Destructor</h3></div></div></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_Constructor"></a>BSerialPort()</h4></div></div></div><code class="constructorsynopsis cpp"><span class="methodname">BSerialPort</span>();</code><p>
Initializes the <code class="classname">BSerialPort</code> object to the following default values:
</p><ul class="itemizedlist"><li><p>
Hardware flow control (see
<a class="link" href="BSerialPort.html#BSerialPort_SetFlowControl" title="SetFlowControl(), FlowControl()"><code class="methodname">SetFlowControl()</code></a>)
</p></li><li><p>
A data rate of 19,200 bits per second (see
<a class="link" href="BSerialPort.html#BSerialPort_SetDataRate" title="SetDataRate(), DataRate(), data_rate"><code class="methodname">SetDataRate()</code></a>)
</p></li><li><p>
A serial unit with 8 bits of data, 1 stop bit, and no parity (see
<a class="link" href="BSerialPort.html#BSerialPort_SetDataBits" title="SetDataBits(), SetStopBits(), SetParityMode(), DataBits(), StopBits(), ParityMode(), data_bits, stop_bits, parity_mode"><code class="methodname">SetDataBits()</code></a>)
</p></li><li><p>
Blocking with no time limit—an infinite timeout—for
reading data (see
<a class="link" href="BSerialPort.html#BSerialPort_Read" title="Read() , SetBlocking() , SetTimeout()"><code class="methodname">Read()</code></a>)
</p></li></ul><p>
The new object doesn't represent any particular serial port. After
construction, it's necessary to open one of the ports by name.
</p><p>
The type of flow control must be decided before a port is opened. But the
other default settings listed above can be changed before or after
opening a port.
</p><p>
See also:
<a class="link" href="BSerialPort.html#BSerialPort_Open" title="Open(), Close()"><code class="methodname">Open()</code></a>
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_Destructor"></a>~BSerialPort()</h4></div></div></div><code class="methodsynopsis cpp"><span class="modifier">virtual </span><span class="methodname">~BSerialPort</span>();</code><p>
Makes sure the port is closed before the object is destroyed.
</p></div></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><hr /><div xmlns:d="http://docbook.org/ns/docbook"><h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_MemberFunctions"></a>Member Functions</h3></div></div></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_ClearInput"></a>ClearInput(), ClearOutput()</h4></div></div></div><code class="methodsynopsis cpp"><span class="void">void </span><span class="methodname">ClearInput</span>();</code><code class="methodsynopsis cpp"><span class="void">void </span><span class="methodname">ClearOutput</span>();</code><p>
These functions empty the serial port driver's input and output buffers,
so that the contents of the input buffer won't be read (by the
<a class="link" href="BSerialPort.html#BSerialPort_Read" title="Read() , SetBlocking() , SetTimeout()"><code class="methodname">Read()</code></a>
function) and the contents of the output buffer (after having been
written by
<a class="link" href="BSerialPort.html#BSerialPort_Write" title="Write()"><code class="methodname">Write()</code></a>)
won't be transmitted over the connection.
</p><p>
The buffers are cleared automatically when a port is opened.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_CountDevices"></a><a id="BSerialPort_GetDeviceName"></a>
CountDevices() , GetDeviceName()</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">int32 </span><span class="methodname">CountDevices</span>();</code><code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">GetDeviceName</span>(<span class="methodparam"><span class="type">int32 </span><span class="parameter">index</span></span>,<br />                       <span class="methodparam"><span class="type">char* </span><span class="parameter">outName</span></span>,<br />                       <span class="methodparam"><span class="type">size_t </span><span class="parameter">bufSize</span><span class="initializer"> = <span class="constant">B_OS_NAME_LENGTH</span></span></span>);</code><p>
<code class="methodname">CountDevices()</code> returns the number of serial ports on the computer.
</p><p>
<code class="methodname">GetDeviceName()</code> returns the name of the device specified by the given
<code class="parameter">index</code>. The buffer pointed to by <code class="parameter">outName</code> is filled with the device name;
<code class="parameter">bufSize</code> indicates the size of the buffer.
</p><p>
The names returned by <code class="methodname">GetDeviceName()</code> can be passed into the
<a class="link" href="BSerialPort.html#BSerialPort_Open" title="Open(), Close()"><code class="methodname">Open()</code></a>
function to open a device.
</p><table class="variablelist returncodes"><thead><tr><th>Return Code</th><th>Description</th></tr></thead><tbody><tr><td><p><span class="term"><code class="constant">B_OK</code>.</span></p></td><td><p>
The name was returned successfully.
</p></td></tr><tr><td><p><span class="term"><code class="constant">B_BAD_INDEX</code>.</span></p></td><td><p>
The specified <code class="parameter">index</code> is invalid.
</p></td></tr><tr><td><p><span class="term"><code class="constant">B_NAME_TOO_LONG</code>.</span></p></td><td><p>
The device name is too long for the buffer.
</p></td></tr></tbody></table></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_IsCTS"></a>IsCTS()</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">bool </span><span class="methodname">IsCTS</span>();</code><p>
Returns <code class="constant">true</code> if the Clear to Send (CTS) pin is asserted,
and <code class="constant">false</code> if not.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_IsDCD"></a>IsDCD()</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">bool </span><span class="methodname">IsDCD</span>();</code><p>
Returns <code class="constant">true</code> if the Data Carrier Detect (DCD) pin is asserted, and
<code class="constant">false</code> if not.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_IsDSR"></a>IsDSR()</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">bool </span><span class="methodname">IsDSR</span>();</code><p>
Returns <code class="constant">true</code> if the Data Set Ready (DSR) pin is asserted, and <code class="constant">false</code> if
not.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_IsRI"></a>IsRI()</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">bool </span><span class="methodname">IsRI</span>();</code><p>
Returns <code class="constant">true</code> if the Ring Indicator (RI) pin is asserted, and
<code class="constant">false</code> if not.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_Open"></a><a id="BSerialPort_Close"></a>
Open(), Close()</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">Open</span>(<span class="methodparam"><span class="modifier">const </span><span class="type">char* </span><span class="parameter">name</span></span>);</code><code class="methodsynopsis cpp"><span class="type">void </span><span class="methodname">Close</span>();</code><p>
These functions open the <code class="parameter">name</code> serial port and close it again. To get a
serial port name, use the <code class="methodname">GetDeviceName()</code> function
</p><p>
To be able to read and write data, the <code class="classname">BSerialPort</code> object must have a
port open. It can open first one port and then another, but it can have
no more than one open at a time. If it already has a port open when
<code class="methodname">Open()</code> is called, that port is closed before an attempt is made to open
the <code class="parameter">name</code> port. (Thus, both <code class="methodname">Open()</code> and <code class="methodname">Close()</code>
close the currently open port.)
</p><p>
<code class="methodname">Open()</code> can't open the <code class="parameter">name</code> port if some other entity already has it open.
(If the <code class="classname">BSerialPort</code> itself has <code class="parameter">name</code> open, <code class="methodname">Open()</code>
first closes it, then opens it again.)
</p><p>
When a serial port is opened, its input and output buffers are emptied
and the Data Terminal Ready (DTR) pin is asserted.
</p><table class="variablelist returncodes"><thead><tr><th>Return Code</th><th>Description</th></tr></thead><tbody><tr><td><p><span class="term">positive integers (not 0).</span></p></td><td><p>
Success.
</p></td></tr><tr><td><p><span class="term"><code class="constant">B_PERMISSION_DENIED</code>.</span></p></td><td><p>
The port is already open.
</p></td></tr><tr><td><p><span class="term"><code class="constant">B_ERROR</code>.</span></p></td><td><p>
The port couldn't be opened for some other reason.
</p></td></tr></tbody></table></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_Read"></a><a id="BSerialPort_SetBlocking"></a>
<a id="BSerialPort_SetTimeout"></a>
Read() , SetBlocking() , SetTimeout()</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">ssize_t </span><span class="methodname">Read</span>(<span class="methodparam"><span class="type">void* </span><span class="parameter">buffer</span></span>,<br />             <span class="methodparam"><span class="type">size_t </span><span class="parameter">maxBytes</span></span>);</code><code class="methodsynopsis cpp"><span class="void">void </span><span class="methodname">SetBlocking</span>(<span class="methodparam"><span class="type">bool </span><span class="parameter">shouldBlock</span></span>);</code><code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">SetTimeout</span>(<span class="methodparam"><span class="type">bigtime_t </span><span class="parameter">timeout</span></span>);</code><p>
<code class="methodname">Read()</code> takes incoming data from the serial port driver and places it in
the data <code class="parameter">buffer</code> provided. In no case will it read more than
<code class="parameter">maxBytes</code>—a value that should reflect the capacity of the buffer.
The input buffer of the driver, from which <code class="methodname">Read()</code> takes the data, holds a
maximum of 2,024 bytes (2048 on Mac hardware). This function fails if the
<code class="classname">BSerialPort</code> object doesn't have a port open.
</p><p>
The number of bytes that <code class="methodname">Read()</code> will read before returning depends not
only on <code class="parameter">maxBytes</code>, but also on the <code class="parameter">shouldBlock</code>
flag and the <code class="parameter">timeout</code> set by the other two functions.
</p><ul class="itemizedlist"><li><p>
<code class="methodname">SetBlocking()</code> determines whether <code class="methodname">Read()</code>
should block and wait for
<code class="parameter">maxBytes</code> of data to arrive at the serial port if that number isn't
already available to be read. If the <code class="parameter">shouldBlock</code>
flag is <code class="constant">true</code>, <code class="methodname">Read()</code>
will block. However, if <code class="parameter">shouldBlock</code> is <code class="constant">false</code>,
<code class="methodname">Read()</code> will take however
many bytes are waiting to be read, up to the maximum asked for, then
return immediately. If no data is waiting at the serial port, it
returns without reading anything.
</p></li><li><p>
The default <code class="parameter">shouldBlock</code> setting is <code class="constant">true</code>.
</p></li><li><p>
<code class="methodname">SetTimeout()</code> sets a time limit on how long <code class="methodname">Read()</code>
will block while
waiting for data to arrive at the port's input buffer. The timeout is
relevant to <code class="methodname">Read()</code> only if the <code class="parameter">shouldBlock</code> flag is <code class="constant">true</code>. However, the
time limit also applies to the <a class="link" href="BSerialPort.html#BSerialPort_WaitForInput" title="WaitForInput()"><code class="methodname">WaitForInput()</code></a> function, which always
blocks, regardless of the <code class="parameter">shouldBlock</code> setting.
</p></li><li><p>
There is no time limit if the timeout is set to
<code class="constant">B_INFINITE_TIMEOUT</code><code class="methodname">Read()</code>
and <a class="link" href="BSerialPort.html#BSerialPort_WaitForInput" title="WaitForInput()"><code class="methodname">WaitForInput()</code></a> will block
forever. Otherwise, the timeout is expressed in microseconds and can
range from a minimum of 100,000 (0.1 second) through a maximum of
25,500,000 (25.5 seconds); differences less than 100,000 microseconds
are not recognized; they're rounded to the nearest tenth of a second.
</p></li><li><p>
The default timeout is <code class="constant">B_INFINITE_TIMEOUT</code>.
</p></li></ul><p>
<code class="methodname">Read()</code> returns…
</p><table class="variablelist returncodes"><thead><tr><th>Return Code</th><th>Description</th></tr></thead><tbody><tr><td><p><span class="term">non-negative integer.</span></p></td><td><p>
Success; the value is the number of bytes that
were read.
</p></td></tr><tr><td><p><span class="term"><code class="constant">B_INTERRUPTED</code>.</span></p></td><td><p>
The operation was interrupted by a signal.
</p></td></tr><tr><td><p><span class="term"><code class="constant">B_FILE_ERROR</code>.</span></p></td><td><p>
The <code class="classname">BSerialPort</code> doesn't have a port open.
</p></td></tr></tbody></table><p>
<code class="methodname">SetTimeout()</code> returns…
</p><table class="variablelist returncodes"><thead><tr><th>Return Code</th><th>Description</th></tr></thead><tbody><tr><td><p><span class="term"><code class="constant">B_OK</code>.</span></p></td><td><p>
Success.
</p></td></tr><tr><td><p><span class="term"><code class="constant">B_BAD_VALUE</code>.</span></p></td><td><p>
Out of range value passed to <code class="methodname">SetTimeout()</code>.
</p></td></tr></tbody></table><p>
(Note that it's not considered an error if a timeout expires.)
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_SetDataBits"></a><a id="BSerialPort_SetStopBits"></a>
<a id="BSerialPort_SetParityMode"></a>
<a id="BSerialPort_DataBits"></a>
<a id="BSerialPort_StopBits"></a>
<a id="BSerialPort_ParityMode"></a>
<a id="BSerialPort_data_bits"></a>
<a id="BSerialPort_stop_bits"></a>
<a id="BSerialPort_parity_mode"></a>
SetDataBits(), SetStopBits(), SetParityMode(), DataBits(),
StopBits(), ParityMode(), data_bits, stop_bits, parity_mode</h4></div></div></div><code class="methodsynopsis cpp"><span class="void">void </span><span class="methodname">SetDataBits</span>(<span class="methodparam"><span class="type">data_bits </span><span class="parameter">count</span></span>);</code><code class="methodsynopsis cpp"><span class="void">void </span><span class="methodname">SetStopBits</span>(<span class="methodparam"><span class="type">stop_bits </span><span class="parameter">count</span></span>);</code><code class="methodsynopsis cpp"><span class="void">void </span><span class="methodname">SetParityMode</span>(<span class="methodparam"><span class="type">parity_mode </span><span class="parameter">mode</span></span>);</code><code class="methodsynopsis cpp"><span class="type">data_bits </span><span class="methodname">DataBits</span>();</code><code class="methodsynopsis cpp"><span class="type">stop_bits </span><span class="methodname">StopBits</span>();</code><code class="methodsynopsis cpp"><span class="type">parity_mode </span><span class="methodname">ParityMode</span>();</code><pre class="programlisting definition c">typedef enum { <code class="constant">B_DATA_BITS_7</code>, <code class="constant">B_DATA_BITS_8</code> } <span class="type">data_bits</span></pre><pre class="programlisting definition c">typedef enum { <code class="constant">B_STOP_BITS_1</code>, <code class="constant">B_STOP_BITS_2</code> } <span class="type">stop_bits</span></pre><pre class="programlisting definition c">typedef enum { <code class="constant">B_EVEN_PARITY</code>, <code class="constant">B_ODD_PARITY</code>, <code class="constant">B_NO_PARITY</code> } <span class="type">parity_mode</span></pre><p>
These functions set and return characteristics of the serial unit used to
send and receive data.
</p><ul class="itemizedlist"><li><p>
<code class="methodname">SetDataBits()</code> sets the number of bits of data in each unit; the
default is <code class="constant">B_DATA_BITS_8</code>.
</p></li><li><p>
<code class="methodname">SetStopBits()</code> sets the number of stop bits in each unit; the default
is <code class="constant">B_STOP_BITS_2</code>.
</p></li><li><p>
<code class="methodname">SetParityMode()</code> sets whether the serial unit contains a parity bit
and, if so, the type of parity used; the default is <code class="constant">B_NO_PARITY</code>.
</p></li></ul></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_SetDataRate"></a><a id="BSerialPort_DataRate"></a>
<a id="BSerialPort_data_rate"></a>
SetDataRate(), DataRate(), data_rate</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">SetDataRate</span>(<span class="methodparam"><span class="type">data_rate </span><span class="parameter">bitsPerSecond</span></span>);</code><code class="methodsynopsis cpp"><span class="type">data_rate </span><span class="methodname">DataRate</span>();</code><pre class="programlisting definition cpp">typedef enum {
<code class="constant">B_0_BPS</code>, <code class="constant">B_50_BPS</code>, <code class="constant">B_75_BPS</code>, <code class="constant">B_110_BPS</code>, <code class="constant">B_134_BPS</code>,
<code class="constant">B_150_BPS</code>, <code class="constant">B_200_BPS</code>, <code class="constant">B_300_BPS</code>, <code class="constant">B_600_BPS</code>, <code class="constant">B_1200_BPS</code>,
<code class="constant">B_1800_BPS</code>, <code class="constant">B_2400_BPS</code>, <code class="constant">B_4800_BPS</code>, <code class="constant">B_9600_BPS</code>, <code class="constant">B_19200_BPS</code>,
<code class="constant">B_31250_BPS</code>, <code class="constant">B_38400_BPS</code>, <code class="constant">B_57600_BPS</code>, <code class="constant">B_115200_BPS</code>, <code class="constant">B_230400_BPS</code>
} <span class="type">data_rate</span></pre><p>
These functions set and return the rate (in bits per second) at which
data is both transmitted and received.
</p><p>
The default data rate is <code class="constant">B_19200_BPS</code>. If the rate is set to 0 (<code class="constant">B_0_BPS</code>),
data will be sent and received at an indeterminate number of bits per
second.
</p><p>
<code class="methodname">SetDataRate()</code> returns…
</p><table class="variablelist returncodes"><thead><tr><th>Return Code</th><th>Description</th></tr></thead><tbody><tr><td><p><span class="term"><code class="constant">B_OK</code>.</span></p></td><td><p>
The rate was successfully set.
</p></td></tr><tr><td><p><span class="term"><code class="constant">B_NO_INIT</code>.</span></p></td><td><p>
The <code class="classname">BSerialPort</code> object doesn't have a port open.
</p></td></tr><tr><td><p><span class="term"><code class="constant">B_ERROR</code>.</span></p></td><td><p>
The data rate couldn't be set for any other reason.
</p></td></tr></tbody></table></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_SetDTR"></a>SetDTR()</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">SetDTR</span>(<span class="methodparam"><span class="type">bool </span><span class="parameter">pinAsserted</span></span>);</code><p>
Asserts the Data Terminal Ready (DTR) pin if the <code class="parameter">pinAsserted</code> flag is
<code class="constant">true</code>, and de-asserts it if the flag is <code class="constant">false</code>.
The function should always
return <code class="constant">B_OK</code>.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_SetFlowControl"></a><a id="BSerialPort_FlowControl"></a>
SetFlowControl(), FlowControl()</h4></div></div></div><code class="methodsynopsis cpp"><span class="void">void </span><span class="methodname">SetFlowControl</span>(<span class="methodparam"><span class="type">uint32 </span><span class="parameter">mask</span></span>);</code><code class="methodsynopsis cpp"><span class="type">uint32 </span><span class="methodname">FlowControl</span>();</code><p>
These functions set and return the type of flow control the driver should
use. There are four possibilities:
</p><table class="variablelist constants"><thead><tr><th>Constant</th><th>Description</th></tr></thead><tbody><tr><td><p><span class="term"><code class="constant">B_SOFTWARE_CONTROL</code></span></p></td><td><p>Control is maintained through XON and XOFF characters
inserted into the data stream.</p></td></tr><tr><td><p><span class="term"><code class="constant">B_HARDWARE_CONTROL</code></span></p></td><td><p>Control is maintained through the Clear to Send (CTS)
and Request to Send (RTS) pins.</p></td></tr><tr><td><p><span class="term"><code class="constant">B_SOFTWARE_CONTROL</code> +
<code class="constant">B_HARDWARE_CONTROL</code></span></p></td><td><p>Both of the above.</p></td></tr><tr><td><p><span class="term">0 (zero)</span></p></td><td><p>No control.</p></td></tr></tbody></table><p>
<code class="methodname">SetFlowControl()</code> should be called before a specific serial port is
opened. You can't change the type of flow control the driver uses in
midstream.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_SetRTS"></a>SetRTS()</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">status_t </span><span class="methodname">SetRTS</span>(<span class="methodparam"><span class="type">bool </span><span class="parameter">pinAsserted</span></span>);</code><p>
Asserts the Request to Send (RTS) pin if the <code class="parameter">pinAsserted</code> flag is <code class="constant">true</code>,
and de-asserts it if the flag is <code class="constant">false</code>. The function always returns <code class="constant">B_OK</code>.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_WaitForInput"></a>WaitForInput()</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">ssize_t </span><span class="methodname">WaitForInput</span>();</code><p>
Waits for input data to arrive at the serial port and returns the number
of bytes available to be read. If data is already waiting, the function
returns immediately.
</p><p>
This function doesn't respect the flag set by
<a class="link" href="BSerialPort.html#BSerialPort_SetBlocking"><code class="methodname">SetBlocking()</code></a>; it blocks
even if blocking is turned off for the
<a class="link" href="BSerialPort.html#BSerialPort_Read" title="Read() , SetBlocking() , SetTimeout()"><code class="methodname">Read()</code></a> function. However, it does
respect the timeout set by <a class="link" href="BSerialPort.html#BSerialPort_SetTimeout"><code class="methodname">SetTimeout()</code></a>. If the timeout expires before
input data arrives at the serial port, it returns 0.
</p></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BSerialPort_Write"></a>Write()</h4></div></div></div><code class="methodsynopsis cpp"><span class="type">ssize_t </span><span class="methodname">Write</span>(<span class="methodparam"><span class="modifier">const </span><span class="type">void* </span><span class="parameter">data</span></span>,<br />              <span class="methodparam"><span class="type">size_t </span><span class="parameter">numBytes</span></span>);</code><p>
Writes up to <code class="parameter">numBytes</code> of data to the serial port's output buffer. This
function will be successful in writing the data only if the <code class="classname">BSerialPort</code>
object has a port open. The output buffer holds a maximum of 512 bytes
(1024 on Mac hardware).
</p><table class="variablelist returncodes"><thead><tr><th>Return Code</th><th>Description</th></tr></thead><tbody><tr><td><p><span class="term">non-negative integer.</span></p></td><td><p>
Success; the value is the number of bytes that were
written.
</p></td></tr><tr><td><p><span class="term"><code class="constant">B_INTERRUPTED</code>.</span></p></td><td><p>
The operation was interrupted by a signal.
</p></td></tr><tr><td><p><span class="term"><code class="constant">B_FILE_ERROR</code>.</span></p></td><td><p>
The <code class="classname">BSerialPort</code> doesn't have a port open.
</p></td></tr></tbody></table></div></div></div><div id="footer"><hr /><div id="footerT">Prev: <a href="BJoystick.html">BJoystick</a>  Up: <a href="TheDeviceKit.html">The Device Kit</a>  Next: <a href="TheGameKit.html">The Game Kit</a> </div><div id="footerB"><div id="footerBL"><a href="BJoystick.html" title="BJoystick"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a href="TheDeviceKit.html" title="The Device Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a href="TheGameKit.html" title="The Game Kit"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="footerBR"><div><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div></div><div id="footerBC"><a href="http://www.access-company.com/home.html" title="ACCESS Co."><img alt="Access Company" src="./images/access_logo.png" /></a></div></div></div><div id="licenseFooter"><div id="licenseFooterBL"><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" title="Creative Commons License"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by-nc-nd/3.0/88x31.png" /></a></div><div id="licenseFooterBR"><a href="./LegalNotice.html">Legal Notice</a></div><div id="licenseFooterBC"><span id="licenseText">This work is licensed under a
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative
Commons Attribution-Non commercial-No Derivative Works 3.0 License</a>.</span></div></div></body></html>