PHP.mk документација

dio_tcsetattr

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.dio-tcsetattr.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.dio-tcsetattr.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
dio_tcsetattr

Референца за `function.dio-tcsetattr.php` со подобрена типографија и навигација.

function.dio-tcsetattr.php

dio_tcsetattr

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

dio_tcsetattr Поставува атрибути на терминалот и брзина на серискиот порт

= NULL

dio_tcsetattr(resource $fd, array $options): bool

dio_tcsetattr() ја поставуваат атрибутите на терминалот и брзината на отворениот fd.

Параметри

fd

Дескрипторот на датотеката вратен од dio_open().

options

Моментално достапни опции се:

  • 'baud' - брзина на портот - може да биде 38400,19200,9600,4800,2400,1800, 1200,600,300,200,150,134,110,75 или 50, стандардна вредност е 9600.

  • 'bits' - data bits - може да биде 8,7,6 или 5. Стандардна вредност е 8.

  • 'stop' - stop bits - може да биде 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 (
true) {
$data = dio_read($fd, 256);
if (
$data !== null && $date !== '') {
echo
$data;
}
}

?>

Белешки

Забелешка: Оваа функција не е имплементирана на платформите Windows.

Белешки од корисници 3 белешки

daniel widyanto (kunilkuda at gmail dot com)
20 години пред
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
healer at colorado dot edu
пред 22 години
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...
fherrero at noticiasdenavarra dot com
20 години пред
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;
  }
}

?>
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.