SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    com port, serial port and serial port

    Is there any function on php to read the on the above port to communicate with the device attached to a computer? my program will execute in server side, but i need to read the device in client side? I send to send to commend to the device and reseived back the respond from device ?

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP cannot access anything on the client machine - it is strictly server-side. I think your only option for this kind of thing over the web is via ActiveX controls, which of course only work in IE.
    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have came across that php can talking to device through serial port to server, reference : http://www.sitepoint.com/forums/showthread.php?t=333532.

    according to http://www.sitepoint.com/forums/showthread.php?t=66620,
    we can have third party tool to read and write the serial port contents to ip socket, and then use php to read from ip socket.

    appreciated for any cmments.

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i found the following code at http://php.chinaunix.net/manual/zh/function.fopen.php
    which stated how to open serial port in linux,
    but according to user feedback,
    using fopen("COM1:", "r+"); can open the serial port in windows,
    any guru experience this before, please let me have the information.
    thank you

    PHP Code:
    <?php
    // HOW TO USE PHP TO WRITE TO YOUR SERIAL PORT: TWO METHODS
    $serproxy=true;
    if (
    $serproxy) {
        
    // Use this code in conjunction with SERPROXY.EXE 
        // (http://www.lspace.nildram.co.uk/freeware.html)
        // which converts a Serial stream to a TCP/IP stream
        
    $fp fsockopen ("localhost"5331$errno$errstr30);
        if (!
    $fp) {
            echo 
    "$errstr ($errno)";
        } else {
            
    $e chr(27);
            
    $string  $e "A" $e "H300";
            
    $string .= $e "V100" $e "XL1SATO";
            
    $string .= $e "Q1" $e "Z";
            echo 
    $string;
            
    fputs ($fp$string );
            
    fclose ($fp);
        }
    } elseif (
    $com1) {
        
    // Use this code to write directly to the COM1 serial port
        // First, you want to set the mode of the port. You need to set
        // it only once; it will remain the same until you reboot.
        // Note: the backticks on the following line will execute the 
        // DOS 'mode' command from within PHP
        
    `mode com1: BAUD=9600 PARITY=N data=8 stop=1 xon=off`;
        
    $fp fopen ("COM1:""w+");
        if (!
    $fp) {
            echo 
    "Uh-oh. Port not opened.";
        } else {
            
    $e chr(27);
            
    $string  $e "A" $e "H300";
            
    $string .= $e "V100" $e "XL1SATO";
            
    $string .= $e "Q1" $e "Z";
            echo 
    $string;
            
    fputs ($fp$string );
            
    fclose ($fp);
        }
    }
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •