Reading COM (Serial Modem) in PHP

泪湿孤枕 提交于 2020-01-02 04:35:07

问题


Reading COM (Serial Modem) in PHP

I'd need a COM interface (Windows,COM2) to read with PHP.

This Demo is going on. Reading is a problem, it's running sometimes.

Is there an other way (no dio,no C++) maybe w32api_register_function() is better?



    function rs232init($com,$bautrate)
    {
    `mode $com: BAUD=$bautrate PARITY=N data=8 stop=1 xon=off`;
    }

    function send($comport,$char)
    {

         $fp = fopen ("$comport", "w+");
         if (!$fp)
          {
             echo "not open for read";
          }
        else {
                fputs ($fp, $char);
                 fclose ($fp);
                }
    }

    function read($comport2,$sek)
    {

       $buffer = "";

       $fp2 = fopen ("$comport2", "r+");
         if (!$fp2)
         {
       echo "port is open for read";
       }
    else
      {
      sleep($sek);
             $buffer .= fgets($fp2, 4096);
            }
          return $buffer;
          fclose ($fp2);
}


rs232init("com2","9600");
send("com2","3"); 
$a = read("com2","2"); 
echo $a; 

回答1:


The com2 device should be referenced as 'COM2:'




回答2:


I should point out that there is a PHP serial class already available at http://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html.

I don't know what methods it uses internally, but perhaps it will make this a bit easier to get started.



来源:https://stackoverflow.com/questions/6370176/reading-com-serial-modem-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!