Results 1 to 1 of 1

Thread: Read Serial Port with PHP

  1. #1
    Join Date
    May 2013
    Beans
    1

    Angry Read Serial Port with PHP

    Hi,

    I'm new at linux world and i'm basically trying to talk with a device with PHP.
    The script is working fine, but i can't read the "answer" from the device.

    PHP CODE:
    Code:
    <?php
    $fp = fopen("/dev/ttyUSB0", "r+");
    if(!$fp)
    {
            echo "something wrong";
            die();
    }
    
     fwrite($fp, "command\r");  // this works, sends a command to device
     $buffer = fread($fp,1024); //doesn't work, page just start loading and nothing happens
     //$buffer = fgets( $fp ); // same here
    fclose($ficheiro);
    ?>

    stty result ( stty -F /dev/ttyUSB0 ):
    Code:
    speed 9600 baud; line = 0;
    kill = ^H; eof = ^A; min = 1; time = 0;
    -icrnl ixoff ixany -imaxbel
    -opost -onlcr
    -isig -icanon -echo -echoe
    setserial result ( setserial -av /dev/ttyUSB0 ):
    Code:
    /dev/ttyUSB0, Line 0, UART: unknown, Port: 0x0000, IRQ: 0
        Baud_base: 9600, close_delay: 12, divisor: 0
        closing_wait: none
        Flags: spd_normal


    Any sugestions? I don't know if is a linux setting or a php problem...
    Last edited by Unknown7; May 26th, 2013 at 05:49 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •