使用PHP的Linux托管服务器的串行COM端口问题 [英] Serial COM port issue with linux hosting server using PHP

查看:64
本文介绍了使用PHP的Linux托管服务器的串行COM端口问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// Change Parms on Comport: Linux: Windows
$command = (PHP_OS == 'Linux') ? 'mode /dev/ttyS1: BAUD=9600 PARITY=N data=8 stop=1 XON=off TO=on' : 'mode COM1: BAUD=9600 PARITY=N data=8 stop=1 XON=off TO=on';

system($command, $retVar);    

if($retVar == '127'){
    echo("Command not found:$command<br>");
    // May want to exit here.
}

//Create the resource id:  Linux: Windows
$path = (PHP_OS == 'Linux') ? '/dev/ttyS1' : 'COM1';
$fp = fopen($path, 'r+');

if(!$fp){ 
  echo"Port not accessible";
  exit();
} else {
  echo"Port COM1 opened successfully";
}

//Read from port:
$buffer = fgets($fp);

echo "<br>Data read from buffer: $buffer";





我尝试过:



因为我无法通过引用Linux服务器和Windows服务器来访问COM端口值。所以我可以通过引用Linux和Linux来解释所有需要设置的内容。 Windows Server。由于以下代码在localhost中正常工作。



因为我收到以下错误 -

命令未找到:mode / dev / ttyS1:BAUD = 9600 PARITY = N data = 8 stop = 1 XON = off TO = on

端口无法访问



What I have tried:

As I am not able access the COM port Value with references to Linux Server and windows server.So explain me what all setting need to made with references to Linux & windows Server.As this below code is working properly in localhost.

As I am getting the following error-
Command Not found:mode /dev/ttyS1: BAUD=9600 PARITY=N data=8 stop=1 XON=off TO=on
Port not accessible

推荐答案

command =(PHP_OS == ' Linux')? ' mode / dev / ttyS1:BAUD = 9600 PARITY = N data = 8 stop = 1 XON = off TO = on' ' 模式COM1:BAUD = 9600 PARITY = N data = 8 stop = 1 XON = off TO =上';

system(
command = (PHP_OS == 'Linux') ? 'mode /dev/ttyS1: BAUD=9600 PARITY=N data=8 stop=1 XON=off TO=on' : 'mode COM1: BAUD=9600 PARITY=N data=8 stop=1 XON=off TO=on'; system(


命令,


retVar);

if(
retVar); if(


这篇关于使用PHP的Linux托管服务器的串行COM端口问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆