User Tools

Site Tools


uphp:functions:f485open

This is an old revision of the document!


f485open

WMPRO, WMMINI FW >= 1.922 WMMEGA FW >= 2.0

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

Description

int f485open ( int $baud, int $parity )

Attempt to open the RS-485 port as a stream, and return the file handle for future operations

In order to use the RS-485 port, you need to disable modbus polling (see Using the RS-485 Serial Port).

Parameters

baud: Rate in bits per second

parity: 0 (even parity) or 1 (odd parity)

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 RS-485 port fails it will return 0

Example

Open the 485 port at 115200 baud with even parity:

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

See Also

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

fseropen() - Open the serial port at the specified baud rate with optional parameters

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

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