Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 471
  • Last Modified:

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

<?php

$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
0
abdul_baig
Asked:
abdul_baig
  • 2
2 Solutions
 
TeRReFCommented:
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().
0
 
kaliyugkaarjunCommented:
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
0
 
TeRReFCommented:
What use is it to just repeat my answer kaliyugkaarjun ?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now