How do I read from a serial port?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pnberry@gmail.com

    How do I read from a serial port?

    Newbie here,

    I've got a digital scale attached to the first serial port of my Linux
    OS computer: /dev/ttyS0
    How would I set up the serial port for reading data and then how would
    I turn that data into a variable that I could use in a PHP program?

    Thanks for any help,
    Paul

  • adlerweb

    #2
    Re: How do I read from a serial port?

    Hi

    If your scale uses the same settings as your OS (speed, etc) it should
    be enough to fopen /dev/ttyS0 and use it like a file. Note: You can not
    read and write with one socket - in this case you have to use two.

    Example:

    $string = "foobar\n";
    $pointer = fopen("/dev/ttyS0","w");
    fwrite ($pointer, $string);
    fclose($pointer );

    Florian

    pnberry@gmail.c om schrieb:
    Newbie here,
    >
    I've got a digital scale attached to the first serial port of my Linux
    OS computer: /dev/ttyS0
    How would I set up the serial port for reading data and then how would
    I turn that data into a variable that I could use in a PHP program?
    >
    Thanks for any help,
    Paul
    >

    Comment

    Working...