Difference between revisions of "Talk:Сериен порт"

From Ilianko
Line 1: Line 1:
 
==php==
 
==php==
  
 +
Инсталира се ser2net и се конфигурира ser2net.conf
  
=== Direktno ===
+
После се достъпва като стандартен сокет
Setup serial port
 
<code><pre>
 
stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts
 
</pre></code>
 
 
 
  
 
<code><pre>
 
<code><pre>
<?php
 
 
 
if(isset($_POST['message']))
 
if(isset($_POST['message']))
 
{
 
{
   $fp =fopen("/dev/ttyS0", "w");
+
   $fp =fsockopen("localhost", 2000);
 +
 
 
   if( !$fp) {
 
   if( !$fp) {
 
     echo "Error";die();
 
     echo "Error";die();
 
   }
 
   }
 +
  fread($fp, 128);
 +
  fwrite($fp, "$_POST[message]");
 +
  $status = fread($fp, 128);
 +
  fclose($fp);
 +
  
  fwrite($fp, "$_POST[message] \n");
 
  fclose($fp);
 
 
}
 
}
  
Line 28: Line 26:
 
<form name="serial" action="" method="post">
 
<form name="serial" action="" method="post">
 
Message:  <input name="message" type="text"><input type="submit" value="Send">
 
Message:  <input name="message" type="text"><input type="submit" value="Send">
 +
 +
<?= (isset($status))? $status:'' ?>
 
</form>
 
</form>
 
</body>
 
</body>
 
</html>
 
</html>
 
</pre></code>
 
</pre></code>
 
 
=== Със [http://ilianko.com/files/php_serial.class.php php_serial.class] ===
 
 
<code><pre>
 
<?php
 
    include "php_serial.class.php";
 
 
    // Let's start the class
 
    $serial = new phpSerial();
 
 
    // First we must specify the device. This works on both Linux and Windows (if
 
    // your Linux serial device is /dev/ttyS0 for COM1, etc.)
 
    $serial->deviceSet("/dev/ttyUSB0");
 
 
    // Set for 9600-8-N-1 (no flow control)
 
    $serial->confBaudRate(9600); //Baud rate: 9600
 
    $serial->confParity("none");  //Parity (this is the "N" in "8-N-1")
 
    $serial->confCharacterLength(8); //Character length    (this is the "8" in "8-N-1")
 
    $serial->confStopBits(1);  //Stop bits (this is the "1" in "8-N-1")
 
    $serial->confFlowControl("none");
 
 
    // Then we need to open it
 
    $serial->deviceOpen();
 
 
    // Read data
 
    $read = $serial->readPort();
 
 
    // Print out the data
 
    echo $read;
 
 
    // If you want to change the configuration, the device must be closed.
 
    $serial->deviceClose();
 
?>
 
</pre></code>
 
 
  
 
== [http://ilianko.com/files/Serial.zip C#] ==
 
== [http://ilianko.com/files/Serial.zip C#] ==

Revision as of 16:31, 25 February 2013

php

Инсталира се ser2net и се конфигурира ser2net.conf

После се достъпва като стандартен сокет

if(isset($_POST['message']))
{
  $fp =fsockopen("localhost", 2000);
  
  if( !$fp) {
    echo "Error";die();
  }
  fread($fp, 128);
  fwrite($fp, "$_POST[message]");
  $status = fread($fp, 128);
  fclose($fp);


}

?>
<html><head></head>
<body>
<form name="serial" action="" method="post">
Message:  <input name="message" type="text"><input type="submit" value="Send">

<?= (isset($status))? $status:'' ?>
</form>
</body>
</html>

C#