From fe25005107dd91cfc196e5bf275058c12cb411fc Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Fri, 21 Mar 2025 13:41:27 +0100 Subject: [PATCH] Fix serial tty setup, include matches in prompt event --- src/LineBufferedDuplexStream.php | 4 ++-- src/SerialFactory.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/LineBufferedDuplexStream.php b/src/LineBufferedDuplexStream.php index 6a6f4a5..992b413 100644 --- a/src/LineBufferedDuplexStream.php +++ b/src/LineBufferedDuplexStream.php @@ -62,13 +62,13 @@ class LineBufferedDuplexStream implements ReadableStreamInterface, WritableStrea // Check if the buffer matches the prompt pattern if ($this->promptPattern !== null) { - if (preg_match($this->promptPattern, $this->buffer)) { + if (preg_match($this->promptPattern, $this->buffer, $matches)) { $this->buffer = preg_replace($this->promptPattern, '', $this->buffer); if ($this->bufferOutput) { $this->emit(self::EVT_OUTPUT, [$this->output]); $this->output = []; } - $this->emit(self::EVT_PROMPT, []); + $this->emit(self::EVT_PROMPT, [ $matches ]); } } diff --git a/src/SerialFactory.php b/src/SerialFactory.php index 4695379..cd0150d 100644 --- a/src/SerialFactory.php +++ b/src/SerialFactory.php @@ -27,7 +27,7 @@ class SerialFactory $deferred = new Deferred(); Loop::futureTick(static function () use ($device, $baud, $bits, $parity, $stop, $deferred) { - $cmd = "stty -F ".escapeshellarg($device)." ".$baud." ".$parity->value." ".escapeshellarg("cs".$bits)." ".($stop==1?"-cstopb":"cstopb")." -echo cbreak min 0 time 0"; + $cmd = "stty -F ".escapeshellarg($device)." ".$baud." ".$parity->value." ".escapeshellarg("cs".$bits)." ".($stop==1?"-cstopb":"cstopb")." -echo -icrnl cbreak min 0 time 0"; //echo $cmd."\n"; exec($cmd); $fd = fopen($device, "a+");