By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,375 Members | 1,116 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,375 IT Pros & Developers. It's quick & easy.

Read data from GSM modem

100+
P: 250
I'm write code to read data from GSM modem. but it couldn't read modem response. Could you please help me? I'll post my code.
[PHP]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;
using System.Timers;
using System.Diagnostics;

namespace rainfall
{
public partial class Form1 : Form
{
//create an Serial Port object
SerialPort sp = new SerialPort();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void btn_Start_Click(object sender, EventArgs e)
{
sp.BaudRate = 19200;
sp.ReceivedBytesThreshold = 1;


try
{
//Open serial port
sp.PortName = "COM1";
sp.Open();

}
catch (System.Exception ex)
{
lblError.Text = ex.Message;
}
}

private void btn_Write_Click(object sender, EventArgs e)
{
try
{
//Write line to serial port
//sp.Write(texSms.Text + "\r\n");
sp.Write(txt_Sms.Text + "\r\n");
//texSms.Text = "";
txt_Sms.Text = "";
}
catch (System.Exception ex)
{
lblError.Text = ex.Message;
}
//Thread.Sleep(200);
//Set time delay
//System.Threading.Thread.Sleep(30);
//sp.WriteTimeout = 200;
}

private void btn_Read_Click(object sender, EventArgs e)
{
try
{
//Cler text box
//Read serial port and displayed the data in text box
Thread current = Thread.CurrentThread;
Thread.Sleep(1000);
txt_Sms.Text = sp.ReadExisting();
//texSms.Text = sp.ReadExisting();
sp.Write("Connected" + "\nS");

}
catch (System.Exception ex)
{
lblError.Text = ex.Message;
}
}
}
}[/PHP]
Jun 4 '08 #1
Share this Question
Share on Google+
1 Reply


100+
P: 366
Hi

the code what you have written is almost correct, make sure that the baud rate you are using matches with the modem you are using .

are you able to get response from hyperterminal which proves that your modem is working fine .

as far as code is considered what you have used is correct ,better check other things connection cable and your hardware.


Regards
nmsreddi
Jun 6 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.