Hi,
I am writing a program that will connect to a modem via an RS232 port, and send commands, like for example to start a call.
Also I will need to read the feedback given from the modem, and by the code I have below, nothing is happening.
Can someone please help?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
namespace IREG_Tester_V2
{
class Program
{
static SerialPort port1 = new SerialPort();
static bool _continue = false;
static void Main(string[] args)
{
//Create Seriel Port Settings
port1.PortName = "COM3";
port1.BaudRate = 9600;
port1.Parity = Parity.None;
port1.DataBits = 8;
port1.StopBits = StopBits.One;
// Open the port for communications
port1.Open();
//Start Call
Console.WriteLine("Enter Number to Dial and press Enter");
string ip = Convert.ToString(Console.ReadLine());
port1.WriteLine("ATD" + ip + ";");
Console.WriteLine(DateTime.Now.ToLongTimeString());
//Console.ReadLine();
int pauseTime = 9000;
System.Threading.Thread.Sleep(pauseTime);
// During the 9 seconds pause, answer the call, and
// a messege OK should be received
//Disconnect Call
port1.WriteLine("ATH");
Console.WriteLine(DateTime.Now.ToLongTimeString());
Console.WriteLine("Call Disconnected!");
Console.WriteLine("Press enter to Exit!");
Console.ReadLine();
// Close the port
port1.Close();
}
public void SerialPortProgram()
{
Console.WriteLine("Incoming Data:");
// Attach a method to be called when there is data waiting in the port's buffer
port1.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
}
private void port_DataReceived(object sender,SerialDataReceivedEventArgs e)
{
// Show all the incoming data in the port's buffer
Console.WriteLine(port1.ReadExisting());
}
}
}