I would like to send SMS from my GSM modem. I tried to implement this using this link as reference. But my modem will not produce any response.Any help..Thanks in advance....
Here is my code snippet..
$gsm_send_sms = new gsm_send_sms();
$gsm_send_sms->init();
$status = $gsm_send_sms->my_send_message_function("+09524566775", "raja");
$gsm_send_sms->close();
//Send SMS via serial SMS modem
class gsm_send_sms {
public $port = 'COM7';
public $baud = "9600";
public $debug = true;
private $fp;
private $buffer;
//Setup COM port
public function init() {
$this->debugmsg("Setting up port: \"{$this->port} # \"{$this->baud}\" baud");
exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval);
if ($retval != 0) {
throw new Exception('Unable to setup COM port, check it is correct');
}
$this->debugmsg(implode("\n", $output));
$this->debugmsg("Opening port");
//Open COM port
$this->fp = fopen($this->port . ':', 'r+');
//Check port opened
if (!$this->fp) {
throw new Exception("Unable to open port \"{$this->port}\"");
}
$this->debugmsg("Port opened");
$this->debugmsg("Checking for responce from modem");
//Check modem connected
fputs($this->fp, "AT\r");
//Wait for ok
$status = $this->wait_reply("OK\r\n", 5);
if (!$status) {
throw new Exception('Did not receive responce from modem');
}
Related
I am trying to send sms via D-Link GSM modem. I am new on this. My code shows Unable to setup COM port I did not add any additional file, library or any modification in php.ini file in xampp. just installed software provided by modem. My operating system is windows 10. I am mentioning my code, though I got it from internet.
$mobile_number=$_POST['mobile_number'];
$messages=$_POST['messages'];
$gsm_send_sms = new gsm_send_sms();
$gsm_send_sms->debug = false;
$gsm_send_sms->port = 'COM3';
$gsm_send_sms->baud = 115200;
$gsm_send_sms->init();
$status = $gsm_send_sms->send($mobile_number,$messages);
if ($status) {
echo "<body bgcolor='lightgreen'>";
echo "<br><br><br>";
echo "<h3 align='center'>Message Successfully Send... </h3>\n";
echo "</body>";
} else {
echo "<body bgcolor='lightgreen'>";
echo "<br><br><br>";
echo "<h3 align='center'>Message not sent Successfully... </h3>\n";
echo "</body>";
}
$gsm_send_sms->close();
//Send SMS via serial SMS modem
class gsm_send_sms {
public $port = 'COM3';
public $baud = 115200;
public $debug = false;
private $fp;
private $buffer;
//Setup COM port
public function init() {
$this->debugmsg("Setting up port: \"{$this->port} # \"{$this->baud}\" baud");
exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval);
if ($retval != 0) {
throw new Exception('Unable to setup COM port, check it is correct');
}
$this->debugmsg(implode("\n", $output));
$this->debugmsg("Opening port");
//Open COM port
$this->fp = fopen($this->port . ':', 'r+');
//Check port opened
if (!$this->fp) {
throw new Exception("Unable to open port \"{$this->port}\"");
}
$this->debugmsg("Port opened");
$this->debugmsg("Checking for response from modem");
//Check modem connected
fputs($this->fp, "AT\r");
//Wait for ok
$status = $this->wait_reply("OK\r\n", 5);
if (!$status) {
throw new Exception('Did not receive responce from modem');
}
$this->debugmsg('Modem connected');
//Set modem to SMS text mode
$this->debugmsg('Setting text mode');
fputs($this->fp, "AT+CMGF=1\r");
$status = $this->wait_reply("OK\r\n", 5);
if (!$status) {
throw new Exception('Unable to set text mode');
}
$this->debugmsg('Text mode set');
}
//Wait for reply from modem
private function wait_reply($expected_result, $timeout) {
$this->debugmsg("Waiting {$timeout} seconds for expected result");
//Clear buffer
$this->buffer = '';
//Set timeout
$timeoutat = time() + $timeout;
//Loop until timeout reached (or expected result found)
do {
$this->debugmsg('Now: ' . time() . ", Timeout at: {$timeoutat}");
$buffer = fread($this->fp, 1024);
$this->buffer .= $buffer;
usleep(200000);//0.2 sec
$this->debugmsg("Received: {$buffer}");
//Check if received expected responce
if (preg_match('/'.preg_quote($expected_result, '/').'$/', $this->buffer)) {
$this->debugmsg('Found match');
return true;
//break;
} else if (preg_match('/\+CMS ERROR\:\ \d{1,3}\r\n$/', $this->buffer)) {
return false;
}
} while ($timeoutat > time());
$this->debugmsg('Timed out');
return false;
}
//Print debug messages
private function debugmsg($message) {
if ($this->debug == true) {
$message = preg_replace("%[^\040-\176\n\t]%", '', $message);
echo $message . "\n";
}
}
//Close port
public function close() {
$this->debugmsg('Closing port');
fclose($this->fp);
}
//Send message
public function send($tel, $message) {
//Filter tel
$tel = preg_replace("%[^0-9\+]%", '', $tel);
//Filter message text
$message = preg_replace("%[^\040-\176\r\n\t]%", '', $message);
$this->debugmsg("Sending message \"{$message}\" to \"{$tel}\"");
//Start sending of message
fputs($this->fp, "AT+CMGS=\"{$tel}\"\r");
//Wait for confirmation
$status = $this->wait_reply("\r\n> ", 5);
if (!$status) {
//throw new Exception('Did not receive confirmation from modem');
$this->debugmsg('Did not receive confirmation from modem');
return false;
}
//Send message text
fputs($this->fp, $message);
//Send message finished indicator
fputs($this->fp, chr(26));
//Wait for confirmation
$status = $this->wait_reply("OK\r\n", 180);
if (!$status) {
//throw new Exception('Did not receive confirmation of message sent');
$this->debugmsg('Did not receive confirmation of message sent');
return false;
}
$this->debugmsg("Message Send Successfully...");
return true;
}
}
It's Look like You are using a D-Link USB GSM Modem.
in this case Modem COM port doesn't show in Device Manager Automatically.
First you must start D-Link Connection Manager SoftWare and then you can find your modem under MODEM category in Device Manager.
R-Click on it and Open Properties window.
You can find COM port on it!
I am sending sms using Nokia usb Device and PHP script but getting error
many answer are there on stack but no answer has solution of this problem
Fatal error: Uncaught Exception: Unable to setup COM port, check it is correct in C:\xampp\htdocs\sms-prac\send-sms.php:103
Stack trace:
#0 C:\xampp\htdocs\sms-prac\send-sms.php(36): gsm_send_sms->init()
#1 {main}
thrown in C:\xampp\htdocs\sms-prac\send-sms.php on line 103
My gsm_send_sms Class Code
//Send SMS via serial SMS modem
class gsm_send_sms {
public $port = 'COM1';
public $baud = 115200;
public $debug = false;
private $fp;
private $buffer;
//Setup COM port
public function init() {
$this->debugmsg("Setting up port: \"{$this->port} # \"{$this->baud}\" baud");
exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval);
if ($retval != 0) {
throw new Exception('Unable to setup COM port, check it is correct');
}
$this->debugmsg(implode("\n", $output));
$this->debugmsg("Opening port");
//Open COM port
$this->fp = fopen($this->port . ':', 'r+');
//Check port opened
if (!$this->fp) {
throw new Exception("Unable to open port \"{$this->port}\"");
}
$this->debugmsg("Port opened");
$this->debugmsg("Checking for responce from modem");
//Check modem connected
fputs($this->fp, "AT\r");
//Wait for ok
$status = $this->wait_reply("OK\r\n", 5);
if (!$status) {
throw new Exception('Did not receive responce from modem');
}
$this->debugmsg('Modem connected');
//Set modem to SMS text mode
$this->debugmsg('Setting text mode');
fputs($this->fp, "AT+CMGF=1\r");
$status = $this->wait_reply("OK\r\n", 5);
if (!$status) {
throw new Exception('Unable to set text mode');
}
$this->debugmsg('Text mode set');
}
//Wait for reply from modem
private function wait_reply($expected_result, $timeout) {
$this->debugmsg("Waiting {$timeout} seconds for expected result");
//Clear buffer
$this->buffer = '';
//Set timeout
$timeoutat = time() + $timeout;
//Loop until timeout reached (or expected result found)
do {
$this->debugmsg('Now: ' . time() . ", Timeout at: {$timeoutat}");
$buffer = fread($this->fp, 1024);
$this->buffer .= $buffer;
usleep(200000);//0.2 sec
$this->debugmsg("Received: {$buffer}");
//Check if received expected responce
if (preg_match('/'.preg_quote($expected_result, '/').'$/', $this->buffer)) {
$this->debugmsg('Found match');
return true;
//break;
} else if (preg_match('/\+CMS ERROR\:\ \d{1,3}\r\n$/', $this->buffer)) {
return false;
}
} while ($timeoutat > time());
$this->debugmsg('Timed out');
return false;
}
//Print debug messages
private function debugmsg($message) {
if ($this->debug == true) {
$message = preg_replace("%[^\040-\176\n\t]%", '', $message);
echo $message . "\n";
}
}
//Close port
public function close() {
$this->debugmsg('Closing port');
fclose($this->fp);
}
//Send message
public function send($tel, $message) {
//Filter tel
$tel = preg_replace("%[^0-9\+]%", '', $tel);
//Filter message text
$message = preg_replace("%[^\040-\176\r\n\t]%", '', $message);
$this->debugmsg("Sending message \"{$message}\" to \"{$tel}\"");
//Start sending of message
fputs($this->fp, "AT+CMGS=\"{$tel}\"\r");
//Wait for confirmation
$status = $this->wait_reply("\r\n> ", 5);
if (!$status) {
//throw new Exception('Did not receive confirmation from modem');
$this->debugmsg('Did not receive confirmation from modem');
return false;
}
//Send message text
fputs($this->fp, $message);
//Send message finished indicator
fputs($this->fp, chr(26));
//Wait for confirmation
$status = $this->wait_reply("OK\r\n", 180);
if (!$status) {
//throw new Exception('Did not receive confirmation of messgage sent');
$this->debugmsg('Did not receive confirmation of messgage sent');
return false;
}
$this->debugmsg("Message sent");
return true;
}
}
My PHP Code which i am using to send SMS
<?php
//SMS via GSM Modem - A PHP class to send SMS messages via a GSM modem attached to the computers serial port.
//Windows only (tested on XP with PHP 5.2.6)
//Tested with the EZ863 (Telit GE863) GSM modem
//Requires that PHP has permission to access "COM" system device, and system "mode" command
ini_set('max_execution_time', 300);
error_reporting(E_ALL);
//Example
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "MembersManagmentSystem";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT Member.memberId, Member.memberContactMobileNumber, SMSRecipient.smsRecipientReceiverId, SMSRecipient.smsInfoId, SMSInfo.smsInfoText, SMSInfo.`smsInfoSaveDateTime` FROM Member, SMSRecipient,SMSInfo WHERE SMSRecipient.`smsRecipientReceiverId` = Member.`memberId` AND SMSRecipient.`smsInfoId`= SMSInfo.`smsInfoId` AND SMSRecipient.smsRecipientSentDateTime IS NULL AND Member.`memberContactMobileNumber` IS NOT NULL AND SMSInfo.`smsInfoSaveDateTime` > DATE_SUB(NOW(), INTERVAL 1 DAY)";
$result = $conn->query($sql);
echo "<pre>";
$gsm_send_sms = new gsm_send_sms();
$gsm_send_sms->debug = false;
$gsm_send_sms->port = 'COM3';
$gsm_send_sms->baud = 115200;
$gsm_send_sms->init();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
print_r($row);
$status = $gsm_send_sms->send($row['memberContactMobileNumber'], $row['smsInfoText']);
if ($status) {
$sql = "UPDATE SMSRecipient SET smsRecipientSentDateTime = now() WHERE smsInfoId = ".$row['smsInfoId']." and smsRecipientReceiverId = ".$row['memberId'];
if ($conn->query($sql) === TRUE) {
echo "Message sent\n";
}
} else {
echo "Message not sent\n";
}
}
//exit();
} else {
echo "0 results";
}
$gsm_send_sms->close();
$conn->close();
?>
on change $gsm_send_sms->debug = false; to true, get
Array
(
[0] =>
[1] => Status for device COM3:
[2] => -----------------------
[3] => Baud: 115200
[4] => Parity: None
[5] => Data Bits: 8
[6] => Stop Bits: 1
[7] => Timeout: OFF
[8] => XON/XOFF: OFF
[9] => CTS handshaking: OFF
[10] => DSR handshaking: OFF
[11] => DSR sensitivity: OFF
[12] => DTR circuit: ON
[13] => RTS circuit: ON
[14] =>
)
After Debug above Code I found that when i first time connect my device and run it php executing this line as like as infinity loop and before this line all debugmsg and other code running fine please help me
$buffer = fread($this->fp, 8192);
I have an own file that receives for post a request ajax, But the request never comes.
In a view:
<script type="text/javascript">
$(document).ready(function(){
$("#bloquear").click(function(e){
$.post("proyectodam/app/Lib/ServerSocket.php", {op: 1});
});
});
</script>
The php I have it in a directory that I have created,His namespaces:
namespace proyectodam\Lib;
file PHP:
<?php
namespace proyectodam\Lib;
try{
set_time_limit(0);
$address = '127.0.0.1';
$port = 5555;
// Create a TCP Stream socket
$sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); // 0 for SQL_TCP
// Bind the socket to an address/port
socket_bind($sock, $address, $port) or die('Could not bind to address'); //0 for localhost
// Start listening for connections
socket_listen($sock);
//loop and listen
while(true){
/* Accept incoming requests and handle them as child processes */
$client = socket_accept($sock);
//$_SESSION[socket_getpeername($client, AF_INET, 5555)] = socket_getpeername($client, AF_INET, 5555);
// Read the input from the client – 1024000 bytes
//$input = socket_read($client, 1024000);
// from here you need to do your database stuff
// and handle the response
// Display output back to client
if(isset($_POST["op"])){
$message = 1;
socket_write($client, $message, strlen($message));
}
socket_close($client);
}
// Close the master sockets
socket_close($sock);
}catch(Exception $e){
echo 'Excepción capturada: ', $e->getMessage(), "\n";
}
Client java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
public class ClienteSocket{
public static void main(String args[]){
try {
Socket client = new Socket("127.0.0.1", 5555);
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
OutputStreamWriter wr = new OutputStreamWriter(client.getOutputStream());
String op;
while((op = in.readLine()) != null){
System.out.println(op);
}
}catch (IOException e){
System.out.println("error");
e.printStackTrace();
}
}
}
That fails?
If you are making a post request to proyectodam/app/Lib/ServerSocket.php You need to make sure that you have a file in /public/proyectodam/app/Lib/ServerSocket.php
What I would suggest doing however is making an api endpoint such as:
Route::post('socket', function() {
return new ClientSocket();
}
And then have your client socket library class be:
<?php
namespace proyectodam\Lib;
class ClienteSocket {
public function __construct()
{
try{
set_time_limit(0);
$address = '127.0.0.1';
$port = 5555;
// Create a TCP Stream socket
$sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); // 0 for SQL_TCP
// Bind the socket to an address/port
socket_bind($sock, $address, $port) or die('Could not bind to address'); //0 for localhost
// Start listening for connections
socket_listen($sock);
//loop and listen
while(true){
/* Accept incoming requests and handle them as child processes */
$client = socket_accept($sock);
//$_SESSION[socket_getpeername($client, AF_INET, 5555)] = socket_getpeername($client, AF_INET, 5555);
// Read the input from the client – 1024000 bytes
//$input = socket_read($client, 1024000);
// from here you need to do your database stuff
// and handle the response
// Display output back to client
if(isset($_POST["op"])){
$message = 1;
socket_write($client, $message, strlen($message));
}
socket_close($client);
}
// Close the master sockets
socket_close($sock);
} catch(Exception $e){
echo 'Excepción capturada: ', $e->getMessage(), "\n";
}
}
}
I manage to send data for ajax (jquery) to the server TCP who is running for line of commands, but apparently the serveris unable to handle them.
From this JS/HTML I try to send data to the server.
<script type="text/javascript">
$(document).ready(function(){
$("#bloquear").click(function(){
$.post("http://localhost/proyectodam/app/Lib/ServerSocket.php", {op: 1});
});
});
</script>
Server in PHP.
<?php
namespace proyectodam\Lib;
try{
set_time_limit(0);
$address = '127.0.0.1';
$port = 5555;
// Create a TCP Stream socket
$sock = socket_create(AF_INET,SOCK_STREAM,SOL_TCP); // 0 for SQL_TCP
// Bind the socket to an address/port
socket_bind($sock, $address, $port) or die('Could not bind to address'); //0 for localhost
// Start listening for connections
socket_listen($sock);
//loop and listen
while(true){
/* Accept incoming requests and handle them as child processes */
$client = socket_accept($sock);
//$_SESSION[socket_getpeername($client, AF_INET, 5555)] = socket_getpeername($client, AF_INET, 5555);
// Read the input from the client – 1024000 bytes
//$input = socket_read($client, 1024000);
// from here you need to do your database stuff
// and handle the response
// Display output back to client
if(isset($_POST["op"]) && $_POST["op"] == 1){
$message = $_POST["op"];
socket_write($client, $message, strlen($message));
//echo json_encode("si");
}
socket_close($client);
}
// Close the master sockets
socket_close($sock);
}catch(Exception $e){
echo 'Excepción capturada: ', $e->getMessage(), "\n";
}
Client Java.
public class ClienteSocket{
public static void main(String args[]){
try {
Socket client = new Socket("127.0.0.1", 5555);
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
OutputStreamWriter wr = new OutputStreamWriter(client.getOutputStream());
String op;
while((op = in.readLine()) != null){
System.out.println(op);
}
}catch (IOException e){
System.out.println("error");
e.printStackTrace();
}
}
}
How the server intercept the data that come for ajax and once obtained to send to the client Java?
I am trying to implement this code below, I have a wavecom gsm modem connected to COM6 http://imgur.com/QwkwfMc it works on 3rd party sms gateway software but it is very expensive.
I am getting these errors
Fatal error: Uncaught exception 'Exception' with message 'Unable to setup COM port, check it is correct' in C:\wamp\www\sms\index.php on line 53
( ! ) Exception: Unable to setup COM port, check it is correct in C:\wamp\www\sms\index.php on line 53
What do i need to do to make this work?
<?php
//SMS via GSM Modem - A PHP class to send SMS messages via a GSM modem attached to the computers serial port.
//Windows only (tested on XP with PHP 5.2.6)
//Tested with the EZ863 (Telit GE863) GSM modem
//Requires that PHP has permission to access "COM" system device, and system "mode" command
error_reporting(E_ALL);
//Example
$gsm_send_sms = new gsm_send_sms();
$gsm_send_sms->debug = false;
$gsm_send_sms->port = 'COM6';
$gsm_send_sms->baud = 9600;
$gsm_send_sms->init();
$status = $gsm_send_sms->send('+642102844012', 'testing 123');
if ($status) {
echo "Message sent\n";
} else {
echo "Message not sent\n";
}
$gsm_send_sms->close();
//Send SMS via serial SMS modem
class gsm_send_sms {
public $port = 'COM6';
public $baud = 9600;
public $debug = false;
private $fp;
private $buffer;
//Setup COM port
public function init() {
$this->debugmsg("Setting up port: \"{$this->port} # \"{$this->baud}\" baud");
exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval);
if ($retval != 0) {
throw new Exception('Unable to setup COM port, check it is correct');
}
$this->debugmsg(implode("\n", $output));
$this->debugmsg("Opening port");
//Open COM port
$this->fp = fopen($this->port . ':', 'r+');
//Check port opened
if (!$this->fp) {
throw new Exception("Unable to open port \"{$this->port}\"");
}
$this->debugmsg("Port opened");
$this->debugmsg("Checking for responce from modem");
//Check modem connected
fputs($this->fp, "AT\r");
//Wait for ok
$status = $this->wait_reply("OK\r\n", 5);
if (!$status) {
throw new Exception('Did not receive responce from modem');
}
$this->debugmsg('Modem connected');
//Set modem to SMS text mode
$this->debugmsg('Setting text mode');
fputs($this->fp, "AT+CMGF=1\r");
$status = $this->wait_reply("OK\r\n", 5);
if (!$status) {
throw new Exception('Unable to set text mode');
}
$this->debugmsg('Text mode set');
}
//Wait for reply from modem
private function wait_reply($expected_result, $timeout) {
$this->debugmsg("Waiting {$timeout} seconds for expected result");
//Clear buffer
$this->buffer = '';
//Set timeout
$timeoutat = time() + $timeout;
//Loop until timeout reached (or expected result found)
do {
$this->debugmsg('Now: ' . time() . ", Timeout at: {$timeoutat}");
$buffer = fread($this->fp, 1024);
$this->buffer .= $buffer;
usleep(200000);//0.2 sec
$this->debugmsg("Received: {$buffer}");
//Check if received expected responce
if (preg_match('/'.preg_quote($expected_result, '/').'$/', $this->buffer)) {
$this->debugmsg('Found match');
return true;
//break;
} else if (preg_match('/\+CMS ERROR\:\ \d{1,3}\r\n$/', $this->buffer)) {
return false;
}
} while ($timeoutat > time());
$this->debugmsg('Timed out');
return false;
}
//Print debug messages
private function debugmsg($message) {
if ($this->debug == true) {
$message = preg_replace("%[^\040-\176\n\t]%", '', $message);
echo $message . "\n";
}
}
//Close port
public function close() {
$this->debugmsg('Closing port');
fclose($this->fp);
}
//Send message
public function send($tel, $message) {
//Filter tel
$tel = preg_replace("%[^0-9\+]%", '', $tel);
//Filter message text
$message = preg_replace("%[^\040-\176\r\n\t]%", '', $message);
$this->debugmsg("Sending message \"{$message}\" to \"{$tel}\"");
//Start sending of message
fputs($this->fp, "AT+CMGS=\"{$tel}\"\r");
//Wait for confirmation
$status = $this->wait_reply("\r\n> ", 5);
if (!$status) {
//throw new Exception('Did not receive confirmation from modem');
$this->debugmsg('Did not receive confirmation from modem');
return false;
}
//Send message text
fputs($this->fp, $message);
//Send message finished indicator
fputs($this->fp, chr(26));
//Wait for confirmation
$status = $this->wait_reply("OK\r\n", 180);
if (!$status) {
//throw new Exception('Did not receive confirmation of messgage sent');
$this->debugmsg('Did not receive confirmation of messgage sent');
return false;
}
$this->debugmsg("Message sent");
return true;
}
}
?>
Try this below code hope it helps,
Note : uses php_serial.class.php
Code :
<?php
require("php_serial.class.php");
$serial = new phpSerial;
// First we must specify the device. This works on both linux and windows (if
// your linux serial device is /dev/ttyS0 for COM1, etc)
$serial->deviceSet("/dev/ttyS0");
// We can change the baud rate, parity, length, stop bits, flow control
$serial->confBaudRate(9600);
$serial->confParity("none");
$serial->confCharacterLength(8);
$serial->confStopBits(1);
$serial->confFlowControl("none");
// Then we need to open it
$serial->deviceOpen();
// To write into
$serial->sendMessage("AT+CMGF=1\n\r");
$serial->sendMessage("AT+cmgs=\"+912709345x23\"\n\r");
$serial->sendMessage("Hi, This is the sms that I sent to you using PHP script with serial Port communication with my phone as serial device!! GN - VKSALIAN \n\r");
$serial->sendMessage(chr(26));
//wait for modem to send message
sleep(7);
// Or to read from
$read = $serial->readPort();
echo $read;
// If you want to change the configuration, the device must be closed
$serial->deviceClose();
?>