Jump to content

access /dev/ttyS0 using php


kumandigital

Recommended Posts

Hello..

first i'm sorry for my bad english.

i try to access serial port under debian linux box using php direct IO.

 

<?php
$fd = dio_open('/dev/ttyS0', O_RDWR | O_NOCTTY | O_NONBLOCK);
dio_close($fd);
?> 

 

but i get warning like this:

Warning: dio_open() [function.dio-open]: cannot open file /dev/ttyS0 with flags 2306 and permissions 0: Permission denied in /var/www/latihan/serial/test.php on line 2

Warning: dio_close() expects parameter 1 to be resource, boolean given in /var/www/latihan/serial/test.php on line 3

 

can you help me to solve my problem??

thanks before.

 

Link to comment
https://forums.phpfreaks.com/topic/162558-access-devttys0-using-php/
Share on other sites

Like the error says, permission is denied.  You will either need to change the permissions on /dev/ttyS0, or you will need to run PHP as a different user.

 

 

If you are running PHP on the command line, you should be able to do:

 

sudo php /path/to/file.php

 

 

If you go the permissions-changing route, you will want to look into chmod.

If you go the permissions-changing route, you will want to look into chmod.

 

Or just change the owner with chown.

 

 

Yeah, but I wouldn't want to change the owner of the serial port.  Perhaps change the group owner and put the user PHP runs under in the group, but I don't like to change the owner from root in cases like that.  Maybe I'm just weird haha.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.