kba-team / 串行端口
使用TCP连接连接到串行端口。
v1.0.0
2020-12-17 10:03 UTC
Requires
- php: ^7.2
- ext-json: *
- ext-sockets: *
Requires (Dev)
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-09-17 19:55:11 UTC
README
PHP类 \kbATeam\SerialPort\SerialPort
用于通过流连接到串行端口。仅实现了socket(TCP)流。
您需要创建实现 \kbATeam\SerialPort\Interfaces\Communication\Command
、\kbATeam\SerialPort\Interfaces\Communication\Container
和 \kbATeam\SerialPort\Interfaces\Communication\Value
的类。这些接口的实现取决于您想要与之通信的设备。
用法
使用 pySerial 将串行设备映射到TCP端口。
使用 Streams\Socket
创建到 SerialPort
的连接,使用 SerialPort->invoke()
调用一个 Communication\Command
并获取 NULL
或至少包含一个 Communication\Value
的 Communication\Container
。
Communication\Command
实例是发送到 SerialPort
实例的字符串。使用其 Stream
实例,SerialPort
实例调用 Communication\Command
。
您的 Communication\Command
实现需要定义如何读取设备返回的字符串,并返回至少包含一个 Communication\Value
的 Communication\Container
或 NULL
。