daverandom/serial

Serial device manipulation toolkit

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 0

Open Issues: 0

pkg:composer/daverandom/serial

dev-master 2018-05-31 13:18 UTC

This package is auto-updated.

Last update: 2025-09-25 10:32:29 UTC


README

<?php

use DaveRandom\Serial\DeviceManager;
use DaveRandom\Serial\ParityMode;
use DaveRandom\Serial\ControlFlowMode;

// Use COM1
const COM_PORT = 1;

// Create the correct device manager for the current platform (only windows supported so far)
$manager = DeviceManager::create();

// Get the current config for COM1
$config = $manager->getConfigForDevice(COM_PORT);
var_dump($config);

// Modify some parameters and set the config
$config
    ->setBaudRate(9600)
    ->setParityMode(ParityMode::NONE)
    ->setDataBits(8)
    ->setStopBits(1)
    ->setControlFlowMode(ControlFlowMode::NONE)
;
$manager->configureDevice(COM_PORT, $config);

// Open the device
$device = $manager->openDevice(COM_PORT);

// Send a message to the device
$device->write('D');

// Read some data from the device
var_dump($device->read());