PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

dio_truncate> <dio_stat
Last updated: Fri, 22 Aug 2008

view this page in

dio_tcsetattr

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

dio_tcsetattr Configura las opciones de un terminal y la velocidad de un puerto serie

Descripción

bool dio_tcsetattr ( resource $fd , array $opciones )

La función dio_tcsetattr() configura las opciones de un terminal y la velocidad en baudios del recurso cuyo descriptor fd ha sido obtenido previamente.

Note: Esta función no está implementada en plataformas Windows.

Lista de parámetros

fd

El descriptor de archivo devuelto por la función dio_open().

opciones

Las opciones actualmente disponibles son las siguientes:

  • 'baud' - velocidad en baudios del puerto serie - puede tomar los valores 38400, 19200, 9600, 4800, 2400, 1800, 1200, 600, 300, 200, 150, 134, 110, 75 o 50. Por defecto se establece una velocidad de 9600 baudios.

  • 'bits' - número de bits de los datos - pueden ser 8, 7, 6 o 5. Por defecto se establece un valor de 8 bits.

  • 'stop' - bits de stop - pueden ser 1 o 2. Por defecto se establece un valor de 1 bit de stop.

  • 'parity' - bits de paridad - pueden ser 0, 1 o 2. Por defecto se establece un valor de 0 bits de paridad.

Valores retornados

No value is returned.

Ejemplos

Example #1 Configurar la velocidad de un puerto serie

<?php

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

dio_fcntl($fd,F_SETFLO_SYNC );

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

while (
1) {

  
$data dio_read($fd,256);

  if (
$data) {
      echo 
$data;
  }


?>



dio_truncate> <dio_stat
Last updated: Fri, 22 Aug 2008
 
add a note add a note User Contributed Notes
dio_tcsetattr
daniel widyanto (kunilkuda at gmail dot com)
01-Jul-2005 03:34
I'm using PHP to interface my AVR microcontroller in /dev/ttyS0. I bet someone else does the same.

Here's some hint :
- dio_tcsetattr -> is set to enable :
            - RTS / CTS hardware control
            - ICANON mode
              (means that dio_read will wait until 0x0A/LF or other control character is entered in /dev/ttyS0 before it returns reading result, when you use dio_write it will also send 0x0A/LF automatically in the end of the message to your device).

For those who dont need RTS/CTS and/or ICANON, you can use linux command : stty.

Here's mine :

<?php
        exec
('stty -F /dev/ttyS0 4800 raw');

       
$fd=dio_open('/dev/ttyS0',O_RDWR | O_NOCTTY | O_NDELAY);
       
dio_fcntl($fd,F_SETFL,0);

       
dio_write($fd,"\x41",1);  // write 0x41 or 'A' to /dev/ttyS0
       
        // Replace result_length with your expected command result length
       
for ($i=0;$i < result_length;$i++) {
              
$result .=dio_read($fd, 1);
        }
        echo
$result;
?>

Refer to :
- Serial Programming Guide for POSIX Operating Systems, http://www.easysw.com/~mike/serial/
- stty man pages
fherrero at noticiasdenavarra dot com
02-Apr-2005 02:30
For Windows the Example 1 looks same this one:

<?php

exec
('mode com1: baud=9600 data=8 stop=1 parity=n xon=on');
// execute 'help mode' in command line of Windows for help

$fd = dio_open('com1:', O_RDWR);

while (
1) {

 
$data = dio_read($fd, 256);

  if (
$data) {
     echo
$data;
  }
}

?>
healer at colorado dot edu
20-Jul-2003 12:37
It was frustrating at first because I was trying to get my Linux box to talk to an external serial device (a PIC18F452 programmable chip) and the example provided here refers to fcntl() and open() parameters that aren't in the PHP documentation.

I finally found out what does what through the man pages:

man open
man fcntl

still haven't gotten it to work, or how to reset the ttySx, but thought it may help someone...

dio_truncate> <dio_stat
Last updated: Fri, 22 Aug 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites