Hello everybody,

I have been working with C#, specifically PortSerial, so I've already read a
lot about that in MSDN Forum.

In a nutshell, I have a *client* that will dial a number and make a request,
whereas the *server* will response. The client dials, requests and
everything works pretty fine, whereas the server answer the call, but the
issue is just that doesn't receive the request! I am sure about that because
the instruction "MessageBox.Show("Received: " + received);", received =
"req", is never called, I mean the Message.ShowBox never shows "Received:
req";

Remark: I've been testing both application using two computers and phone
lines, so that a computer is the server whereas the other one is the client.

I've already spent much time working on it and until now I wasn't
successful.
Thanks in advance.

###Client###
this.serial = new SerialPort();
this.serial.DtrEnable = true;
this.serial.DataReceived += new
SerialDataReceivedEventHandler(this.port_DataReceived);


private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
            string received = serial.ReadExisting();
            Thread.Sleep(5000);
            MessageBox.Show("Message Received: " + received);
}

//Dial Method
private void button1_Click(object sender, EventArgs e)
{
            string number = textBox1.Text;
            if (!serial.IsOpen)
                serial.Open();
            serial.Write("ATDT" + number + ";\r\n");
            Thread.Sleep(5000);
}

//Request Method
private void button2_Click_1(object sender, EventArgs e)
{
            serial.WriteLine("req\r\n");
            Thread.Sleep(5000);
            MessageBox.Show("Message Requested");
}
###Client###



###Server###
this.serial = new SerialPort();
this.serial.DtrEnable = true;
this.serial.DataReceived += new
SerialDataReceivedEventHandler(this.port_DataReceived);

private void server_DataReceived(object sender, SerialDataReceivedEventArgs
e)
{
            string received = serial.ReadExisting();
            MessageBox.Show("Received: " + received);
            switch (received) {
                case "\r\nRING\r\n":
                    MessageBox.Show("Received: " + received);
                    this.serial.WriteLine("ATA\r\n");
                    Thread.Sleep(5000);
                    MessageBox.Show("Answered");
                    break;

                case "\r\nreq\r\n":
                    MessageBox.Show("Request Received");
                    this.serial.WriteLine("Oi\r\n");
                    Thread.Sleep(5000);
                    MessageBox.Show("Oi sent");
                    break;
            }
}
###Server###

-- 
Ramon Pereira Lopes

Reply via email to