请看下面的代码:
#pragma once
using namespace System::IO::Ports;
using namespace System::Text::RegularExpressions;
using namespace System::Collections::Generic;
ref class SMS
{
public:
SMS(void);
void sendMessage();
private:
System::IO::Ports::SerialPort ^port;
};
和cpp文件
#include "StdAfx.h"
#include "SMS.h"
SMS::SMS(void)
{
//Initialize the Serial Port
port = gcnew System::IO::Ports::SerialPort();
port->PortName = "COM12";
port->BaudRate = 9600;
port->Parity = Parity::None;
port->DataBits = 8;
port->StopBits = StopBits::One;
port->Handshake = Handshake::RequestToSend;
port->DtrEnable = true;
port->RtsEnable = true;
port->NewLine = System::Environment::NewLine;
if(!port->IsOpen)
{
port->Open();
}
//Set message format
port->WriteLine("AT+CMGF=1");
//Turn off echo
port->WriteLine("ATE0");
//Set memory configurations
port->WriteLine("AT+CPMS=\"ME\",\"ME\",\"ME\"");
}
//This method will send the SMS
void SMS::sendMessage()
{
if(!port->IsOpen)
{
port->Open();
}
port->WriteLine("AT+CMGS=\"012121212\"");
port->WriteLine("Test Message From C#");
port->WriteLine(System::Convert::ToString((char)(26)));
port->Close();
}
我试图通过访问加密狗发送短信。端口是正确的,加密狗也很好,因为它几小时后回复了我朋友的代码。我在这做错了什么?我用C ++ / CLI做了什么不正确的事吗? AT命令?
尝试在每个AT命令后添加“CR”“LF”(回车符和换行符),一些GSM加密狗(如SIM900)needem以便工作。我希望这有助于问候
如果是win32,..更喜欢使用
HFILE OpenFile(LPCSTR lpFileName,//指向文件名LPOFSTRUCT的指针lpReOpenBuff,//指向文件信息缓冲区的指针 UINT uStyle //动作和属性);
与其他活动,...
如果使用具有调制解调器AT命令功能的SMS网关,如果U使用手机,这对于直接读写COM端口很好,其中许多都不起作用。例如诺基亚6070,3100型号组
最好用超级终端测试它。
我用过CBuildre6
https://sites.google.com/site/xpressdms/rosegarden
欢呼。