Link to home
Start Free TrialLog in
Avatar of Spike
Spike

asked on

Sending SMS messages via GPRS

I want to develope an application which will send SMS through GPRS, if GPRS is available,  if not- send the SMS in the conventional way.

Initially, I'm hoping to develop it using C#.net and Windows Mobile 6.

Could someone point me the right direction to get me started on this.
Avatar of alexey_gusev
alexey_gusev
Flag of United Kingdom of Great Britain and Northern Ireland image

Avatar of Spike
Spike

ASKER

Hi
Thanks for the reply. I think I need to explain it a bit more fully.
I'm writing an application that is to sit on a phone and send messages at a regular rate at quite frequent intervals top a modem. To save SMS being used, I want to send the messages via GPRS, if available.
Cheers
I understand, what I meant is that you need to open com port to communicate to GPRS on the phone and send AT commands. For regular SMS sending simply use PocketOutlook assembly (numerous samples everywhere on the net, just google it).
Avatar of Kalpesh Chhatrala
Avatar of Spike

ASKER

Regular sending of SMS messages is not a problem (I've written the application to regularly send SMS messages already.). i want to convert it to send these messages over GPRS instead.
I might be missing something, alexey_gusev, but aren't the links to articles explaining how to send GPRS messages from Hyperterminal on your PC?
ignore that it is about PC, the main idea is to open the com port and feed it AT command :)
it doesn't matter if that happens via hyperterminal or you do it yourself. AT commands is what you need, and how you send it it's up to you.
it seems that you want to send SMS from your mobile phone, using the GPRS technology.
If so, then you can purchase sms service from the service providers, like some companies provide you a push link where you have to input you senders mobile number, your login details and message. then the sms is sent to the respective number, note: their are multiple options for this costing very less for single sms
Avatar of Spike

ASKER

I understand the idea about sending it AT commands and have cobbled together the code to do this.
What I'm struggling with at the moment is getting my head around the opening of the COM port on the phone. I'm unsure of the settings required to open the COM port.
i.e.
port.PortName = how can I tell which port to use, or would it always be COM1?
Cheers
no, it wouldn't be COM1 usually, but the rest of the settings may be as follows:

7 bit, 115200 baud (this may vary), 1 stop bit, hardware control

Re. com port name, you might want to look at HKLM\Drivers\BuiltIn to find what port corresponds to Unimodem. Or maybe there will be something about GSM as well, depends on the device.
Avatar of Spike

ASKER

So the COM port  is device dependant and would  change depending on the phone being used?
How is this delt with as far as developing applications for different handsets, let alone OS?
Cheers
yes, this is device dependant. if you look at the registry, you can find there something about gprs or gsm. for instance, on my custom WinCE50 device there is the following key:

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\GPRS2440]

which tells me in its values that it can be accessed as "DSK1:"  :)  

So if I were you I would probably set the com port via some kind of configuration means. In general, if you want some 'auto-discovery' feature, you might try to open COM ports in a loop, writing there eg "ATZ" command and waiting for "OK", something like that.
Avatar of Spike

ASKER

OK- I've found a the following key in the registry:
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\CODEC_GSM610] There is no reference to GSM or GPRS.
I take it it is the Prefix value I need- I was expecting Value!
Cheers

just try COM ports from 1 to 9 and see if any of them returns you "OK" on "ATZ"
Avatar of Spike

ASKER

A bit confused now, sorry.
I've writen a quick application to send AT commands to the phone.
I've plugged in the phone via USB.
When I check which COM port is opened when I attach the phone, by checking the DeviceManager, no new COM port appears. The phone opens a new Network adapter (Microsoft Mobile Remote Adapter #4).
I've tried connecting to it using Hyperterminal, but the ports available don't work.
I could write a quick application to install on the phone to test which COM port to use, but shouldn't I be able to send it AT commands from Hypperterminal?
(I've upped the points- this is becoming more involved that I thought it would be).
Avatar of Spike

ASKER

Ok
An update- I've tried setting the phone up as a new  connection, via the Network and Sharing Centre (I'm using Windows 7). I tried adding it as a new Dial Up Connection and I received the message that a dial up modem could not be detected. The mobile is connected OK (it is listed up the Device Manager as a Portable Device rather than as  a Modem). Ideas?
>> I'm writing an application that is to sit on a phone and send messages at a regular rate at quite frequent intervals top a modem
hold on, did I misunderstood you? Why are you trying to connect the phone to the desktop PC? As far as I perceive what you want to achieve is this:

- you have the phone which has GPRS/GSM modem
- you want to use it (the phone + GSM) to send SMS messages

So then you need to find the port GSM is sitting on, and send AT commands to that port. All this does NOT involve any desktop parts at all :) [ well, apart from using VS2005/2008 and ActiveSync/WMDC for debugging etc ]

Am I missing something?
Avatar of Spike

ASKER

I was going to send the commands via Hyperterminal just to detect the port.
No matter- I've moved on.
I believe I've got the right COM port, by writing a small app for the phone.
I'm just writing the bit to send a message, so hopefully I'm on the home straight now.
I'll leave this open for now and come back with any further issue soon.
If all goes well I'll close it this off shortly.
Cheers
Avatar of Spike

ASKER

Hi
Ok back to this - the idea of having the right port was wrong- possibly!
I can Open a port on the phone (OK- I can open a few, but I've tried the following with all of the ones that "open").
I have tried sending AT commands to the open port- but don't seem to  be getting any response.
However, when I opened the port , one setting I did't know what to enter was the encoding:( i.e.
port.Encoding). I'm guessing  this is required.
How can I determine what these settiungs should be?
Cheers
it has to be ascii I think, so port settings are usually like that:

115200, 7 bit, No Parity, 1 Stop Bit

Have you tried all com ports from 1 to 9?
Avatar of Spike

ASKER

Yes- (actually up to 10.)
When I try to set the port to open- I can get some of them to open OK (I check this by checking the status of the potrt).
However, I never get a response from any of them.
Currently, I'm runnning the application on the phone via my laptop, and deploying it on a Trio Pro.
hmm, ok, this one should have GSM module. perhaps it simply doesn't have it? then opening the com port and sending AT commands won't work :(

Check also these links in case you're on CDMA and on on GSM, maybe it would help:

http://www.sendsms.cn/download/CDMA_AT_178.pdf
http://igor.chudov.com/manuals/AT_Commands-For-CDMA-Modems-Incl_Qualcomm_U300.pdf
Avatar of Spike

ASKER

I've actually now installed the app on the trio, and enabled the selection of which COM port to open. Still no joy in getting a message back.
Avatar of Spike

ASKER

Could someone comfirm whether you actually need a GPRS data contract with your SIM to be able to get message responses from sendning AT commands to the relevant port?
Cheers
I use pay-on-the-go SIM on the device (WinCE 5.0) with GSM/GPRS, and sms sending works fine. GSM uses COM3 which I send to/read from.
Avatar of Spike

ASKER

Hi
Not really what I meant. I've enabled GPRS on the phone, but don't actually have a SIM with GPRS.
Will the phone still respond to simple AT commands in this case- or do I need to have a GPRS SIM to receive even "OK" back.
If you attach a GSM device via a USB cable it won't automatically pop up as a COM port. Normally there is a bit of software which comes with the device which will enable a COM simulation. What is the name/type of device you are using?
Avatar of Spike

ASKER

Hi-
I've written a Windows Mobile applicsation  in C#
Rather than sending SMS messages I want use GPRS.
I am using Visual Stio to develop it.
I am using the Windows Mbile Device Centre to communicate with it.
I have added some code to the application just to test the sending of AT commands.
I can select the port to use on the phone (1-10)
I open the port (then display the state of the port (open/ closed).
I then send simple AT command to it to see if I can get the response "OK".
I have tried running this application from VS, deploying it to the phone (it deloys fine)- as well as actually installing it on the phone.
I never get OK back.
I have enable GPRS on the phone (but don't actually have a SIM account with GPRS).
Should I still get a OK back when sending AT commands?
Cheers
I
You didn't answer my question.

If the phone actually does map to a COM port, then open HyperTerminal, select the relevant port and type ATZ or AT0 or just AT, followed by return. One of those commands must return either OK or an error. If nothing happens then there is no connection between a Windows virtual serial port and the device, probably because some software is missing. If you cannot even open the port, the software is definitely missing.
Avatar of Spike

ASKER

I'm not expecting that when I connect the phone  via a USB cable it won't automatically pop up as a COM port.  (I did when I started this- but I've moved on!). (The phone is a Trio, by the way.)
I'm opening the COM port on the phone via the phone appication - I'm not using Hyperterminal to send commands to the phone.
I have written an application that simply opens a COM port (on the phone) then sends AT commands. The application is running on the phone (or in VS and depoyed to the phone).
I can open (and close) each of the ports on the COM ports on the phone OK- and when I check their status it returns that it has been oppened or closed.
I have tried send AT commands to each of these ports  (that open), but get no response from them.
I  think hyperterminal will complicate it further as I can already send AT commands.
Well, you can't send AT commands, since you don't get any reply. The simplest command ATZ resets the phone and should always give a OK response.

I'd open the COM port and set 8,N,1 as the bits per byte, parity and stop bit, then set 9600 speed (just to be on the safe side). Perhaps you might publish a bit of your code? PS sometimes you have to wait a bit for any reply. I time out after 5 seconds, longer when sending PDUs, but that's another matter.
Avatar of Spike

ASKER

Hi
I was trying to send more complicated commands but have reduced it to just AT- just to get a response!  I do seem to be able to open the ports OK.

To open the port:
~~~~~~~~~~~~~~
port.PortName = p_strPortName;                 // eg: COM1
port.BaudRate = p_uBaudRate;                   //9600
port.DataBits = p_uDataBits;                   //8
port.StopBits = StopBit.One;                  //1
port.Parity = Parity.None;                     //None
port.ReadTimeout = p_uReadTimeout;             //300
port.WriteTimeout = p_uWriteTimeout;           //300
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
port.Open();
port.DtrEnable = true;
 port.RtsEnable = true;

To write to the port:
~~~~~~~~~~~~~~~
port.DiscardOutBuffer();
port.DiscardInBuffer();
receiveNow.Reset();
port.Write(command + "\r"); //where command is just  AT at the moment

Then:
~~~~~~~~~~~~~~
string input = ReadResponse(port, responseTimeout); //where Timeout is currently set to 1000
Can you tell me whether SerialDataReceivedEventHandler actually fires?

I suspect that port.Open() actually does nothing other than set up the software side.
Avatar of Spike

ASKER

I'll have get back to you on that.
I'm snowed in at the moment and the phone is at work!
I'm assuming the simulator woun't respond to AT commands- is there a bolt on GPRS simulator available anywhere?
By the way, I did remove:
port.Encoding = Encoding.GetEncoding("iso-8859-1");
as it caused errors- should I be using something similar?
It is some time since I worked on out GPRS modem software and in those days I used the Nokia Tool Kit. You might find something on the Nokia site.

The encoding option is not an issue. Forget it.

In those days I had several phones to test the compatibility of our software and I always used Hyperterminal to establish that the phone actually had the interface. Some older phones did not support the establishment of a TCP/IP connection and therefore did not respond to AT commands or to specific comands. Your phone has actually three SIM cards in it. I don't think I was able to get my phone to work without a SIM card (if that's an issue?), and I'd like to know how you know with which SIM card one communicates with?
Avatar of Spike

ASKER

"Your phone has actually three SIM cards in it. "???  it has a O2 SIM card installed (no GPRS on the SIM)- am I missing something?
The reason I'm not using hyperterminal is that I couldn't seem to get it communicate at all.
When the phone was plugged in usin the USB cable, if you look back at my posts, you'll see when  I plugged in the phone via USB,  I check which COM port is opened by checking the DeviceManager, no new COM port appears. The phone opens a new Network adapter (Microsoft Mobile Remote Adapter #4).
I've tried connecting to it using Hyperterminal, but the ports available didn't work.
The phone is a very new Windows Mobile-based Palm Treo Pro.
>>no GPRS on the SIM)- am I missing something?

No, you wrote "Trio" and not "Treo pro". The Trio is a multiple SIM device so that one can open more than one channel and multiplex TCP/IP over a slow network.
Avatar of Spike

ASKER

Sorry!
Avatar of Spike

ASKER

Hi

I'm still awaiting a response to the question Could someone comfirm whether you actually need a GPRS data contract with your SIM to be able to get message responses from sendning AT commands to the relevant port?"

Re:"Can you tell me whether SerialDataReceivedEventHandler actually fires?"
It's difficult to tell: for some reason I can't use breakpoints- they become disabled when I run the code (in debug moode)- both on the simulator and when deployed to the phone.

Cheers
>>It's difficult to tell: for some reason

You build in a bit of code which writes the event into a file. If the file is empty no event.

I still think you ought to be able to test the device with Hyperterminal, since this is the only real way of ascertaining whether the device does implement AT commands.

>> Could someone comfirm whether you actually need a GPRS data contract with your SIM to be able to get message responses from sendning AT commands to the relevant port?"

It all depends on the device. I have always tested WITH a SIM card, since I wanted to actually SEND data, so I can't tell whether it is the case with your device. In any event one needs to know the exact model number in order to tell whether the device actually implements AT commands.
if it works with Pay-as-You-Go SIM cards, then I believe the data plan is unnecessary.
Avatar of Spike

ASKER

"I still think you ought to be able to test the device with Hyperterminal, since this is the only real way of ascertaining whether the device does implement AT commands."

As stated in an earlier poat:

"The reason I'm not using hyperterminal is that I couldn't seem to get it communicate at all.
When the phone was plugged in using the USB cable, if you look back at my posts, you'll see when I plugged in the phone via USB, I check which COM port is opened by checking the DeviceManager, no new COM port appears. The phone opens a new Network adapter (Microsoft Mobile Remote Adapter #4).
I've tried connecting to it using Hyperterminal, but the ports available didn't work.
The phone is a very new Windows Mobile-based Palm Treo Pro. "

How do I get Hyperterminal to control it?




if you want hyperterminal, you might try this one: http://www.tsreader.com/ztermppc/index.html

or just open com ports from the code (as you have been trying already)
>>port.PortName = how can I tell which port to use, or would it always be COM1?

Yes we are going around in circles because this is the primary problem.

A USB device HAS TO HAVE SOFTWARE installed to make it behave like a serial device. This might be com0com (freeeware) or it might be propierty. In order to tell whether the device HAS this option, I need the product name and it's model number. In that way we might to able to find out whether the device actually supports AT commands and if so how or with what driver/connector.
@BigRat: OP is doing it on Windows Mobile device [>> Initially, I'm hoping to develop it using C#.net and Windows Mobile 6.], so it is NOT a desktop and hence USB and com0com are nice but certainly not available :)
ASKER CERTIFIED SOLUTION
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Spike

ASKER

I've had a look at these links and they look as if they will provide the answer.
However, whilst I was waiting, I've decided to probably use a Webservice instead!
I'm going to close this, accepting BigRat's solution- as it at least  points me in the right direction-(if I do change my mind again.)
Thanks for the help!