|
Code samples
We have included some source code examples to show you how the toolkit is
used to encode and decode SMS content.
Here is an example for creating (encoding) the PDU strings for a Picture Message:
|
Visual Basic
|
C++ |
VB.NET
|
C#
|
Dim objEncoder As New
XMSEngineLib.SMSMessageManager
Dim objPictureMessage As XMSEngineLib.PictureMessage
Dim objPDU As XMSEngineLib.PDU
'Create a new picture message
Set objPictureMessage = objEncoder.CreatePictureMessage( _
"", _
"Please call
me ASAP", _
"c:\temp\PicMsg.bmp")
'Iterate through PDUs collection for results
For Each objPDU In objPictureMessage .PDUs
Debug.Print "PDU to send: " + objPDU.PDU
Debug.Print "Length in octets (use with AT+CMGS): " + CStr(objPDU.LengthInOctets)
Next
ISMSMessageManagerPtr pEncoder;
pEncoder.CreateInstance(CLSID_SMSMessageManager);
// Create a new picture message
IPictureMessagePtr pPictureMessage = pEncoder->CreatePictureMessage("",
"Please call me ASAP", "c:\\temp\\PicMsg.bmp", "", 167);
// Iterate through PDUs collection for results
for (long lPDUCount =
1; lPDUCount <= pPictureMessage->PDUs->Count; lPDUCount ++)
{
IPDUPtr pPDU = pPictureMessage->PDUs->Item[lPDUCount];
TRACE(_T("PDU to send: %s\r\n"), LPCTSTR(pPDU->PDU));
TRACE(_T("Length in octets (use with AT+CMGS): %d\r\n"), pPDU->LengthInOctets);
}
Dim objEncoder As New
XMSEngineLib.SMSMessageManager()
Dim objPictureMessage As XMSEngineLib.PictureMessage
Dim objPDU As XMSEngineLib.PDU
'Create a new picture message
objPictureMessage = objEncoder.CreatePictureMessage( _
"", _
"Please call
me ASAP", _
"c:\temp\PicMsg.bmp")
'Iterate through PDUs collection for results
For Each objPDU In objPictureMessage .PDUs
System.Diagnostics.Debug.WriteLine("PDU to send: " + objPDU.PDU)
System.Diagnostics.Debug.WriteLine("Length in octets (use with AT+CMGS): " + CStr(objPDU.LengthInOctets))
Next
XMSENGINELib.SMSMessageManager objEncoder = new XMSENGINELib.SMSMessageManager();
XMSENGINELib.PictureMessage objPictureMessage;
//Create a new picture message
objPictureMessage = objEncoder.CreatePictureMessage(
"",
"Please call me ASAP",
"c:\\temp\\PicMsg.bmp", "", 167);
// Iterate through PDUs collection for results
foreach (PDU _pdu in objPictureMessage.PDUs)
{
System.Diagnostics.Debug.WriteLine("PDU to send: " + _pdu.PDU);
System.Diagnostics.Debug.WriteLine("Length in octets
(use with AT+CMGS): " + _pdu.LengthInOctets.ToString());
}
Here is an example for decoding the PDU strings for a Picture Message:
|
Visual Basic
|
C++ |
VB.NET
|
C#
|
Dim objDecoder As New
XMSEngineLib.SMSMessageManager
Dim objSMSMessage As XMSEngineLib.SMSMessage
Dim objPictureMessage As XMSEngineLib.PictureMessage
Dim objPDU As XMSEngineLib.PDU
'Decode the incoming PDU
Set objSMSMessage = objDecoder.DecodePDU( _
"F2440BF100F" & _
"521448AE" & _
"C00060000C1B031F00C00660000C" & _
"1B033181EE1EF6C33C" & _
"66C3661C3CF1CE1C3CFB" & _
"0183F30663C606337B31861B3661866C1B33318619E3618" & _
"3CC1B331F000000000000000000")
'Do we have the complete PDU?
If objSMSMessage.State = Waiting Then Exit Sub 'Come back
later with the next PDU
If objSMSMessage.MessageType = PictureMessage Then
'Cast to a PictureMessage message to get specific properties
Set objPictureMessage = objSMSMessage
'Report on some of the incoming message properties
Debug.Print "Image for Picture Message: " + objPictureMessage.BitmapFileName
Debug.Print "Sent from: " + objPictureMessage.SenderAddress
Debug.Print "Message arrived: " +
objPictureMessage.PDUs.Item(1).ArrivalDate
End If
ISMSMessageManagerPtr pDecoder;
pDecoder.CreateInstance(CLSID_SMSMessageManager);
// Decode the incoming PDU
ISMSMessagePtr pSMSMessage = pDecoder->DecodePDU(
"F2440BF100F"
"521448AE"
"C00060000C1B031F00C00660000C"
"1B033181EE1EF6C33C"
"66C3661C3CF1CE1C3CFB"
"0183F30663C606337B31861B3661866C1B33318619E3618"
"3CC1B331F000000000000000000");
// If we don't have the complete message, leave and we'll
come back in
// later with the next one(s)
if (pSMSMessage->State == Waiting) return;
if (pSMSMessage->MessageType == PictureMessage)
{
// Cast to a PictureMessage message to get specific properties
IPictureMessagePtr pPictureMessage = pSMSMessage;
// Report on some of the incoming message properties
TRACE(_T("Image for Picture: %s\r\n"), LPCTSTR(pPictureMessage->BitmapFileName));
TRACE(_T("Sent from: %s\r\n"), LPCTSTR(pPictureMessage->SenderAddress));
TRACE(_T("Message arrived: %s\r\n"), LPCTSTR(pPictureMessage->PDUs->Item[1L]->ArrivalDate));
}
Dim objDecoder As New XMSENGINELib.SMSMessageManager()
Dim objSMSMessage As XMSENGINELib.SMSMessage
Dim objPictureMessage As XMSENGINELib.PictureMessage
Dim objPDU As XMSENGINELib.PDU
'Decode the incoming PDU
objSMSMessage = objDecoder.DecodePDU( _
"F2440BF100F" & _
"521448AE" & _
"C00060000C1B031F00C00660000C" & _
"1B033181EE1EF6C33C" & _
"66C3661C3CF1CE1C3CFB" & _
"0183F30663C606337B31861B3661866C1B33318619E3618" & _
"3CC1B331F000000000000000000")
'Do we have the complete PDU?
If objSMSMessage.State = enumMultipartMessageState.Waiting Then
Exit Sub 'Come back later with the next
PDU
End If
If objSMSMessage.MessageType = enumSMSMessageType.PictureMessage Then
'Cast to a PictureMessage message to
get specific properties
objPictureMessage = objSMSMessage
'Report on some of the incoming message
properties
System.Diagnostics.Debug.WriteLine("Image for Picture
Message: " + objPictureMessage.BitmapFileName)
System.Diagnostics.Debug.WriteLine("Sent from: " +
objPictureMessage.SenderAddress)
System.Diagnostics.Debug.WriteLine("Message arrived: " +
objPictureMessage.PDUs.Item(1).ArrivalDate)
End If
XMSENGINELib.SMSMessageManager objDecoder = new XMSENGINELib.SMSMessageManager();
XMSENGINELib.SMSMessage objSMSMessage;
XMSENGINELib.IPictureMessage objPictureMessage;
//Decode the incoming PDU
objSMSMessage = objDecoder.DecodePDU(
"F2440BF100F" +
"521448AE" +
"C00060000C1B031F00C00660000C" +
"1B033181EE1EF6C33C" +
"66C3661C3CF1CE1C3CFB" +
"0183F30663C606337B31861B3661866C1B33318619E3618" +
"3CC1B331F000000000000000000");
//Do we have the complete PDU?
if (objSMSMessage.State == enumMultipartMessageState.Waiting)
return; // Come back later with the
next PDU
if (objSMSMessage.MessageType == enumSMSMessageType.PictureMessage)
{
// Cast to a IPictureMessage message to
get specific properties
objPictureMessage = (IPictureMessage) objSMSMessage;
// Report on some of the incoming
message properties
System.Diagnostics.Debug.WriteLine("Image for Picture
Message: " + objPictureMessage.BitmapFileName);
System.Diagnostics.Debug.WriteLine("Sent from: " +
objPictureMessage.SenderAddress);
System.Diagnostics.Debug.WriteLine("Message arrived: " +
objPictureMessage.PDUs.get_Item(1).ArrivalDate);
}
|