array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.dio-tcsetattr.php', 1 => 'dio_tcsetattr', ), 'up' => array ( 0 => 'ref.dio.php', 1 => 'Direct IO 函数', ), 'prev' => array ( 0 => 'function.dio-stat.php', 1 => 'dio_stat', ), 'next' => array ( 0 => 'function.dio-truncate.php', 1 => 'dio_truncate', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/dio/functions/dio-tcsetattr.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.3.0, PHP 5 < 5.1.0)
dio_tcsetattr — 设置串行端口的终端属性和波特率
fd
由 dio_open() 返回的文件描述符。
options
当前可用选项:
'baud' - 端口波特率 - 可以是 38400、19200、9600、4800、2400、1800、1200、600、300、200、150、134、110、75 或 50,默认为 9600。
'bits' - 数据位 - 可以是 8、7、6 或 5。默认为 8。
'stop' - 停止位 - 可以是 1 或 2。默认为 1。
'parity' - 可以是 0、1 或 2。默认是 0。
没有返回值。
示例 #1 在串口上设置波特率
<?php
$fd = dio_open('/dev/ttyS0', O_RDWR | O_NOCTTY | O_NONBLOCK);
dio_fcntl($fd, F_SETFL, O_SYNC);
dio_tcsetattr($fd, array(
'baud' => 9600,
'bits' => 8,
'stop' => 1,
'parity' => 0
));
while (1) {
$data = dio_read($fd, 256);
if ($data) {
echo $data;
}
}
?>
注意: 此函数未在 Windows 平台下实现。