php - 适用于 Windows 的 PHP 中串行类的 readPort 函数
问题描述
function readPort ($count = 0)
{
if ($this->_dState !== SERIAL_DEVICE_OPENED)
{
trigger_error("Device must be opened to read it", E_USER_WARNING);
return false;
}
if ($this->_os === "linux" || $this->_os === "osx")
{
// Behavior in OSX isn't to wait for new data to recover, but just grabs what's there!
// Doesn't always work perfectly for me in OSX
$content = ""; $i = 0;
if ($count !== 0)
{
do {
if ($i > $count) $content .= fread($this->_dHandle, ($count - $i));
else $content .= fread($this->_dHandle, 128);
} while (($i += 128) === strlen($content));
}
else
{
do {
$content .= fread($this->_dHandle, 128);
} while (($i += 128) === strlen($content));
}
return $content;
}
elseif ($this->_os === "windows")
{
/* Do nothing : not implented yet */
}
trigger_error("Reading serial port is not implemented for Windows", E_USER_WARNING);
return false;
}
我刚刚给出了来自 Github 的部分代码。这些代码是我唯一的兴趣点。如果你想查看源代码,这里是。
我正在寻找如何在 Windows 中将串口数据从 Arduino 读取到 PHP。在搜索了这么多时间后,我从 Github 找到了代码。但是在 windows 还没有实现 readPort() 的地方。
任何人都可以帮助我吗?
解决方案
推荐阅读
- python - 从finally块python访问try块中的变量
- javascript - 如何正确启用/禁用离子刷新器
- reactjs - 使用 React 单击图像时无法提醒工作
- material-ui - 试图创建一个可拖动的表/列表,它给了我一个错误,说“provided.innerRef 没有提供 HTMLElement。”
- c - CTRL-D 退出程序而不是循环
- c# - 用 2 次选择改进这个 Linq 到同一张表
- applescript - 使用 applescript 获取 Outlook 帐户的全名
- android - Xamarin - 在手机解锁事件中检测正确或不正确的 pin
- python - 如何在 Python 中创建 L2TP VPN 连接?
- nuget - NuGet 包多久更新一次?