<?php

namespace App\Services;
use Carbon\Carbon;
use Fawno\PhpSerial\SerialDio;
use Fawno\PhpSerial\SerialConfig;
class SerialCommunicationService
{
    public function sendMessageDevice1($message, $port = 'COM2')
    {
        $config     = new SerialConfig();
        $config->setBaudRate(9600);
        $config->setParity(0);
        $config->setDataBits(8);
        $config->setStopBits(1);
        $config->setFlowControl(0);
        $serial     = new SerialDio($port, $config);
        $serial->open('r+b');
        $serial->setBlocking(0);
        $serial->setTimeout(0, 0);
        $serial->send($message);
        $pesan      = $serial->read();
        $serial->close();
        return $pesan;
    }
}
