tvelu77/php-serial 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tvelu77/php-serial

最新稳定版本:v1.0

Composer 安装命令:

composer require tvelu77/php-serial

包简介

Multi-platform convenience class to access the serial port from PHP for PHP 8+

README 文档

README

This project was created for a project at my work where a Symfony project needs to communicate to a machine through the COM port on Windows. After a long time, surfing the web, I found PHP-Serial made by Xowap.
However, when I found out that the project wasn't longer maintened and the pull requests weren't accepted, I decided to share some fixes and improvements ! Especially, a Windows fix, a PHP 8+ compatibility and a cleaner code (I think so, I don't know, Java is better :P).

I really hope it will help someone !

Of course, I am not the main author, all credits goes to Xowap.

Example

<?php
include 'PhpSerial.php';

// Let's start the class
$serial = new PhpSerial();

// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->deviceSet("COM1");

// We can change the baud rate, parity, length, stop bits, flow control
$serial->confBaudRate(2400);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");

// Then we need to open it
$serial->deviceOpen();

// To write into
$serial->sendMessage("Hello !");

// To read
$serial->readLine();

State of the project

Bugs

There is lots of bugs. I know there is. I just don't know which are they.

Platform support

  • Linux: need to be tested !
  • MacOS: need to be tested !
  • Windows: it should work, at least on a Windows server, it works :) !

Concerns

I have a few concerns regarding the behaviour of this code.

  • Inter-platform consistency. I seriously doubt that all operations go the same way across all platforms.
  • Auto-closing the device. There is an auto-close function that is registered at PHP shutdown. This sounds quite ridiculous, something has to be done about that.
  • Use exceptions.

Call for contribution

As in all open-source projects, I need people to fit this to their needs and to contribute back their code.

If you feel like doing any of those, do not hesitate to create an issue or a pull-request, I'll gladly consider consider it :)

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-only
  • 更新时间: 2024-06-21