User Tools

Site Tools


uphp:functions:fseropen

fseropen

WMPRO FW >= 1.0 WMMEGA FW >= 2.0

Open the serial port at the specified baud rate with optional parameters

Description

int fseropen ( int $baud [, int $blocking [, int $invert [, int $parity ]]] )

Attempt to open the serial port, and return the file handle for future operations

Parameters

$baud: Rate in bits per second

$blocking: Optional, if set to 1 read operations will block until data is available

$invert: Optional

$parity: Optional, 0 (even parity) or 1 (odd parity)

Return Values

Integer: File handle, or 0 if the attempt to open the serial port fails

The file handle may be used together with the other file functions that require a handle such as fgets(), fwrite(), fclose() and feof()

Example

Open the serial port at 115200 baud in non-blocking mode

<?
  $fp=fseropen(115200);
  if ($fp) {
    $res=fwrite($fp,"Hello from wattmon");
    if ($res) {
      print("An error occurred while trying to write to the port");
    }
    fclose($fp);
  } else {
    print("Serial open failed");
  }
?>

Also See

Serial Port Programming - Some information on connecting and using the serial ports

fopen() - Open a file for reading or writing

f485open() - Open the RS-485 port at the specified baud rate and parity

fsockopen() - Open an internet socket connection with optional timeout

fread() - Read bytes from a file, stream or socket

fgets() - Return a single line from a file, stream or socket, with optional size limit

fwrite() - Write data to a file, stream or socket

feof() - Test if no more data is available in a file, stream or socket

filesize() - Return the size of a file, or the number of unread bytes in a stream or socket

fseek() - Position the file pointer in an open file

ftell() - Return the current position of a file read/write pointer

fclose() - Close a file, stream or socket

uphp/functions/fseropen.txt · Last modified: 2021/09/13 05:57 (external edit)