Reputation: 321
I want to use a broadband stick and create a C# application in VB.net 2012 that can send SMS message to single / multiple mobile phones. I'm currently connected to a COM Port, but I could not send any message. Here is my whole code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GsmComm.GsmCommunication;
using GsmComm.PduConverter;
using GsmComm.Server;
using GsmComm.Interfaces;
namespace myTEXT
{
public partial class Form1 : Form
{
private GsmCommMain comm;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void cmdSend_Click(object sender, EventArgs e)
{
SmsSubmitPdu pdu;
byte dcs = (byte)DataCodingScheme.GeneralCoding.Alpha7BitDefault;
pdu = new SmsSubmitPdu(txtMessage.Text, txtPhoneNumber.Text, dcs);
comm.SendMessage(pdu);
}
private void cmdConnect_Click(object sender, EventArgs e)
{
if (txtCommPort.Text == "")
{
MessageBox.Show("Invalid Port Number!");
}
else
{
comm = new GsmCommMain(txtCommPort.Text, 9600, 150);
Cursor.Current = Cursors.Default;
Cursor.Current = Cursors.WaitCursor;
comm.Open();
Cursor.Current = Cursors.Default;
MessageBox.Show("Connected!");
}
}
}
}
When I run my program, I can connect to a certain port (for my case, COM22). But when I try to send my message, it has an error
CommException was unhandled
No phone connected.
What to do?
Thanks for the help! Happy coding ^_^
Upvotes: 3
Views: 1459
Reputation: 37632
I just got the same error message.
My app includes GsmComm and was working very stable under MS Windows Server 2008 R2 about 2 years. But about 1 month ago after system updates it had started works with errors.
And today I see the
No phone connected.
but the port and modem are detected properly by GsmComm!
I just inserted Huawei modem in my PC MS WIndows 10 (all last updates) and started my app and it sends SMS (COM5) just fine!
So my conclusion is the GsmComm has software conflicts AFTER updates on MS Windows Server 2008 R2.
I didn't trye to clean MS Windows Server 2008 R2 so I cannot tell you exactly the root of issue but I will.
So try to test your app under other machine.
I hope it will help you!
Upvotes: 0
Reputation: 237
After opening the port, make sure also that you are connected to the device that will send the SMS. Here is the code...
private void cmdConnect_Click(object sender, EventArgs e)
{
if (txtCommPort.Text == "")
{
MessageBox.Show("Invalid Port Number!");
}
else
{
comm = new GsmCommMain(txtCommPort.Text, 9600, 150);
Cursor.Current = Cursors.Default;
Cursor.Current = Cursors.WaitCursor;
comm.Open();
Cursor.Current = Cursors.Default;
if (!comm.IsConnected())
{
MessageBox.Show("No phone connected.");
}
else
{
MessageBox.Show("Connected!");
}
}
}
Upvotes: 1
Reputation: 31
Might be too late but i created a method that the serial port where gsm device is connected before connecting.you can also save the com22 directly to your code,thats if you won't move the device to another com.after getting the com where the device is you can save it to app setting,it another way to work it around.
Upvotes: 0