• Stars
    star
    339
  • Rank 124,272 (Top 3 %)
  • Language
    PHP
  • License
    GNU General Publi...
  • Created over 10 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

PHP Serial

PHP Serial was written at a time where I did not know any other language than PHP and I started to get seriously bored with its abilities.

I somehow got hold of a « Citizen C2202-PD » point-of-sale display, and I wanted to play around with it. I also managed to get the documentation of it, and created a convenience class to access the serial port though the Linux file.

Afterwards, I posted it to PHP Classes, and this probably is what brought it any visibility.

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 !");

State of the project

Interestingly enough, this piece of code that is widely untested has created a lot if interest ever since it was created, and especially nowadays with everybody toying around with Arduinos and Raspberry Pis. I receive about 1 email every month asking for help with the code or sending patches/suggestions.

I think that it is time for me to remove the dust off this project and to give it a full visibility on modern tools, aka GitHub.

Bugs

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

Platform support

  • Linux: the initially supported platform, the one I used. Probably the less buggy one.
  • MacOS: although I never tried it on MacOS, it is similar to Linux and some patches were submitted to me, so I guess it is OK
  • Windows: it seems to be working for some people, not working for some others. Theoretically there should be a way to get it done.

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.
  • Read operations. Reading was never needed in my project, so all the tests I did on that matter were theoretic. I was also quite naive, so the API is probably not optimal. What we need is to re-think reading from scratch.
  • Configuration done by calling functions. This is so Java. It would be much better to be able to pass a configuration array once and for all. Furthermore, I suspect that the order of call matters, which is bad.
  • 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. Currently there is an heavy use of the errors system to report errors (2007 baby), but this is seriously lame. They have to be replaced by actual exceptions.

Call for contribution

I have about 0 time to code or test this project. However, there is clearly a need for it.

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

What is needed, IMHO:

  • Address the concerns listed above, and find new ones.
  • Create a reproducible test environment for each OS, and prove that each feature works (basically, unit-testing).
  • Report of use cases, bugs, missing features, etc.

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 :)

Licence

PHP Serial Copyright (C) 2007-2014 PHP Serial's contributors (see CONTRIBUTORS file)

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

More Repositories

1

Spybar

Adds progress bars to any file-reading tool (gzip, md5sum, etc)
Python
21
star
2

DEV-CLI

A CLI interface to the dev.to API
Python
16
star
3

cr30-calibration

CR-30-specific calibration shapes
OpenSCAD
5
star
4

filemarx

Check that a file/directory structure conforms to a given JSON Schema
Python
5
star
5

Maiznet

Le site maiznet.fr
Python
4
star
6

typefit

A Python library to fit JSON into type-anotated Python objects
Python
4
star
7

PyTriggerTrap

Control a TriggerTrap device without the smartphone app.
Python
4
star
8

TS-Proxy

A TeamSpeak 2 & 3 proxy, for sysadmins frustrated with the non-standard port of TeamSpeak
C++
3
star
9

KarteServer

Python
3
star
10

mtuprobe

A tool to find out maximum MTU size on an IPv4 path
Python
3
star
11

FreneticBunny

Frennetic Bunny is a Facebook helper for jQuery
JavaScript
3
star
12

librechat-stats

A tool to extract statistics from LibreChat
Python
3
star
13

wsgiref

Python
2
star
14

dev-blog

My dev.to articles source
2
star
15

gibi

Generate random words based on Markov chains
Python
2
star
16

Vlang

A vue-cli plugin for i18n
JavaScript
2
star
17

JSZ

Javascript Zip - Autoextractible javascript code.
Python
2
star
18

faire-du-js

Une présentation sur la qualité de code en Javascript
JavaScript
2
star
19

deskbottom-spool-holder

A filament spool holder hanging from a table/desk
OpenSCAD
1
star
20

Armdorande

Armadeus-based light saber fight simulator.
C++
1
star
21

pycachu

A basic Python package to store files in a LRU cache.
Python
1
star
22

pypi.run

A simple online too to allow one-liner Python package execution
Python
1
star
23

pylesswrap

A Python wrapper around LESS.js, destined to help compiling LESS files from Django.
Python
1
star
24

wc2018_analysis

Analysis of World Cup 2018 results + various prediction algorithms
Python
1
star
25

frigotunnel

FrigoTunnel is a simple network protocol for auto-discovery and multicast communication
C++
1
star
26

Ponytile

A Python library/utility to create CSS sprites.
Python
1
star
27

activmusic

Rip music files from various sources and serve them as playlists
Python
1
star
28

nsre

Non-String Regular Expressions
Python
1
star
29

bureaudesrip

A tool to help saving your DVD series onto a more modern storage
Python
1
star
30

good-chat-tp

Dépôt du TP Good Chat
JavaScript
1
star
31

logit

A simple script to turn Git commit history into a time sheet
Python
1
star
32

nocallback.js

Async JS without callbacks. Get things simple again.
JavaScript
1
star