User Tools

Site Tools


uphp:functions:fseropen

This is an old revision of the document!


fseropen

WMPRO, WMMINI 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

Return Value

Upon success it returns a file handle which may be used together with the other file functions that require a handle such as fgets(), fwrite(), fclose() and feof()

If the attempt to open the serial port fails it will return 0

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");
}
?>

See Also

Serial Port Programming

f485open() - Open the RS-485 port as a stream

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

fopen() - Open a file for reading or writing

fclose() - Close a file, stream or socket

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

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

fread() - Return bytes from a file or stream

fwrite() - Write data to a file or stream

if - Flow control structure for conditional execution

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