serial communication using php in linux

i am new in linux environment . i want to write data on serial port using PHP the code i have written is


$fp = fopen ("/dev/ttyS0", "w");

echo fput ($fp,128);


but the error has ocured that
Warning: fopen("/dev/ttyS0", "w") - Permission denied and Fatal error: Call to undefined function: fput()  kindly help me out
Who is Participating?
TeRReFConnect With a Mentor Commented:
The user the webserver runs under needs to have rights to access /dev/ttyS0. You can achieve this with chmod.
It's not fput(), but fputs().
kaliyugkaarjunConnect With a Mentor Commented:
1: $fp = fopen ("/dev/ttyS0", "w");
If you have logged in the system as root user then you will not have such permission problem..

Otherwise ..u have to login as a root user..
change the file permissions to have write access..
Just do one thing..change the file permissions to 333 using
chmod 333 /dev/ttyS0
2: echo fput ($fp,128);
Try using fputs($fp,128) or fwrite($fp,128)

This will work
What use is it to just repeat my answer kaliyugkaarjun ?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.