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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.