Results 1 to 4 of 4

Thread: -

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User a_panov's Avatar
    Join Date: Mar:2005
    Location: Sofia
    Posts: 45

    -



    - .
    :
    1 - :
    DSL Linux, 2.4 , XAMPP "--enable-dio", php.ini e . . /dev/ttyS0 e 666 rw- rw- rw-. :
    echo "12345" > /dev/ttyS0
    :
    cat /proc/tty/drivers/serial
    tx 5 rx 5 .

    , . , . :
    cat /proc/tty/drivers/serial
    tx rx .

    1 - :
    Decian Linux, 2.6 , XAMPP ( ) "--enable-dio", php.ini e . . /dev/ttyS0 e 666 rw- rw- rw-. :
    echo "12345" > /dev/ttyS0
    :
    cat /proc/tty/drivers/serial
    tx rx , 0.

    , "12" ( ) :
    Writing ...
    4 bytes written.
    Try to read ...Read miss...
    Read miss...
    Read miss...
    Read miss...
    Read miss...
    Read miss...
    , !!! :
    cat /proc/tty/drivers/serial
    tx rx , 0.

    dio. , UPS-. , . .

    :
    -
    -
    -
    e :
    http://www.karatebulgaria.com/alex/

    Code:
    <?php
    
    if(!empty($_POST['command_text']))
    {
     $dio_file_name = "/dev/ttyS0";
     
     $dio_file_desc = dio_open($dio_file_name, O_RDWR);//O_CREAT | O_APPEND, O_WRONLY);
     dio_tcsetattr($dio_file_desc, array("baud" => 9600, "bits" => 7, "stop" => 2, "parity" => 2));
     
     $text = $_POST['command_text']."*".chr(13);
     $write_num = dio_write($dio_file_desc, $text);
     echo "Writing ...<br>";echo "".$write_num." bytes written.<br>";
     dio_close($dio_file_desc);
    sleep(1);
     echo "Try to read ...";
     
     $dio_file_desc = dio_open($dio_file_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
     # $dio_file_desc = dio_open($dio_file_name, O_NONBLOCK, O_RDONLY);
     dio_tcsetattr($dio_file_desc, array("baud" => 9600, "bits" => 7, "stop" => 2, "parity" => 2));
     
     $read_miss_counter = 0;
     while(($dio_read = dio_read($dio_file_desc, 1)) != chr(13))
     {
      if($dio_read == "")
      {
       $read_miss_counter++;
       if($read_miss_counter == 20)
       {
        break;
       }
       else 
       {
        echo "Read miss...<br>";
     #   sleep(1);
       }
      }
      else 
      {
       echo "Read \"".$dio_read."\"<br>";
      }
     }
     dio_close($dio_file_desc);
    
    }
    else 
    {
    ?>
    
    <form method = "post">
     (  ): <input type = 'text' name = 'command_text' maxlength= '131' value = "">
    <input type = "submit" name = "submit_button" value = "Go!">
    </form>
    <?php
    }
    ?>
    Last edited by a_panov; 8th September 2007 at 12:52. Reason:

  2. #2
    Registered User
    Join Date: Jul:2006
    Location:
    Posts: 480
    PHP ? The wrong tool for the job. .

  3. #3
    philosophus duratea icaci's Avatar
    Join Date: Oct:2006
    Location: Aachen
    Posts: 2,698
    C++ - CGI (WEB , ),

    @a_panov, , , . dio_tcsetattr() dio, tcsetattr(3) tcflush(3) TCIFLUSH, loopback- dio_read(). dio_close(), dio_open() dio_tcsetattr(). , .. , - , .

    (), (IRQ, I/O ..). setserial ( ) , ..
    Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others

  4. #4
    Registered User a_panov's Avatar
    Join Date: Mar:2005
    Location: Sofia
    Posts: 45
    Quote Originally Posted by icaci View Post
    C++ - CGI (WEB , ),

    @a_panov, , , . dio_tcsetattr() dio, tcsetattr(3) tcflush(3) TCIFLUSH, loopback- dio_read(). dio_close(), dio_open() dio_tcsetattr(). , .. , - , .

    (), (IRQ, I/O ..). setserial ( ) , ..
    . .

    dio_write dio_read '' Php.net .

    Code:
    <?php
    if(!empty($_POST['command_text']))
    {
    
        $dio_file_name = "/dev/ttyS0";
    
    /*            */
        exec("stty 9600 parenb -parodd cs7 cstopb cread clocal -crtscts -ixon -ixoff -echo icanon -F /dev/ttyS0");
    
        $dio_file_desc = dio_open($dio_file_name, O_RDWR | O_NDELAY | O_NOCTTY);
        dio_fcntl($dio_file_desc, F_SETFL, 0);
    
        $text = $_POST['command_text']."*".chr(13);
        $write_num = dio_write($dio_file_desc, $text);
        echo "Writing ...<br>";echo "".$write_num." bytes written.<br>";
    
        echo "Try to read ...<br>";
    
        $dio_read1 = dio_read($dio_file_desc, 256);
        echo "Read: ".$dio_read1;
    
        dio_close($dio_file_desc);
    
    }
    else
    {
    ?>
    
    <form method = "post">
    Enter Command: <input type = 'text' name = 'command_text' maxlength= '131' value = "">
    <input type = "submit" name = "submit_button" value = "Go!">
    </form>
    <?php
    }
    ?>
    - , LF dio_Read :
    Code:
    <?php
    if(!empty($_POST['command_text']))
    {
    
       $dio_file_name = "/dev/ttyS0";
    
       exec("stty 9600 parenb -parodd cs7 cstopb cread clocal -crtscts -ixon -ixoff -echo raw -F /dev/ttyS0");
    
       $dio_file_desc = dio_open($dio_file_name, O_RDWR | O_NDELAY | O_NOCTTY);
       dio_fcntl($dio_file_desc, F_SETFL, 0);
    
        $text = $_POST['command_text']."*".chr(13);
        $write_num = dio_write($dio_file_desc, $text);
        echo "Writing ...<br>";echo "".$write_num." bytes written.<br>";
    
       echo "Try to read ...<br>";
    
    /*  LF     dio_read */
       dio_write($dio_file_desc,"\x41",1);
       $dio_read1 = dio_read($dio_file_desc, 256);
       echo "Read: ".$dio_read1;
    
       dio_close($dio_file_desc);
    
    }
    else
    {
    ?>
    
    <form method = "post">
    Enter Command: <input type = 'text' name = 'command_text' maxlength= '131' value = "">
    <input type = "submit" name = "submit_button" value = "Go!">
    </form>
    <?php
    }
    ?>
    spec. char , 2- , php dio , ... - ... , php .. .

    "" -> \0 , , , , , ...



    . exec() . , .

Posting Permissions

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

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |