Currently on my university we're doing communication between these old 56k modems. As messages from PC to modem go through the serial port, I thought to use System.IO.Ports.SerialPort .NET class.
I wrote pretty big C# application to communicate with modem, dial to other modem and communicate through them. It all worked fine till I managed to establish connection between two modems. When this happens, both modems (as it should be) switch from COMMAND mode (where I can send Hayes' commands to modem) to DATA mode (where all data I send to modem are being forwarded to the other modem).
My application can send things to, as well as receive things from serial port. It's installed on both connected PC's. But when I type something in my application, e.g. "Hello", it isn't received on the other side. And here comes the weird part. Here's how I'm sending messages through the serial port ('port' is an instance of SerialPort class, 'data' is an instance of a string):
port.Write(data);
So it works. It have to work. Especially, because if I use my application to send on the one side and PuTTy to receive on the other - it works! PuTTy connected to valid serial port receives my message. It also implicate, that not only my message comes to the first modem; it is being send by network to the other modem, and then the other modem sends it through the serial port to receiving PC. But that's not all. When I use my application to receive, I use SerialPort.DataReceived event, like this (of course method has been +=ed to event handler):
void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
//this message box should pop up if event hit:
MessageBox.Show("Data from serial port received!");
//calling my method to handle incoming message
DataReceived((SerialPort)sender);
}
And it works, when modem (one connected to receiving PC) is in COMMAND mode. E.g. when I send "AT" Hayes' command to modem (which means nothing more than a 'ping'), modem responds "OK", and I receive it. SerialPort.DataReceived event fires. But when this modem is in DATA mode (when I can't send Hayes' commands to it), and it receives a message from sending modem, and forwards it to serial port - nothing. Event doesn't even fire. I checked it well.
It's weird!
This only brings me to conclusion, that the way, in which modem sends message to serial port, is slightly different when in DATA mode and in COMMAND mode, and PuTTy somehow does understand that other way, and the SerialPort class does not.
I really don't understand this.