Is it possible to use a serial port like session in c#?

Posted by Pandiya Chendur on Stack Overflow See other posts from Stack Overflow or by Pandiya Chendur
Published on 2010-06-17T04:16:00Z Indexed on 2010/06/18 16:33 UTC
Read the original article Hit count: 169

Filed under:
|
|
|
|

I am using serial port communication in my asp.net webform application...

 private bool sendSMS(int portNo, string mobNo, string details)
    {
        try
        {
            SerialPort SerialPort1 = new SerialPort();
            SerialPort1.PortName = "COM" + portNo.ToString();
            SerialPort1.BaudRate = 9600;
            SerialPort1.Parity = Parity.None;
            SerialPort1.DataBits = 8;
            SerialPort1.StopBits = StopBits.One;
            SerialPort1.RtsEnable = true;
            SerialPort1.DtrEnable = true;
            SerialPort1.Encoding.GetEncoder();
            SerialPort1.ReceivedBytesThreshold = 1;
            SerialPort1.NewLine = Environment.NewLine;
            SerialPort1.Open();
            SerialPort1.Write("AT" + SerialPort1.NewLine);
            Sleep(500);
            SerialPort1.Write("AT+CMGF=1" + SerialPort1.NewLine); 
            Sleep(500);
            SerialPort1.Write("AT+CMGS=" + (char)34 + mobNo + (char)34 + 
                                        SerialPort1.NewLine); 
            Sleep(1000);
            SerialPort1.Write(details + (char)26);
            Sleep(2000);
            SerialPort1.Close();
          }
        catch
        {

        }
        return true;
    }

This method works when i send i single message... But when want to send sms in bulk opening and closing port everytime is not a good idea... So my question is it possible to use a serial port like session in c#?... When i open a port i want it to be open for 1 hour and then if my time expires i want to close the port and open it the next time... Any suggestion...

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET