======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 [[how_tos:Serial Port Programming#Using the RS-485 Serial Port]]).
====Parameters====
$baud: Rate in bits per second
$parity: 0 (even parity) or 1 (odd parity)
====Return Values====
Integer: File handle, or 0 if the attempt to open the RS-485 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 485 port at 115200 baud with even parity===
$fp=f485open(115200,0);
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====
[[how_tos:Serial Port Programming]] - Some information on connecting and using the serial ports
[[fopen()]] - Open a file for reading or writing
[[fseropen()]] - Open the serial port at the specified baud rate with optional parameters
[[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