douju1953 2015-09-03 07:25
浏览 81

PHP +串口+ GSM调制解调器

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
");
$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
");
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条回答 默认 最新

  • doudeng9425 2015-09-03 08:23
    关注

    Use:

    exec("cu -l /dev/cu.usbserial-xxxxxx; AT
    ", $output);
    
    echo $output;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题