Reputation: 603
i am using GSMComm library and Wavecom modem to create simple program SMS Sender, when i press the button Send in my winform a got a message debug in my VS2010.
The phone reports an unspecified error. This typically happens when a command is not supported by the device, a command is not valid for the current state or if a parameter is incorrect.
this my code
private void btnSend_Click(object sender, EventArgs e)
{
var port = "COM3"; // default port to connect modem wavecom
var baudRate = 115200;
var timeout = 300;
var comm = new GsmCommMain(port, baudRate, timeout);
try
{
var msg = txtIsiPesan.Text;
var phoneNumber = txtNoTujuan.Text;
comm.Open();
SmsSubmitPdu pdu = new SmsSubmitPdu(msg, phoneNumber, "");
comm.SendMessage(pdu); //debug found error here
comm.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "error");
}
}
Is this indicate that my wavecom modem didn't support to SmsSubmitPdu ? Please suggest me thanks.
Upvotes: 2
Views: 2674
Reputation: 1349
I have finally found the solution.
SmsSubmitPdu pdu = new SmsSubmitPdu(msg, phoneNumber, "");
the third parameter should be service center number as i am using GrameenPhone it is +8801700000600
So i tried with
SmsSubmitPdu pdu = new SmsSubmitPdu(msg, phoneNumber, "+8801700000600");
and successfull send sms. By the way make sure your com port is correct as mine is COM5.
var port = "COM5"; // default port to connect modem wavecom
var baudRate = 115200;
var timeout = 300;
var comm = new GsmCommMain(port, baudRate, timeout);
try
{
var msg = "TESTING";
var phoneNumber = "+8801719461643";
comm.Open();
SmsSubmitPdu pdu = new SmsSubmitPdu(msg, phoneNumber, "+8801700000600");
comm.SendMessage(pdu); //debug found error here
comm.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "error");
}
Upvotes: 2
Reputation: 1349
when comm is open you can do a long polling by while loop ,read sms and delete the index of the sms msg.Add the code after comm.Open();
while(true){
DecodedShortMessage[] messages =
gsmCommMain.ReadMessages(PhoneMessageStatus.All, PhoneStorageType.Sim);
foreach (var decodedShortMessage in messages)
{
var msgData = decodedShortMessage.Data.UserDataText;
int indexP = decodedShortMessage.Index;
gsmCommMain.DeleteMessage(indexP, PhoneStorageType.Sim);
// gsmCommMain.DeleteMessages(DeleteScope.Read, PhoneStorageType.Sim); delete all msg
}
}
Hope this helps
Upvotes: 2