GSM modem AT commands UCS2 error 500

柔情痞子 提交于 2019-12-11 14:33:32

问题


Three days ago I started making a simple app to send SMS. I already tested it and it works in GSM CSCS mode, but when I switch it to UCS2 it doesn't show the Cyrillic letters

<?php
error_reporting(E_ALL);

$fp = fopen("/dev/ttyUSB0", 'w+');

$msg = strtoupper(bin2hex(mb_convert_encoding("Тест", "UCS-2", "UTF-8")));
$number_raw = "+359000000000";
$number = bin2hex(mb_convert_encoding($number_raw, "UCS-2", "UTF-8"));
echo $number."<br>";
echo $msg;
$debug = false;
if(!$fp || $debug){
  //echo "Can not open!";
}else{
  fwrite($fp, "AT+CMGF=1".chr(13)); // OK
  sleep(5);
  fwrite($fp, 'AT+CSCS="UCS2"'.chr(13)); // OK
  sleep(5);
  fwrite($fp, 'AT+CMGS="'.$number.'"'.chr(13)); // OK
  sleep(5);
  fwrite($fp, $msg.chr(26)); // ERROR 500
  echo "<br>Sent";
}
?>

Number and message are encoded properly according to this source: http://www.columbia.edu/kermit/ucs2.html

When the message is sent, I receive it (so the encoding of the number is correct) but the content isn't shown properly.

https://imgur.com/a/cCaTU

What are possible causes for this behaviour and could it be my PHP file encoding? Also why is linux finding 3 GSM tty devices?


回答1:


After you have removed all the horrible sleep calls and implemented proper final response parsing, then you need fix the parsing for waiting for the "\r\n> " response of AT+CMGS.

Without any of that fixed, character set encoding trouble is a very minor problem. When you run AT+CSCS="UCS2" every single string will be encoded by the modem that way and must be encoded that way by you until eternity (or another character set is selected), so for instance to switch from UCS2 to UTF-8 would be AT+CSCS="005500540046002D0038" and not AT+CSCS="UTF-8".



来源:https://stackoverflow.com/questions/48086140/gsm-modem-at-commands-ucs2-error-500

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!