forked from Xowap/PHP-Serial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsms.php
More file actions
32 lines (24 loc) · 971 Bytes
/
sms.php
File metadata and controls
32 lines (24 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
include 'PhpSerial.php';
// Let's start the class
$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)
// If you are using Windows, make sure you disable FIFO from the modem's
// Device Manager properties pane (Advanced >> Advanced Port Settings...)
$serial->deviceSet("COM4");
// Then we need to open it
$serial->deviceOpen('w+');
// We may need to return if nothing happens for 10 seconds
stream_set_timeout($serial->_dHandle, 10);
// We can change the baud rate
$serial->confBaudRate(9600);
// SMS inbox query - mode command and list command
$serial->sendMessage("AT",1);
var_dump($serial->readPort());
$serial->sendMessage("AT+CMGF=1\n\r",1);
var_dump($serial->readPort());
$serial->sendMessage("AT+CMGL=\"ALL\"\n\r",2);
var_dump($serial->readPort());
// If you want to change the configuration, the device must be closed
$serial->deviceClose();