uTools-Manuals/docs/php/dio_tcsetattr.html
2019-04-28 19:00:34 +08:00

116 lines
6.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Sets terminal attributes and baud rate for a serial port</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.dio-tcsetattr" class="refentry">
<div class="refnamediv">
<h1 class="refname">dio_tcsetattr</h1>
<p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5 &lt; 5.1.0)</p><p class="refpurpose"><span class="refname">dio_tcsetattr</span> &mdash; <span class="dc-title">
Sets terminal attributes and baud rate for a serial port
</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.dio-tcsetattr-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>dio_tcsetattr</strong></span>
( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$fd</code></span>
, <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code></span>
) : <span class="type">bool</span></div>
<p class="para rdfs-comment">
<span class="function"><strong>dio_tcsetattr()</strong></span> sets the terminal attributes and baud
rate of the open <code class="parameter">fd</code>.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.dio-tcsetattr-parameters">
<h3 class="title">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">fd</code></dt>
<dd>
<p class="para">
The file descriptor returned by <span class="function"><a href="dio_open.html" class="function">dio_open()</a></span>.
</p>
</dd>
<dt>
<code class="parameter">options</code></dt>
<dd>
<p class="para">
The currently available options are:
<ul class="itemizedlist">
<li class="listitem">
<p class="para">
&#039;baud&#039; - baud rate of the port - can be 38400,19200,9600,4800,2400,1800,
1200,600,300,200,150,134,110,75 or 50, default value is 9600.
</p>
</li>
<li class="listitem">
<p class="para">
&#039;bits&#039; - data bits - can be 8,7,6 or 5. Default value is 8.
</p>
</li>
<li class="listitem">
<p class="para">
&#039;stop&#039; - stop bits - can be 1 or 2. Default value is 1.
</p>
</li>
<li class="listitem">
<p class="para">
&#039;parity&#039; - can be 0,1 or 2. Default value is 0.
</p>
</li>
</ul>
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.dio-tcsetattr-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
没有返回值。
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.dio-tcsetattr-examples">
<h3 class="title">范例</h3>
<p class="para">
<div class="example" id="example-2745">
<p><strong>Example #1 Setting the baud rate on a serial port</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$fd&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dio_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'/dev/ttyS0'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">O_RDWR&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">O_NOCTTY&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">O_NONBLOCK</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">dio_fcntl</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">F_SETFL</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">O_SYNC</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">dio_tcsetattr</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">,&nbsp;array(<br />&nbsp;&nbsp;</span><span style="color: #DD0000">'baud'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">9600</span><span style="color: #007700">,<br />&nbsp;&nbsp;</span><span style="color: #DD0000">'bits'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">8</span><span style="color: #007700">,<br />&nbsp;&nbsp;</span><span style="color: #DD0000">'stop'&nbsp;&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,<br />&nbsp;&nbsp;</span><span style="color: #DD0000">'parity'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">0<br /></span><span style="color: #007700">));&nbsp;<br /><br />while&nbsp;(</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;{<br /><br />&nbsp;&nbsp;</span><span style="color: #0000BB">$data&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dio_read</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">256</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$data</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$data</span><span style="color: #007700">;<br />&nbsp;&nbsp;}<br />}&nbsp;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
</div>
</p>
</div>
<div class="refsect1 notes" id="refsect1-function.dio-tcsetattr-notes">
<h3 class="title">注释</h3>
<blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数未在 Windows 平台下实现。</span></p></blockquote>
</div>
</div></div></div></body></html>