Hi

OS = Redhat 9
PHP version = 4.2.2
Error message = Warning: dio_open(): cannot open file /dev/ttyS0 with flags 2306 and permissions 0: Permission denied in /home/serial_port_write.php on line 4

As you can see I am desperatly trying to work out how to write to the serial port using PHP however I seam to have the wrong permissions to run the script. I have tried inside and out side the web dir and also seting the GID and UID to root and also the user and also the permissions on the file and dir to chmod 777 however no matter what I do I can't seam to be able to call this cmd. Can someon please help me with setting the write permisions and ownership of the file so that I can talk to the serial port using dio_open(). This is my code

<?php
exec('stty -F /dev/ttyS0 4800 raw'); // stty terminal -F = device /dev/ttyS0 = serial port 4800 = speed

$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;
?>

    <?php 
    
    // stty terminal -F = device /dev/ttyS0 = serial port 4800 = speed 
    exec( 'stty -F /dev/ttyS0 4800 raw' );
    
    $fd=dio_open( '/dev/ttyS0', O_RDWR | O_NOCTTY | O_NDELAY ); 
    dio_fcntl( $fd, F_SETFL, 0 );
    
    // write 0x41 or 'A' to /dev/ttyS0  
    dio_write( $fd, "\x41", 1 ); // Replace result_length with your expected command result length for ($i=0;$i < result_length;$i++) { $result .= dio_read( $fd, 1 ); } echo $result; ?>

    I use TV with COLOR. Not black/white.
    How about you?
    🙂 🙂

      Write a Reply...