主框架 / 串行
在PHP中与串行设备通信
dev-master
2014-02-02 19:58 UTC
Requires
- psr/log: 1.0.*@dev
This package is not auto-updated.
Last update: 2024-09-28 14:41:04 UTC
README
在PHP中与来自各种平台的串行设备通信。
获取方式
获取 Composer。使您的项目需要串行。
composer require themainframe/serially dev-master
示例
ConnectionManager
类允许您通过抽象平台检测过程来编写与串行兼容的代码。
getConnection
方法返回一个实现 ConnectionInterface
的连接实例,适用于当前平台。
$manager = new ConnectionManager;
$connection = $manager->getConnection('/dev/ttyS0');
$connection->writeLine('Hello from PHP');
日志记录
调试串行设备和它们之间的通信可能很困难。串行使用符合 PSR-3 的 LoggerInterface
日志记录,使过程更容易。
// $myLogger implements LoggerInterface
// Connections created with this manager will be logged to $myLogger
$manager->setLogger($myLogger);
限制
读取 从串行端口读取字节在PHP中是一个挑战。根据平台的不同,您可能会观察到在调用 readLine()
或 readByte()
之前接收到的数据可能不可用。
平台 灵活性还在开发中。 PlatformSpecific
命名空间包含针对 Mac OS X (Darwin) 和 Linux 的特定平台连接实现(ConnectionInterface
)。Windows 版本可能很快就会出现。
归属与感谢
- 受到 rubberneck 的 php-serial 的极大启发。