我需要通过串口连接到APC备份并从中获取任何值。
如何将PHP连接到串口?
我正在使用S.O Ubuntu 13.04,这个测试在我的电脑上直接连接到APC。
答案 0 :(得分:0)
尝试使用这两个链接,真棒:
http://wirespeed.xs4all.nl/mediawiki/index.php/Udev_rules_file_for_Arduino_boards
http://wirespeed.xs4all.nl/mediawiki/index.php/Cat_ttyUSB0
答案 1 :(得分:0)
用这个来测试你:
<?php
/**
*
*/
/ Set up serial open -
$fp =fopen("/dev/ttyUSB", "w");
//check the GET actions variable to see if something needs to be done
if (isset($_GET['action'])) {
//Action has been requested
//Issue the command we wish to send to the Arduino
if ($_GET['action'] == "true") {
//UP LED true - for this simple script we are just looking for either a 1 or 0
fwrite($fp, chr(1));
} else if ($_GET['action'] == "false") {
//Down LED off
fwrite($fp, chr(0));
}
//We're done, so close the serial port again
fclose($fp);
}
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Arduino LED control</title>
</head>
<body>
<h1>LED Control system - Arduino Interface</h1>
<p><a href="<?=$_SERVER['PHP_SELF'] . "?action=true" ?>">
Turn LED On.</a></p>
<p><a href="<?=$_SERVER['PHP_SELF'] . "?action=dalse" ?>">
Turn LED Off.</a></p>
</body>
</html>