user4482202
user4482202

Reputation:

PHP + Serial port + GSM Modem

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!

Upvotes: 1

Views: 1111

Answers (1)

Jackie
Jackie

Reputation: 494

Use:

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

echo $output;

Upvotes: 0

Related Questions