- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 AT 命令在 C#.Net 中开发 GSM 调制解调器 (D-Link DWM-156) 的应用程序。我在发送英文短信时遇到问题。 我尝试发送“你好”,但我在手机中收到 □□□□ 或...除了你好。
serialPort1.DataBits = 8;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.BaudRate = 9600;
serialPort1.DtrEnable = true;
serialPort1.RtsEnable = true;
serialPort1.DiscardInBuffer();
serialPort1.DiscardOutBuffer();
serialPort1.WriteLine("AT\r");
Thread.Sleep(2000);
serialPort1.WriteLine("AT+CMGF=1\r");
Thread.Sleep(1000);
serialPort1.WriteLine("AT+CMGS=\"09390149196\"\r")
Thread.Sleep(2000);
serialPort1.WriteLine("hello" + "\x1A");
Thread.Sleep(1000);
最佳答案
很少有修复(可能更多,但我没有看到完整代码)。
WriteLine()
而要使用 Write()
,因为 \r
(单独)是命令行和结果代码终止符。SerialPort.WriteLine()
默认写入一个 usASCII 编码的字符串,但您的 GSM 调制解调器期望使用 AT 命令指定的编码字符串。将 SerialPort.Encoding
属性设置为特定编码并发送 CSCS
命令。您可以使用 CSCS=?
AT 命令询问支持的编码。即使应该应用默认 GSM,我也会避免隐含地依赖它。OK
或 ERROR
字符串)。来自 docs :
A command line is made up of three elements: the prefix, the body, and the termination character. The command line prefix consists of the characters "AT" or "at" [...] The termination character may be selected by a user option (parameter S3), the default being CR.
在伪代码中:
void SendCommand(string command) {
serialPort.Write(command + "\r");
// Do not put here an arbitrary wait, check modem's response
// Reading from serial port (use timeout).
CheckResponse();
}
serialPort.DataBits = 8;
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.BaudRate = 9600;
serialPort.DtrEnable = true;
serialPort.RtsEnable = true;
serialPort.Encoding = Encoding.GetEncoding("iso-8859-1");
serialPort.DiscardInBuffer();
serialPort.DiscardOutBuffer();
SendCommand("AT"); // "Ping"
SendCommand("AT+CMGF=1"); // Message format
SendCommand("AT+CSCS=\"PCCP437\""); // Character set
SendCommand("AT+CMGS=\"123456\"") // Phone number
SendCommand("hello" + "\x1A"); // Message
要检查响应(绝对避免任意等待!),您可以从这样的事情开始(未经测试的原始改编,因此您可能需要一些调试,另请参阅 this post ):
AutoResetEvent _receive;
string ReadResponse(int timeout)
{
string response = string.Empty;
while (true)
{
if (_receive.WaitOne(timeout, false))
{
response += _port.ReadExisting();
}
else
{
if (response.Length > 0)
throw new InvalidOperationException("Incomplete response.");
else
throw new InvalidOperationException("No response.");
}
// Pretty raw implementation, I'm not even sure it covers
// all cases, a better parsing would be appreciated here.
// Also note I am assuming verbose V1 output with both \r and \n.
if (response.EndsWith("\r\nOK\r\n"))
break;
if (response.EndsWith("\r\n> "))
break;
if (response.EndsWith("\r\nERROR\r\n"))
break;
}
return response;
}
在发送命令之前添加 _receive.Reset()
,当然还添加 OnPortDataReceived
作为 SerialPort.DataReceived
事件的处理程序:
void OnPortDataReceived(object sender,
SerialDataReceivedEventArgs e)
{
if (e.EventType == SerialData.Chars)
_receive.Set();
}
如果遇到问题(但可以连接),可以将 \r
替换为 \n
。一些调制解调器错误地(假设<CR>
除了使用13
参数没有映射到S3
之外)默认使用这个字符作为命令行终止符(即使它应该只出现在V1
详细输出的输出中) .更改您的代码或发送适当的 S3
。
关于c# - 使用 GSM 调制解调器 (D-Link DWM-156) 发送英文短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28315943/
在 .m 文件中: UIActionSheet *someSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"TI
常用HTML正则表达式 1.只能输入数字和英文的: 复制代码 代码如下: <input onkeyup="value=value.replace(/[/W]/g,'
前言 本文主要介绍使用UITextField限制只可输入中,英文,数字,我们可以使用NSPredicate正则表达式可以过滤,下面看看详细的步骤方法 首先设置UItextField的代理 实现
本文实例讲述了php判断输入是否是纯数字,英文,汉字的方法。分享给大家供大家参考。具体分析如下: 这里利用php的mb_strlen和strlen函数就可以轻松得知字符串的构成是全英文、英汉混合、
给定一个文本字符串 var string1 = 'IAmNotFoo'; 如何只提取大写字母? 'IANF' 下面是每个链接的一些方法: function isUpperCase1(aCharacte
如何在 PHP tcpdf 中生成连字? 最佳答案 tcpdf 使用 FreeType 来栅格化字体,或者只是将它们嵌入到 PDF 中并在查看器中栅格化。连字实际上是在字体中定义的。如果您使用的是 T
请多多指教!我正在完成“C 语言编程”一书中的练习。 我必须编写一个程序,它接受一个整数,然后提取并用英语显示整数的每一位。 因此,如果我输入 1234,它应该打印回“一二三四”。 由于这个练习接近本
只能输入中文:<input id="input1" type="text" onkeyup="value=value.replace(/[^\
复制代码 代码如下: $str='asb天水市12'; if (preg_match("/^[\x7f-\xff]+$/", $str)){ echo '全部是汉字'; }
我发现这个公式可以将金额转换为单词,但它不能 100% 起作用。每当金额以 20,30, 40 等结尾时,都会出现错误。例如 1020 会出错,但 1019 和 1021 可以正常工作。我试图自己解决
某些 Windows 计算机安装了多种显示语言。 我可以使用以下函数以该语言获取当前用户的 UI 语言: function GetUsersWindowsLanguage: string; var
引言需求:(输入框限制输入多少字符) 1、一个字母、符号、数字相当于一个字符 2、一个汉字相当于两个字符 3、不能输入特殊字符 4、不能输入emoji表情 直接上代码 1、注册通知
我目前正在使用 Emacs + Magit,但我想我的问题比这些软件的具体使用更笼统。我读过 How does one change the language of the command line
有谁知道包含示例英语词典单词脚本的 Web 引用链接,可用于填充 SQL Server 中的词典表? 我可以处理 .txt 或 .csv 文件,或类似的文件。 或者,我正在向我的网络应用程序添加自定义
Oracle(多语言环境)如何判断给定字符串(表列值)的语言(英文,中文...)? 最佳答案 应该可以使用像 Language Dectection for Java 这样的库并将它与您的 PL/SQ
当您现在在 Xcode 5 上本地化一个文件时,您将拥有这个“基本”文件,据我所知,如果用户使用的是另一种未本地化的语言,则会使用该文件。在旧版本的 Xcode 上,您没有。 我希望英语成为默认使用的
我有如下文字: 아니다 bukan 싫다 tidak suka 훌륭하다 bagus 我正在尝试删除英文行(英文字母)并将其附加到上行(韩文字母)的末尾,如下所示: 아니다bukan 싫다tidak
这个问题在这里已经有了答案: Unicode string literals in VBA (3 个回答) How to type Unicode currency character in Visu
我可以知道是否有任何 SQL 脚本可以满足我的以下场景? 如果column1包含中文字符,更新值column2为'Chinese' 如果 column1 包含英文字符,则将值 column2 更新为“
我正在使用一个图像处理 API 来读取图像上的文本,并且从我返回的字符串数据中,我需要提取英语或字典中的单词以及常见的名字和姓氏。换句话说,我在字符串中得到了我需要的文本,但在结果中也得到了一些我需要
我是一名优秀的程序员,十分优秀!