PHP Serial extension reference

Website: http://TheByteWorks.com

Jump to Function Reference

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
PHP must run as CGI. To find if you are running PHP as CGI and if you are using
correct php.ini please make a file like this in your web folder:

<html>
<head>
<title>
Local index page
</title>
</head>
<body>
<?php phpinfo(); ?>
</body>
</html>
Load it and look for information under Server API line (should be CGI/FastCGI),
Configuration File (php.ini) Path line; also win_serial_port module should appear in loaded
modules list.
To change how PHP is running, open Apache configuration file, example (change path):
C:\Apache\conf\httpd.conf

Comment this line:
#LoadModule php5_module "c:/Php/php5apache2.dll"

And add 2 new lines:
ScriptAlias /php/ "c:/php/"
Action application/x-httpd-php "/php/php-cgi.exe"

Save, and very important, restart Apache.

Notice for XAMPP users:
- XAMPP runs PHP as Apache module by default, must be changed to CGI mode
- changes must be made to conf/extra/httpd-xampp.conf file instead of /conf/httpd.conf
Locate lines like:
#ScriptAlias /php/ "C:/Program Files/xampp/php/"
#Action application/x-httpd-php "/php/php-cgi.exe"
LoadModule php5_module "C:/Program Files/xampp/apache/bin/php5apache2.dll"
AddType application/x-httpd-php-source .phps

Uncomment lines 1 and 2. Comment line 3. Restart Apache.

Functions reference:

string ser_version( void )
    Returns extension version as string, example 10032006.1.

void ser_open( string port, int baudrate, int databits, string parity, float 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,Hardware,Software
    Example:
    ser_open( "COM1", 115200, 8, "None", 1, "None" );

string ser_isopen( void )
    Returns a string describing port properties if open, empty string if closed<.br>     Example:
    $str = ser_isopen();
    echo "Port: $str";

    Outputs following string on web page: Port: COM3 115200 8 None 1 None.

void ser_close( void )
    Closes serial port.

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_write( string data )
    Writes data string to the serial ports.
    Example:
    ser_write( "Hello from PHP" );
    This procedure sends "Hello from PHP" to serial port.

string ser_read( int chars_no )
    Reads data from serial port until chars_no characters are received or timeout occurs.
    Example:
    ser_read(512);
    echo "Received: $str";

    Outputs following string on web page: Received: Hello from PHP.

Software is in continuous development, please check website for updates.

Copyright 2006, Cosmin Buhu