Wallogit.com
2017 © Pedro Peláez
Talk to serial devices in PHP
Talk to serial devices in PHP from various* platforms., (*1)
Get Composer. Make your project require Serially., (*2)
composer require themainframe/serially dev-master
The ConnectionManager class enables you to write platform-portable code against Serially by abstracting the platform detection process away from your code., (*3)
The getConnection method returns an connection instance implementing ConnectionInterface suitable for the current platform., (*4)
$manager = new ConnectionManager;
$connection = $manager->getConnection('/dev/ttyS0');
$connection->writeLine('Hello from PHP');
Debugging serial devices and the communication between them can be difficult. Serially logs to a PSR-3-conformant LoggerInterface to make the process easier., (*5)
// $myLogger implements LoggerInterface // Connections created with this manager will be logged to $myLogger $manager->setLogger($myLogger);
Reading bytes from serial ports is a challenge in PHP. Depending on the platform, you may observe
that data received before readLine() or readByte() is called may or may not be available., (*6)
Platform agility is a work-in-progress. The PlatformSpecific namespace contains platform-specific connection implementations (of ConnectionInterface) for Mac OS X (Darwin) and Linux. A Windows one may emerge soon., (*7)