User Tools

Site Tools


uphp:functions:fseropen

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
uphp:functions:fseropen [2017/03/18 13:18]
jeff
uphp:functions:fseropen [2021/09/13 05:57] (current)
Line 1: Line 1:
 ======fseropen====== ======fseropen======
-<badge>WMPRO, WMMINI FW >= 1.0</badge> <badge>WMMEGA FW >= 2.0</badge>+ 
 +<badge>WMPRO FW >= 1.0</badge> <badge>WMMEGA FW >= 2.0</badge>
  
 Open the serial port at the specified baud rate with optional parameters Open the serial port at the specified baud rate with optional parameters
  
 ====Description==== ====Description====
-<well size="sm"><html><span style="font-size:125%;color:green;">int + 
-<span style="color:black;"></html>[[fseropen]] +<well size="sm"><html> 
-<html>+<span style="font-size:125%;color:green">int 
-<span style="color:green;">int +<span style="color:black">fseropen ( 
-<span style="color:blue;">$baud +<span style="color:green">int 
-<span style="color:black;">[, +<span style="color:blue">$baud 
-<span style="color:green;">int +<span style="color:black">[, 
-<span style="color:blue;">$blocking +<span style="color:green">int 
-<span style="color:black;">[, +<span style="color:blue">$blocking 
-<span style="color:green;">int +<span style="color:black">[, 
-<span style="color:blue;">$invert +<span style="color:green">int 
-<span style="color:black;">[, +<span style="color:blue">$invert 
-<span style="color:green;">int +<span style="color:black">[, 
-<span style="color:blue;">$parity +<span style="color:green">int 
-<span style="color:black;">]]] )+<span style="color:blue">$parity 
 +<span style="color:black">]]] )
 </html></well> </html></well>
  
Line 25: Line 27:
  
 ====Parameters==== ====Parameters====
-<html><span style="color:blue;"><b>baud</b><span style="color:black;"></html>:  Rate in bits per second 
  
-<html><span style="color:blue;"><b>blocking</b><span style="color:black;"></html>:  Optional, if set to 1 read operations will block until data is available+<html><b><span style="color:blue">$baud<span style="color:black"></b></html>:  Rate in bits per second
  
-<html><span style="color:blue;"><b>invert</b><span style="color:black;"></html>:  Optional+<html><b><span style="color:blue">$blocking<span style="color:black"></b></html>:  Optional, if set to 1 read operations will block until data is available
  
-<html><span style="color:blue;"><b>parity</b><span style="color:black;"></html>:  Optional+<html><b><span style="color:blue">$invert<span style="color:black"></b></html>:  Optional
  
-====Return Value==== +<html><b><span style="color:blue">$parity<span style="color:black"></b></html>:  Optional(even parityor 1 (odd parity)
-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+====Return Values====
  
 +<html><b><span style="color:green">Integer<span style="color:black"></b></html>:  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==== ====Example====
-Open the serial port at 115200 baud in non-blocking mode:+ 
 +===Open the serial port at 115200 baud in non-blocking mode=== 
 <code php> <code php>
 <? <?
-$fp=fseropen(115200); +  $fp=fseropen(115200); 
-if ($fp) { +  if ($fp) { 
-  $res=fwrite($fp,"Hello from wattmon"); +    $res=fwrite($fp,"Hello from wattmon"); 
-  if ($res) { +    if ($res) { 
-    print("An error occurred while trying to write to the port");+      print("An error occurred while trying to write to the port"); 
 +    } 
 +    fclose($fp); 
 +  } else { 
 +    print("Serial open failed");
   }   }
-  fclose($fp); 
-} else { 
-  print("Serial open failed"); 
-} 
 ?> ?>
 </code> </code>
  
-====See Also==== +====Also See====
-[[uphp:Serial Port Programming]]+
  
-[[f485open()]] - Open the RS-485 port as a stream+[[how_tos: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 [[fsockopen()]] - Open an internet socket connection with optional timeout
  
-[[fopen()]] - Open a file for reading or writing+[[fread()]] - Read bytes from a file, stream or socket
  
-[[fclose()]] - Close a file, stream or socket+[[fgets()]] - Return a single line from a file, stream or socket, with optional size limit
  
-[[feof()]] - Test if no more data is available in a file or stream+[[fwrite()]] - Write data to a filestream or socket
  
-[[fgets()]] - Return a single line from a file or stream, with optional size limit+[[feof()]] - Test if no more data is available in a file, stream or socket
  
-[[fread()]] - Return bytes from a file or stream+[[filesize()]] - Return the size of a fileor the number of unread bytes in a stream or socket
  
-[[fwrite()]] - Write data to a file or stream+[[fseek()]] - Position the file pointer in an open file
  
-[[uphp:control_structures:if]] - Flow control structure for conditional execution+[[ftell()]] - Return the current position of a file read/write pointer 
 + 
 +[[fclose()]] - Close a file, stream or socket
  
uphp/functions/fseropen.1489843135.txt.gz · Last modified: 2021/09/13 05:56 (external edit)