note 54346 added to function.dio-tcsetattr
| From: | (kunilkuda@gmail.com) | Date: | Fri, 01 Jul 2005 01:34:31 +0000 |
| Subject: | note 54346 added to function.dio-tcsetattr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91228@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.dio-tcsetattr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54346
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54346&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54346&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54346&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54346&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54346&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54346&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54346&report=yes
Search -- http://master.php.net/manage/user-notes.php