跪求解决。顶着有分

Change_L 2011-12-05 09:43:57
ss_port.Write(Encoding.ASCII.GetBytes("AT+CSCA?\r"));//获取手机短信中心号
string centerNumber = Encoding.ASCII.GetString(ss_port.Read(128));//第一次循环结果为AT+CSCA?+CSCA: "+8613010180500",145 OK//这确
if (centerNumber.Length > 0)
{
centerNumber = centerNumber.Substring(20, 13);
}
string decodedSMS = sms.smsDecodedsms(centerNumber, phoneNumber, content);//第一次循环结果0891683110100805F011000D91683105238054F2000800046D4B8BD5//正确
byte[] buf = Encoding.ASCII.GetBytes(String.Format("AT+CMGS={0}\r", sms.nLength));
ss_port.Write(buf);
string response = Encoding.ASCII.GetString(ss_port.Read(128));
if (response.Length > 0 && response.EndsWith("> "))
{
ss_port.Write(Encoding.ASCII.GetBytes(String.Format("{0}\x01a", decodedSMS)));
SendState = true;
}

第二次获取中心号码结果:string centerNumber=0891683110100805F011000D91683105238054F2000800046D4B8BD5 ERROR AT+CSCA? +CSCA: "+8613010180500",145 OK

好像是第一次的内容加上AT指令+发回结果了。这是什么问题。。在线等。。
...全文
201 33 打赏 收藏 转发到动态 举报
写回复
用AI写文章
33 条回复
切换为时间正序
请发表友善的回复…
发表回复
q198708wyp 2011-12-06
  • 打赏
  • 举报
回复
定下把 问题太长了 懒得看了
绿领巾童鞋 2011-12-06
  • 打赏
  • 举报
回复
string response = Encoding.ASCII.GetString(ss_port.Read(128));
绿领巾童鞋 2011-12-06
  • 打赏
  • 举报
回复
恩,解决了?先顶一下
阿非 2011-12-06
  • 打赏
  • 举报
回复
解决了?
Change_L 2011-12-06
  • 打赏
  • 举报
回复
结贴了。看来没人遇到过。。。
绿领巾童鞋 2011-12-06
  • 打赏
  • 举报
回复
[Quote=引用 32 楼 yxq371711105 的回复:]

UP!+1
[/Quote]
+2
Change_L 2011-12-06
  • 打赏
  • 举报
回复

public void Open()
{
DCB dcbCommPort = new DCB();
COMMTIMEOUTS ctoCommPort = new COMMTIMEOUTS();
// 打开串口 OPEN THE COMM PORT.
hComm = CreateFile(PortNum, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
// 如果串口没有打开,就打开 IF THE PORT CANNOT BE OPENED, BAIL OUT.
if (hComm == INVALID_HANDLE_VALUE)
{
throw (new ApplicationException("非法操作,不能打开串口!"));
}
// 设置通信超时时间 SET THE COMM TIMEOUTS.
GetCommTimeouts(hComm, ref ctoCommPort);
ctoCommPort.ReadTotalTimeoutConstant = ReadTimeout;
ctoCommPort.ReadTotalTimeoutMultiplier = 0;
ctoCommPort.WriteTotalTimeoutMultiplier = 0;
ctoCommPort.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(hComm, ref ctoCommPort);
// 设置串口 SET BAUD RATE, PARITY, WORD SIZE, AND STOP BITS.
GetCommState(hComm, ref dcbCommPort);
dcbCommPort.fOutxCtsFlow = 524800;
dcbCommPort.BaudRate = BaudRate;
dcbCommPort.flags = 0;
dcbCommPort.flags |= 1;
if (Parity > 0)
{
dcbCommPort.flags |= 2;
}
dcbCommPort.Parity = Parity;
dcbCommPort.ByteSize = ByteSize;
dcbCommPort.StopBits = StopBits;
if (!SetCommState(hComm, ref dcbCommPort))
{
CloseHandle(hComm);
throw (new ApplicationException("非法操作,不能打开串口!"));
}
Opened = true;
}
Change_L 2011-12-06
  • 打赏
  • 举报
回复

ss_port.Write(Encoding.ASCII.GetBytes("AT+CSCA?\r"));//获取手机短信中心号
string centerNumber = Encoding.ASCII.GetString(ss_port.Read(128));
if (centerNumber.Length > 0)
{
centerNumber = centerNumber.Substring(20, 13);
}
string decodedSMS = sms.smsDecodedsms(centerNumber, phoneNumber, content);
byte[] buf = Encoding.ASCII.GetBytes(String.Format("AT+CMGS={0}\r", sms.nLength));
ss_port.Write(buf);
string response = Encoding.ASCII.GetString(ss_port.Read(128));
if (response.Length > 0 && response.EndsWith("> "))
{
ss_port.Write(Encoding.ASCII.GetBytes(String.Format("{0}\x01a", decodedSMS)));
SendState = true;
}

土地公公 2011-12-06
  • 打赏
  • 举报
回复
没遇到过。
大哥,代码格式给整整啊,照顾下观众。
PaulyJiang 2011-12-06
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 ju523756055 的回复:]
引用 7 楼 cf_nxcxy 的回复:
帮顶------------

+1
[/Quote]
~~~
kkbac 2011-12-06
  • 打赏
  • 举报
回复
令狐苦瓜 2011-12-06
  • 打赏
  • 举报
回复
断点调试
Change_L 2011-12-06
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 q198708wyp 的回复:]
定下把 问题太长了 懒得看了
[/Quote]

大哥。别懒得看啊。懂就给看看啊
Change_L 2011-12-05
  • 打赏
  • 举报
回复
public void Open()
{
DCB dcbCommPort = new DCB();
COMMTIMEOUTS ctoCommPort = new COMMTIMEOUTS();
// 打开串口 OPEN THE COMM PORT.
hComm = CreateFile(PortNum, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
// 如果串口没有打开,就打开 IF THE PORT CANNOT BE OPENED, BAIL OUT.
if (hComm == INVALID_HANDLE_VALUE)
{
throw (new ApplicationException("非法操作,不能打开串口!"));
}
// 设置通信超时时间 SET THE COMM TIMEOUTS.
GetCommTimeouts(hComm, ref ctoCommPort);
ctoCommPort.ReadTotalTimeoutConstant = ReadTimeout;
ctoCommPort.ReadTotalTimeoutMultiplier = 0;
ctoCommPort.WriteTotalTimeoutMultiplier = 0;
ctoCommPort.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(hComm, ref ctoCommPort);
// 设置串口 SET BAUD RATE, PARITY, WORD SIZE, AND STOP BITS.
GetCommState(hComm, ref dcbCommPort);
//dcbCommPort.fOutxCtsFlow = 524800;
dcbCommPort.BaudRate = BaudRate;
dcbCommPort.flags = 0;
//dcb.fBinary=1;
dcbCommPort.flags |= 1;
if (Parity > 0)
{
//dcb.fParity=1
dcbCommPort.flags |= 2;
}
dcbCommPort.Parity = Parity;
dcbCommPort.ByteSize = ByteSize;
dcbCommPort.StopBits = StopBits;
if (!SetCommState(hComm, ref dcbCommPort))
{
CloseHandle(hComm);
throw (new ApplicationException("非法操作,不能打开串口!"));
}
Opened = true;
}

//dcbCommPort.fOutxCtsFlow = 524800;一开始是没有这句的。但没有这句获取不到中心号码,需要用别的出口工具打开一下再关闭才能获取到。发送正常。但加了这句了就出问题了
jmx123456789 2011-12-05
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 cf_nxcxy 的回复:]
帮顶------------
[/Quote]
+1
Change_L 2011-12-05
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 findcaiyzh 的回复:]
第二次出错误了?
返回值里有ERROR.
[/Quote]

为什么会把第二次内容添加上啊?
南瓜 2011-12-05
  • 打赏
  • 举报
回复
顶个! 每天回帖即可获得10分可用分!小技巧:教您如何更快获得可用分
梦里独赏花 2011-12-05
  • 打赏
  • 举报
回复
设断点 调试跟踪一下
宝_爸 2011-12-05
  • 打赏
  • 举报
回复
第二次出错误了?
返回值里有ERROR.

110,565

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧