www.webdeveloper.com
Results 1 to 7 of 7

Thread: insert data from com port into textbox php

  1. #1
    Join Date
    May 2007
    Posts
    8

    insert data from com port into textbox php

    I read where this is an easy task but to a newbe, it isn't that easy. I have a scale attached to computer with RS232. I need a php script to read the weight into a text box.

    I found the following:

    include "php_serial.class.php";
    $serial = new phpSerial;
    $serial->deviceSet("COM1");
    $serial->confBaudRate(2400);
    $serial->confParity("none");
    $serial->confCharacterLength(8);
    $serial->confStopBits(1);
    $serial->confFlowControl("none");
    $serial->deviceOpen();
    $read = $serial->readPort();
    $serial->deviceClose();
    $serial->confBaudRate(2400);
    // etc...

    But how do I echo the data?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    From your code, it looks like $read should contain the data from the port.

    Try a var_export() of it to see what data it contains and how it's structured, e.g.:
    PHP Code:
    echo "<pre>".var_export($readtrue)."</pre>"
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    May 2007
    Posts
    8
    Tried that...again, didn't work. I know my computer can read the com port 1.

  4. #4
    Join Date
    May 2007
    Posts
    8
    So I tried this:

    PHP Code:

    error_reporting
    (E_ALL);

    $fp fopen('COM1''r+');

    if(!
    fp){
     echo 
    "Port not accessible";
    } else {
    echo 
    "Port COM1  opened.";
    }

    $output "mode COM1: BAUD=1200 PARITY=Even data=7 stop=1 Xon=off  ";

    $buffer fgets($fp);

    echo 
    "Read: $buffer"
    Port is open but no $buffer and no errors.

  5. #5
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    Do you need to fput() your output first? (I'm by no means a COM port expert -- haven't touched that stuff in a bunch of years. )
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  6. #6
    Join Date
    May 2007
    Posts
    8
    Not sure what you mean?

  7. #7
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,921
    You assign a string to the variable $output, but you don't actually do anything with it. I thought maybe you meant to output that string to the COM port, in which case I believe that could be done via fputs() or fwrite() (fputs is just an alias of fwrite).

    Or I could be completely wrong.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles