I’m using following code to send sms throuh gsm modem
for (int i = 0; i < 10; i++)
{
MSComm1.CommPort = 3;
MSComm1.PortOpen = true;
MSComm1.Output = "AT" + '\r' + '\n';
Thread.Sleep(1000);
MSComm1.Output = "AT+CMGF=1" + '\r' + '\n';
Thread.Sleep(1000);
MSComm1.Output = "AT+CMGS=" + '\"' + MobileNo + '\"' + '\r' + '\n';
Thread.Sleep(1000);
MSComm1.Output = MsgTxt + (char)26;
Thread.Sleep(1000);
MSComm1.PortOpen = false;
}
my question is:
i want to open the port as in (MSComm1.CommPort = 3;) only if it is not already opened. so that i don’t have to open and close it again and again for each sms as in the above loop
You should ditch the MSComm ActiveX control if you’re using any language/framework designed in the last decade or if you’d like your application to run on new or newer machines/Operating Systems.
Instead you can use the SerialPort class provided in the .Net Framework: