Solved

Serial Communication using php

Posted on 2006-06-15
4
537 Views
Last Modified: 2012-05-05

Can i write /read data on serial port using php....?if yes ...how .?
 what would be solution for windows and what for linux..

0
Comment
Question by:abdul_baig
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
ljubiccica earned 500 total points
ID: 16909917
from php manual (not my 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, $errstr, 30);
   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);
   }
}
?>
0
 
LVL 7

Expert Comment

by:ljubiccica
ID: 16909928
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Redirect 301 from one address  to another 5 26
Need to remove %20 from url in get 17 36
PHP 5.6 and 7.x 4 23
form validation - make sure at least 1 checkbox is selected 18 31
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question