Skip to content

Commit

Permalink
Create a configure for mac
Browse files Browse the repository at this point in the history
  • Loading branch information
lepiaf committed Sep 12, 2018
1 parent 1ffb660 commit 2f5244d
Showing 3 changed files with 41 additions and 2 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -35,3 +35,25 @@ while ($data = $serialPort->read()) {
}
}
```

For mac os, you must use `TTYMacConfigure`. It will use `stty -f` instead of `stty -F`.

```php
<?php

use lepiaf\SerialPort\SerialPort;
use lepiaf\SerialPort\Parser\SeparatorParser;
use lepiaf\SerialPort\Configure\TTYMacConfigure;

$serialPort = new SerialPort(new SeparatorParser(), new TTYMacConfigure());

$serialPort->open("/dev/ttyACM0");
while ($data = $serialPort->read()) {
echo $data."\n";

if ($data === "OK") {
$serialPort->write("1\n");
$serialPort->close();
}
}
```
4 changes: 2 additions & 2 deletions src/lepiaf/SerialPort/Configure/TTYConfigure.php
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
namespace lepiaf\SerialPort\Configure;

/**
* Configuration for linux/mac
* Configuration for linux
*/
class TTYConfigure implements ConfigureInterface
{
@@ -71,7 +71,7 @@ public function removeOption($value)
*
* @return string
*/
private function getOptions()
protected function getOptions()
{
if (!$this->options) {
$this->options = $this->default;
17 changes: 17 additions & 0 deletions src/lepiaf/SerialPort/Configure/TTYMacConfigure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace lepiaf\SerialPort\Configure;

/**
* Configuration for mac
*/
class TTYMacConfigure extends TTYConfigure
{
/**
* {@inheritdoc}
*/
public function configure($device)
{
exec(sprintf('stty -f %s %s', $device, $this->getOptions()));
}
}

0 comments on commit 2f5244d

Please sign in to comment.