有一个想法:用PHP程序做监控,要通过串口通讯,以前没有做过这块--大家来讨论一下

s_delhpi 2007-12-11 01:39:25
用串口通讯,如果采用vc,vb,delphi这个问题就比较容易解决,现在有个想法就是用php来做,这样的话就出现两个大的问题,一个是页面的刷新,一个是串口通讯。

请大家来讨论,这种做法可行吗?

刷新页面是否可以通过ajax来做呢?
...全文
249 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
s_delhpi 2007-12-11
  • 打赏
  • 举报
回复
不知道有人做过吗?实际效果怎么样
s_delhpi 2007-12-11
  • 打赏
  • 举报
回复
我想这样设计是否可以:

1. php程序完成串口数据的发送。
2. 用c编写服务在服务器运行,接收串口数据,更新数据库
3. ajax定请求检测数据库,数据更新则返回新数据,完成页面刷新(比如颜色改变、参数值改变)

这样的好处就是多处监控只需要在服务器安装一套程序,方便维护。
bigman_lfj 2007-12-11
  • 打赏
  • 举报
回复
1.php与com通讯
php官方站点提供了sample
link:http://jp.php.net/manual/zh/function.fopen.php
2.可以用ajax来刷新页面

sample:
<?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);
}
}
?>

21,893

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧