C# 从移动宽带模块接收PDU格式的短信
这是我的问题:我想通过c代码从移动宽带模块发送短信 经过大量研究,我发现了如何检测模块、解锁pin码、访问所有信息(家庭提供商、服务中心地址等)。但当我来发送信息时,什么也没发生。我尝试使用在线工具创建PDU消息: 但它似乎不是很有效 这是我的密码:C# 从移动宽带模块接收PDU格式的短信,c#,sms,C#,Sms,这是我的问题:我想通过c代码从移动宽带模块发送短信 经过大量研究,我发现了如何检测模块、解锁pin码、访问所有信息(家庭提供商、服务中心地址等)。但当我来发送信息时,什么也没发生。我尝试使用在线工具创建PDU消息: 但它似乎不是很有效 这是我的密码: //Get the interface manager MbnInterfaceManager manager = new MbnInterfaceManager(); //M
//Get the interface manager
MbnInterfaceManager manager = new MbnInterfaceManager();
//Make it usable
IMbnInterfaceManager infMgr = (IMbnInterfaceManager)manager;
try
{
//Get all interfaces
IMbnInterface[] interfaces = infMgr.GetInterfaces() as IMbnInterface[];
if (interfaces.Length > 0)
{
foreach (IMbnInterface interf in interfaces)
{
//Write its information
Console.WriteLine("State : " + interf.GetReadyState());
//Get the Pin
IMbnPinManager pinMan = interf as IMbnPinManager;
IMbnPin pin = pinMan.GetPinList().GetValue(0) as IMbnPin;
uint requestID;
//Unlock Sim
pin.Enter("MyPinCode", out requestID);
Thread.Sleep(10000);
Console.WriteLine("Home Provider : " + interf.GetHomeProvider().providerName);
Console.WriteLine("Connection ID : " + interf.GetConnection().ConnectionID);
//Create an object sms
IMbnSms sms = interf as IMbnSms;
//Get its information
IMbnSmsConfiguration smsConfig = sms.GetSmsConfiguration();
//Get capabilities of the interface
MBN_INTERFACE_CAPS caps = interf.GetInterfaceCapability();
//get SMS capabilities and cast it
MBN_SMS_CAPS scaps = (MBN_SMS_CAPS)caps.smsCaps;
//Show capabilities and other info
//SMS CAPS returns 3, which means PDU receive and send
Console.WriteLine("SMS CAP : " + scaps.ToString());
Console.WriteLine("Service center address : " + smsConfig.ServiceCenterAddress);
MBN_SMS_STATUS_INFO smsInfo = new MBN_SMS_STATUS_INFO();
sms.GetSmsStatus(out smsInfo);
//Send a message with a pdu format
//You can know the format to use with the SMS CAPS
string pduData = "0692600600030011000A9270684803880000AA19C2B75BFDAECB41EA32685E4FCF417537485E7687E5644";
//Get the byte size of the message
byte[] bytesize = Encoding.Unicode.GetBytes(pduData);
//Send sms
sms.SmsSendPdu(pduData, (byte) bytesize.Length, out requestID);
Console.WriteLine("Sending sms ....");
}
}
else
{
Console.WriteLine("No connection found");
}
}
catch (COMException e)
{
Console.WriteLine(e.HResult + "\n" + e.Message + "\n" + e.Source);
}
该代码一直工作到应该发送SMS的部分
在哪里可以找到脱机转换器来动态获取我的PDU消息,对于我当前尝试发送的一个,它为什么不工作?更改如下:sms.SmsSendPdu(bytesize,bytesize.Length,out requestID);您需要发送字节数组,而不是将长度截断为256。非常感谢您的回答,问题是我必须以字符串形式发送pdu消息,以字节形式发送大小,怎么办?代码没有意义。您正在使用GetBytes()获取字节[],然后获取长度。但是你正在传递字符串。为什么?长度需要与数据一致。不能先获取字节长度,然后再传递字符串。尺码不一样。哦,好的,我明白了!所以我必须得到pduData本身的长度?信息是正确的还是我必须改变什么?不知道。这取决于SmsSendPdu()方法需要什么;您需要发送字节数组,而不是将长度截断为256。非常感谢您的回答,问题是我必须以字符串形式发送pdu消息,以字节形式发送大小,怎么办?代码没有意义。您正在使用GetBytes()获取字节[],然后获取长度。但是你正在传递字符串。为什么?长度需要与数据一致。不能先获取字节长度,然后再传递字符串。尺码不一样。哦,好的,我明白了!所以我必须得到pduData本身的长度?信息是正确的还是我必须改变什么?不知道。这取决于SmsSendPdu()方法需要什么。