Reputation: 325
I was tried to communicate with serial port using php, my code is,
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); ?>
<?php
include "php_serial.class.php";
use phpSerial\phpSerial;
$serial = new phpSerial();
$serial->deviceSet("COM1");
$serial->confBaudRate(2400);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
$serial->deviceOpen();
$serial->sendMessage("Hello !");
$read = $serial->readPort();
$serial->deviceClose();
$serial->confBaudRate(2400);
is i needed to include my php_serial.class.php in my question ? what is the problem with my code?
Upvotes: 1
Views: 2964
Reputation: 1110
Sometimes even when you enter the serial port correctly, you might get this error on Linux. In this case, you should give permission to read this port in the terminal by entering sudo chmod 0777 /dev/YOUR_SERIAL_PORT
wich YOUR_SERIAL_PORT
is your serial port, for example: ttyS0
.
Also, don't forget to enter sudo usermod -a -G dialout www-data
to grant PHP to use the serial port.
Upvotes: 0
Reputation: 4021
If you work on linux, you must use a different device:
$serial->deviceSet("/dev/ttyS0"); // or /dev/ttyS1, ...
Upvotes: 2