PHP 7.2.0 Release Candidate 4 Released

dio_tcsetattr

(PHP 4 >= 4.3.0, PHP 5 <= 5.0.5, PHP 7)

dio_tcsetattr Sets terminal attributes and baud rate for a serial port

Descrierea

bool dio_tcsetattr ( resource $fd , array $options )

dio_tcsetattr() sets the terminal attributes and baud rate of the open fd.

Parametri

fd

The file descriptor returned by dio_open().

options

The currently available options are:

  • 'baud' - 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.

  • 'bits' - data bits - can be 8,7,6 or 5. Default value is 8.

  • 'stop' - stop bits - can be 1 or 2. Default value is 1.

  • 'parity' - can be 0,1 or 2. Default value is 0.

Valorile întoarse

Nu este întoarsă nici o valoare.

Exemple

Example #1 Setting the baud rate on a serial port

<?php

$fd 
dio_open('/dev/ttyS0'O_RDWR O_NOCTTY O_NONBLOCK);

dio_fcntl($fdF_SETFLO_SYNC);

dio_tcsetattr($fd, array(
  
'baud' => 9600,
  
'bits' => 8,
  
'stop'  => 1,
  
'parity' => 0
)); 

while (
1) {

  
$data dio_read($fd256);

  if (
$data) {
      echo 
$data;
  }


?>

Note

Notă: Această funcție nu este implementată pe platformele Windows.

add a note add a note

User Contributed Notes 3 notes

up
0
daniel widyanto (kunilkuda at gmail dot com)
12 years ago
I'm using PHP to interface my AVR microcontroller in /dev/ttyS0. I bet someone else dolupcaen/r sb0dHre'sttyS0 hsin :lupcaen- PHP: dio: #0efau>PH'm u><aentl:lupcaenbsp;}< bsp;}< bsp;}< bsp;}< bsp;}< bsp;}< - RTS / CTS hardwsii my AVR upcaenbsp;}< bsp;}< bsp;}< bsp;}< bsp;}< bsp;}< - ICA #0as aelupcaenbsp;}< bsp;}< bsp;}< bsp;}< bsp;}< bsp;}< bsp;}< (meanone (kr: #0000"><lr">ait an lku0x0A/LF- carefs. my AVR ad> age anfaueing er ocontroller idevatcțtss="refs 0000iles.piv c, when you="hekr: #w#DDcțts><lr"als/dt>ndu0x0A/LF-autoh.php'>ly ocoe el>ndu- baud v id="f'm uyour tent=").upcaen/r sb0F cathohekwhosomin neer RTS/CTS and/ caICA #0, you=ity&"heklinux en/featl:lsler.upcaen/r sb0dHre'stm'>Se:br />} <ode"><code><hreflang=r: #0000BB">&lbsp;}< bsp;}< bsp;}< bsp;}< exec<br /><br /><<code><keywordlor: #007700">(<ong>: <sle"me="'sler -Fontroller id,192 raw'<br /><br /><<code><keywordlor: #007700">);<br /> bsp;}< bsp;}< bsp;}< <br /><br /><<code><hreflang=r: #0000BB">$fd<<code><keywordlo=<br /><br /><<code><hreflang=r: #0000BB">dio_open<<code><keywordlor: #007700">(<ong>: <sle"me="': #DD0000">'/dev/ttyS0'<<code><keywordlo,<br /><br /><<code><hreflang=r: #00 <br /><br /><<code><keywordlo| <br /><br /><<code><hreflang=r: #0000 <br /><br /><<code><keywordlo| <br /><br /><<code><hreflang=r: DELAY<br /><br /><<code><keywordlor: #0077<br /> bsp;}< bsp;}< bsp;}< <br /><br /><<code><hreflang=r: #0000BB">dio_fcntl<<code><keywordlor: #007700">(<ong>: <hreflang=r: #0000BB">$fd<<code><keywordlo,<br /><br /><<code><hreflang=r: #0000BB">F_SETFL<<code><keywordlo,<br /><br /><<code><hreflang=0<br /><br /><<code><keywordlor: #007700">);<br /> bsp;}< bsp;}< bsp;}< <br /><br /><<code><hreflang=r: #w#DDcB">dio_fcntl<<code><keywordlor: #007700">(<ong>: <hreflang=r: #0000BB">$fd<<code><keywordlo,<br /><br /><<code><sle"me=""\x41"0BB">F_SETFL<<code><keywordlo,<br /><br /><<code><hreflang=1<br /><br /><<code><keywordlor:bsp;}< <br /><br /><<code><="para rd// w#DDc0x41- ca'A''m u: #DD0000"00">);<br /> bsp;}< bsp;}< bsp;}< <0">);<br /> bsp;}< bsp;}< bsp;}< // Rearch-s.piv c_lengthphp'>Dyour expelect en/featl.piv c length00">);<br /> bsp;}< bsp;}< bsp;}< <br /><br /><<code><keywordlod bar: #007700">(<ong>: <hreflang=ri#0000BB">$fd<<code><keywordlo=<br /><br /><<code><hreflang=0<br /><br /><<code><keywordlo;: #007700">(<ong>: <hreflang=ri <br /><br /><<code><keywordlor: # <br /><br /><<code><hreflang=.piv c_length<br /><br /><<code><keywordlo;: #007700">(<ong>: <hreflang=ri<br /><br /><<code><keywordlo++) {upcaenbsp;}< bsp;}< bsp;}< bsp;}< bsp;}< bsp;}< bsp;}<bsp;}< <br /><br /><<code><hreflang=r.piv c <br /><br /><<code><keywordlo.=<br /><br /><<code><hreflang=r: #0000BB">dio_read<<code><keywordlor: #007700">(<ong>: <hreflang=r: #0000BB">$fd<<code><keywordlo, <br /><br /><<code><hreflang=1<br /><br /><<code><keywordlor:upcaenbsp;}< bsp;}< bsp;}< bsp;}< }BB">&lbsp;}< bsp;}< bsp;}< bsp;}< ecla <br /><br /><<code><hreflang=r.piv c<br /><br /><<code><keywordlo;:nbsp;<br /><br /><<code><hreflang=r: #00nbsp;<br /><bnbsp;p'>Fu'm u:upcaen- S rate Pro.phmmilesGuidand baPOSIX ratorsracte.php's,it</a> < xmlns=easyswnual/~mtit/d rate/"php"> ofR men" targ <me_blank"> < xmlns=easyswnual/~mtit/d rate/346">pcaen- sler t> <dd>Nount">3 pan> </span> </cospan></p>pan><="allnotes"> <div class=1509e" id="54346"> <div class="votes"> 1509e"d="Vd54346"> <a href="/manual/vote-n1509php?id=54346&page=function.dio-tcsetattr&vote=up" title="Vote up!" class="usernotes-voteu">up</a> </div> 1509e"d="Vd54346"> <a href="/manual/vote-n1509php?id=54346&page=function.dio-tcsetattr&vote=down" title="Vote down!" class="usernotes-voted">down</a> </div> <div class="t1509e id="V54346" title="50% like this..."> 0 </div> </div> 1509e ef="#54346" class="name"> <strong classffs.reroo (k cliciasd><av700"uda at gail dot com)</em></strong></a><a class="genanch1509e" f="#54346"> ¶</a><div class="date" t4-01 04:30-06-30 06:34"><strong>12 years ago</strong></div> <div class="tex1509e"dHcom54346"> <div class="phpcode"><code><span clF caindows.paud <p><str1 lookslse dle="5 . I:br />} <ode"><code><hreflang=r: #0000BB">&lBB">&lexec<br /><br /><<code><keywordlor: #007700">(<ong>: <sle"me="'s ael"te1: Sett=r: #bits&=8stop&=ass="ity=n xon=on'<br /><br /><<code><keywordlor: #00770br /><br /><<code><="para rd// execun" 'tionas ae' ococdline.php'>C- bindows.pd bat> <dr />} <br /><br /><ong>: <hreflang=r: <br /><br /><<code><keywordlo= <br /><br /><<code><hreflang=r: #0000BB">dio_open<<code><keywordlor: #007700">(<ong>: <sle"me="'"te1:>'/dev/ttyS0'<<code><keywordlo, <br /><br /><<code><hreflang=r: #00<br /><br /><<code><keywordlor: #007700">);<br /ar: #007700">(<ong>: <hreflang=1<br /><br /><<code><keywordlor 700">) {<br /> <br /><br /><<code><hreflang=rits&#<br /><br /><<code><keywordlo= <br /><br /><<code><hreflang=r: #0000BB">dio_read<<code><keywordlor: #007700">(<ong>: <hreflang=r: #0000BB">$fd<<code><keywordlo, <br /><br /><<code><hreflang=r: #0000BB">256<<code><keywordlor: #007700">);<br /> ifar: #007700">(<ong>: <hreflang=r: #0000BB">$data<<code><keywordlor 700">)&bsp;}< bsp;}<bsp;}< ecla <br /><br /><<code><hreflang=r: #0000BB">$data<<code><keywordlo:upcaenbsp;}<  &ndr />} <br /><br /><ong>: <hreflang=r: #0000BB">?></span> </span> </cospan></p>pan><="allnotes"> <div class34250e" id="54346"> <div class="votes"> 34250e"d="Vd54346"> <a href="/manual/vote-34250php?id=54346&page=function.dio-tcsetattr&vote=up" title="Vote up!" class="usernotes-voteu">up</a> </div> 34250e"d="Vd54346"> <a href="/manual/vote-34250php?id=54346&page=function.dio-tcsetattr&vote=down" title="Vote down!" class="usernotes-voted">down</a> </div> <div class="34250e id="V54346" title="50% like this..."> 0 </div> </div> 34250e ef="#54346" class="name"> <strong classheamicra at loradouda aeduail dot com)</em></strong></a><a class="genanc34250e" f="#54346"> ¶</a><div class="date3-07-19 03:37-06-30 06:34"><strong>12 years ago</strong></div> <div class="te34250e"dHcom54346"> <div class="phpcode"><code><span clat wa.pdru yersracta afirst beca"hekI wa.ptrymple o g <to iLinux box> <ddalk> <de">div/en/lud rate tent=" (a PIC18F452 pro.phmmaentlchip) ne.pe el><p><strnet/idadat>rnformas> <d0000B() ne.pnctionss="refsectne (karen't ocoe el> I'dp?bug_type=D.upcaen/r sb0Iafin'>ly ftyle out w (krmeonw (kthroughbaud v> <dd>No:br />} v> <0000Bnbsp;v> <0000BBr />} st<lr"haven't gottențts <d.net,- cahows <d'/mat</spantySx, b> houghtțtsmayat> <ttyS0. I0% ></span> </span> </cospan></p>pan><re. </p> </div> footlass="action"><a href="/manual/add-note.php?sect=function.dio-tcsetattr&redirect=http://fr2.php.net/manual/ro/function.dio-tcsetattr.php"><img src='/images/notes-add@2x.png' alt='add a note' width='12' height='12'> <small>add a note</</div> v> </d>..."> v> </d>endi section id="la > < </a>Gen/div> 'sectiondd>P'> </dd> are: r: #uresox" i <li'kish</option> <> </ </a="actior/manual/ro/ref.dio.php'>Funcții IO </dd> aon> <e: rchildsox" i <li'kish</> aon> > aon> </li> <> aon> ="function"><a href="fclosmanual/lass="dr: #​closmg=r: #​closmtr.php">Edi> =/> </ < > aon> </li> <> aon> ="function"><a href="f0000Banual/lass="dr: #​0000Bg=r: #​0000BB".php">Edi> =/> </ < > aon> </li> <> aon> ="function"><a href="function.dilass="dr: #​unctg=r: #​0000BB.php">Edi> =/> </ < > aon> </li> <> aon> ="function"><a href="f0000ion.dilass="dr: #​rdiv cr: #​rdivBB.php">Edi> =/> </ < > aon> </li> <> aon> ="function"><a href="fseekion.dilass="dr: #​seek cr: #​seekBB.php">Edi> =/> </ < > aon> </li> <> aon> ="function"><a href="fsnction.dilass="dr: #​snct cr: #​snctBB.php">Edi> =/> </ < > aon> </li> <> aon> ="function"><a href="function.dio-tcslass="dr: #​unction.dio