TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
saeid farahi
NA
3
0
AT commands and modems using serial port
Feb 12 2010 8:43 AM
Hi, I wrote some code for two modems: one, must send some string and another must answer the call and receive the string. My receiver modem is a D-Link voice-modem which has COM port, and the sender modem is a NetForce usb2.0 data-modem. Two modems are connected to two different computers and each one has a phone line. I first run the receiver's code and then the sender's code. Here's the code for each of them and log files:
The receiver modem's code:
<pre>
SerialPort sp = new SerialPort("COM1");
private void Form1_Load(object sender, EventArgs e)
{
sp.NewLine = "\r\n";
sp.Parity = Parity.None;
sp.DataBits = 8;
sp.StopBits = StopBits.One;
sp.DtrEnable = true;
sp.WriteBufferSize = 1024;
sp.Open();
sp.WriteLine("ATE0");
sp.BaseStream.Flush();
sp.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(sp_DataReceived);
}
void sp_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string str;
str = sp.ReadLine();
if (str == "RING")
{
sp.WriteLine("ATA");
sp.BaseStream.Flush();
}
System.IO.File.AppendAllText("c:\\log_receiver.txt", str + "\r\n");
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
sp.Close();
}
</pre>
and its log file(log_receiver.txt):
OK
RING
CONNECT 9600
And sender's code:
<pre>
SerialPort sp = new SerialPort("COM8");
private void Form1_Load(object sender, EventArgs e)
{
sp.NewLine = "\r\n";
sp.Parity = Parity.None;
sp.DataBits = 8;
sp.StopBits = StopBits.One;
sp.DtrEnable = true;
sp.WriteBufferSize = 1024;
sp.Open();
sp.WriteLine("ATE0");
sp.WriteLine("ATDT6632");
sp.BaseStream.Flush();
sp.WriteLine("My string to be sent");
sp.BaseStream.Flush();
sp.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(sp_DataReceived);
}
void sp_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string str;
str = sp.ReadLine();
File.AppendAllText("C:\\log_sender.txt", str + "\r\n");
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
sp.Close();
}
</pre>
and the sender's log file(log_sender.txt);
ATE0
OK
NO CARRIER
I have read all the commands of the Hayes AT commands, but there were no tutorial about how to use the commands(I know that using commands may differ in some modems). I wanted to know that where's the problem of my code and does anyone have an idea about using AT commands in order to send and receive data between modems?
Reply
Answers (
2
)
C# - Create TXT file & then execute cmd batch that copies the file to printer
Generics