Click here to Skip to main content
16,022,971 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Using the SerialPort.Write() example listed on MSDN (http://msdn.microsoft.com/en-us/library/y2sxhat8.aspx), whenever Read() is called, it only returns whatever was originally written to the device. (ie. I send "AT", it responds "AT", etc.) Using a terminal program, such as PuTTY, the device functions fine, returning what it should. Any idea why this would be happening?
Code used:
public static void Main()
{
    string name;
    string message;
    StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
    Thread readThread = new Thread(Read);
    // Create a new SerialPort object with default settings.
    _serialPort = new SerialPort();
    // Allow the user to set the appropriate properties.
    _serialPort.PortName = SetPortName(_serialPort.PortName);
    _serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate);
    _serialPort.Parity = SetPortParity(_serialPort.Parity);
    _serialPort.DataBits = SetPortDataBits(_serialPort.DataBits);
    _serialPort.StopBits = SetPortStopBits(_serialPort.StopBits);
    _serialPort.Handshake = SetPortHandshake(_serialPort.Handshake);
    // Set the read/write timeouts
    _serialPort.ReadTimeout = 500;
    _serialPort.WriteTimeout = 500;
    _serialPort.Open();
    _continue = true;
    readThread.Start();
    Console.Write("Name: ");
    name = Console.ReadLine();
    Console.WriteLine("Type QUIT to exit");
    while (_continue)
    {
        message = Console.ReadLine();
        if (stringComparer.Equals("quit", message))
        {
            _continue = false;
        }
        else
        {
            _serialPort.WriteLine(
                String.Format("<{0}>: {1}", name, message) );
        }
    }
    readThread.Join();
    _serialPort.Close();
}
public static void Read()
{
    while (_continue)
    {
        try
        {
            string message = _serialPort.ReadLine();
            Console.WriteLine(message);
        }
        catch (TimeoutException) { }
    }
}
Posted

1 solution

AFAIK GSM modems are mirroring what was sent. Putty sends characters codes to the device and doesn't print it on the screen (unless you force it too). Device mirrors what have you typed in in the terminal as a feedback.

So in your program you see one response from keyboard and one from the device.

This is only a clue - I didn't examine your code carefully :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900