1

I need to get response from GSM modem. Is it possible with Mac OS X? I mean is it possible to get the answer and save it to variable?

First problem

I know about php_serial.class.php, but this class supports Linux and Windows. Mac OS X has Darwin core, so it doesn't work. Besides, some of commands are different between Linux and Mac OS X. For example OS X uses 'cu -l /dev/... when Linux uses stty -F /dev/... to access the device.

Second problem

It might be not a problem, but still, I do not use COM port, but USB-COM converter. That's why I access through /dev/cu.usbserial-xxxxxx where xxxxxx is device's serial number.

What I tried

$gsmModem = fopen('/dev/cu.usbserial-xxxxxx', 'r+');
if ($gsmModem) echo 'Port opend!<br/>'; else echo 'Error opening port';
fwrite($gsmModem, "AT\r\n");
$response = fclose($gsmModem);
echo $response;

The first line result is: Port opened! which mean, that I am connected to my USB-COM converter. And the second line is 1 instead of OK.

Then I tried shell_exec() command, but still got nothing, due to insufficient administrative right (my guess):

$gsmModem = shell_exec("cu -l /dev/cu.usbserial-xxxxxx; AT\r\n");
echo $gsmModem;

One good thing is i can do is using terminal.app, where I can talk to gsm modem and get answers for each standard commands but it doesn't really help me, because I need response from modem to get some data and work with it. For example:

$ sudo cu -l /dev/cu.usbserial-xxxxxx
$ Password:
$ Connected.
  AT
  OK
  AT+CSQ
  +CSQ: 25,0

Really would be appreciated for any help!

1 Answers1

0

Use:

exec("cu -l /dev/cu.usbserial-xxxxxx; AT\r\n", $output);

echo $output;
Jackie
  • 494
  • 7
  • 14
  • Hello and thank's for your reply. But still nothing. I think this is because **cu -l** should be made with **sudo**. As far as I know there is no safe way to use **sudo** with shell_exec in php. –  Sep 03 '15 at 08:29
  • I think what you need maybe is here http://stackoverflow.com/questions/3173201/sudo-in-php-exec – Jackie Sep 03 '15 at 08:33