Website: http://www.thebyteworks.com
Installation:
- download from website
- unzip php_ser.zip and place php_ser++.dll file in PHP extension folder.
For PHP5 this is usualy: drive:\PHP_install_folder\ext\
Example: C:\PHP\ext\
- find php.ini file (usualy placed in C:\Windows folder) and open it
- fill extension_dir directive with extension folder, for example:
extension_dir= ".\ext"
- fill an extension directive to load php_ser automatically:
extension=php_ser++.dll
- save and close php.ini file
- test with php_ser_test.php file (included in distribution), which lists functions
Important notice
The correct extension version must be used to pair with PHP version. For example there is
one extension version that works with PHP 5.2.0 to 5.2.11 and one extension version that
works with 5.3.0.
string ser_version( void )
Returns extension version as string, example 20091007.1.
Note:
The trial version returns also word TRIAL and input and output usage (for TRIAL version there
is a maximum of 1024 bytes that can be read and write). Example:
20091007.1 TRIAL 534 in 234 out
void ser_open( string port, int baudrate, int databits, string parity, string stopbits, string flowcontrol )
Opens serial port.
port: a valid port name, in upper case, such as "COM3"
baudrate: valid baudrates are: 110,300,600,1200,2400,4800,9600,14400,19200,38400,56000,57600,115200
databits: valid databits are: 5, 6, 7, 8
parity: valid parities are: "None", "Odd", "Even", "Mark", "Space"
stopbits: valid stopbits are: "1", "1.5", "2"
flowcontrol: valid flowcontrols are: "None", "CtsRts", "CtsDtr", "DsrRts", "DsrDtr", "XonXoff"
Example:
ser_open( "COM1", 115200, 8, "None", "1", "None" );
Note:
1. For ports higher than 9 use an escape sequence as below:
ser_open("\\\\.\\COM10", 9600, 8, "None", "1", "None");
2. For the TRIAL version there is an intentional delay at port opening of several seconds.
3. If PHP is not runing as CGI you can leave the port open between script runs to accumlate data,
however think at buffer overuns.
bool ser_isopen( void )
Returns a bool value describing the port status.br>
Example:
if (ser_isopen()) echo "Port is open!."
Outputs following string on web page: Port is open!
void ser_close( void )
Closes serial port.
Note:
If PHP is not runing as CGI you can leave the port open between script runs to accumlate data,
however think at buffer overuns.
void ser_setDTR( bool Signal_state )
Set DTR signal as specified by Signal_state parameter, true or false.
Example:
ser_setDTR( True );
This procedure raises DTR.
void ser_setRTS( bool Signal_state )
Set RTS signal as specified by Signal_state parameter, true or false.
Example:
ser_setRTS( True );
This procedure raises RTS.
int ser_write( string data )
Writes data string to the serial ports.
Returns the number of written data.
Example:
ser_write( "Hello from PHP" );
This procedure sends "Hello from PHP" to serial port.
int ser_writebyte( byte data )
Writes data byte to the serial ports.
Returns the number of written data.
Example:
ser_write( 0 );
This procedure sends byte 0 to serial port.
int ser_inputcount( void )
Returns number of bytes available to be read in input buffer.
Example:
$nr = ser_inputcount( );
echo "$nr bytes available";
Outputs following string on web page: 17 bytes available.
string ser_read( void )
Reads data available in serial port input buffer, without waiting.
Example:
$str = ser_read();
echo "Received: $str";
Outputs following string on web page: Received: Hello from PHP.
string ser_readbyte( )
Reads one byte form serial port input buffer, without waiting.
Example:
$b = ser_readbyte();
printf('Received: %X', $b);
Outputs following string on web page: Received: 0D.
void ser_flush(boolean inbuffer, boolean outbuffer)
Clears input and/or output buffers.
Example:
ser_flush(true,true);
Software is in continuous development, please check website for updates.
Copyright 2006-2012, Cosmin Buhu http:/www.thebyteworks.com