views:

1010

answers:

4

Hi,

I'm trying to send a sms via a Nokia phone over serial which is easy enough via putty. The commands from the nokia documentation works fine.

However, trying to send the same commands from a c# application fails miserably. I've run Sysinternals PortMon and can see the commands come through OK, the only difference I can see is in the way it connects but I am having trouble finding the commands that would iron out those differences.

The code I'm running looks a little bit like this

using (SerialPort port = new SerialPort(comPort, 9600, Parity.None, 8, StopBits.One))
      {
       port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
       port.ErrorReceived += new SerialErrorReceivedEventHandler(port_ErrorReceived);

       //port.ReceivedBytesThreshold = 1;
       port.DtrEnable = true;
       port.RtsEnable = true;
       port.ReadTimeout = 1;
       port.Handshake = Handshake.XOnXOff;


       try
       {
        port.Open();

        port.WriteLine("AT");

        port.WriteLine("AT+CMGF=1");

        port.WriteLine("AT+CMGS=\"" + number + "\"");

        port.WriteLine(message);

        port.Write(new byte[] { (byte)26 }, 0, 1);
       }
       finally
       {
        if (port.IsOpen)
        {
         port.Close();
        }
       }

The differences I'm seeing in the trace from the serial port are

At the start

0.00001844  aspnet_wp.exe IOCTL_SERIAL_SET_HANDFLOW USBSER001 SUCCESS Shake:1 Replace:43 XonLimit:4096 XoffLimit:4096

And at the very end

0.00061153  aspnet_wp.exe IOCTL_SERIAL_PURGE USBSER001 SUCCESS Purge: RXABORT RXCLEAR 
0.00004442  aspnet_wp.exe IOCTL_SERIAL_PURGE USBSER001 SUCCESS Purge: TXABORT TXCLEAR

Has anyone got any tips on how to iron out these issues? I also notice that the phone is not responding back to the application with any acknowledgement when I issue a command so I suspect the problem is with the connection, not those messages at the end.

+1  A: 

Try to see if you can read out the serial communication from the phone. After you send 'AT', the phone should respond with 'OK'. It might be a good idea to verify that the serial communication is working before taking on the SMS bit.

From what I remember, I think that after AT+CMGS the message should be entered and followed by ctrl-z, and no newline is needed. Could you try changing the WriteLine(message) to Write(message)?

Hope this helps!

ylebre
this is definitely NOT happening. therefore i guess the issue is the line that has the Shake, Replace on it. Guess I better keep trying to figure out what the issue is with that.. Thanks.
marshall
A: 

You need to wait for the ">" before writing out the message. Also, don't terminate the message with a CR/LF (WriteLine).

Aki Korhonen
A: 

did you get your answer? I'm having the same problem.

sepidweb
no sorry, never figured it out!
marshall
A: 

i found the answer !!

biggles
Then you should post it here.
sth