Table of contents
Since I got my first mobile phone, I was always dreaming about sending my SMS messages from a PC. When I first found a program, which was able to do that, I was the happiest man around the world - no more typing on the phone's little keyboard. And a week ago I found an article on the Internet about Vista gadgets. After I read the article, an idea came to my mind: 'Hey, maybe I could do something useful. Maybe I could make a Gadget, that is able to send SMS's..' I tried it, and the
MobileControl Gadget is the result.
NOTE: I assume, you are at least a little familiar with Vista Gadgets, I won't write about how to create a Gadget, but how I've made "this" Gadget.
NOTE: The main goal was to create an SMS-sender. The call control features are experimental stuff, thus there may be some issues with them. Actually, there is one I know about: On some phones, the voice mail is called after hanging up an incoming call with the Gadget. I don't know the reason, but I hope there is a solution.
With this Gadget you can send messages, initiate/hang up calls; incoming calls are also displayed. But wait a minute - you've not even installed it yet. So, double-click on MobileControl.Gadget file found in MobileControl.zip, and Vista will install the Gadget for you. It will even add it to the Sidebar - go, and remove it. Why? Because you have to register the ATCommandHelper.dll, which is the heart of this Gadget. Open a command prompt from the Gadget's bin directory (%USERPROFILE%\AppData\Local\Microsoft\Windows Sidebar\Gadgets\MobileControl.Gadget\bin), and type the following command:
regsvr32 ATCommandHelper.dll. That's all folks, the Gadget is installed!
Add the Gadget to the Sidebar, if you haven't done that yet! Here is a picture of
MobileControl in action - you have to see something similar:
MobileControl is running, and you can't wait to try it. First, you need to know the port, your phone is communicating. I'll show you, how to find it out with a Bluetooth connection. Open "Control Panel", and choose "Bluetooth Devices". Select your phone, and click on the "Properties" button. On the "Properties" pane, go to "Services" tab. You will find the needed information there.
Now open the Settings page of the Gadget, and pick the proper port!
Well, your Gadget is ready to establish a connection with your phone, so click the "Connect" button! When this button's text changes to "Disconnect", the Gadget is ready to send commands to the phone. There are two text boxes - the little for the phone number, and the bigger for the SMS text. There are some restrictions about the number and the message:
- Phone number has to be in international format (Country Code + 9 digits).
- SMS message cannot be longer than 160 characters.
- SMS message can contain only ASCII characters.
UserControl DLL in C#, and I embedded it in a simple HTML.
This task is quite easy - you just need to create a new Windows Control Library project in Visual Studio. The Control has to have a unique ID, and it has to be COM visible. This can be done with these two lines before the
public partial class ATCommandControl : UserControl
A GUID can be generated with Microsoft's GUIDGen program, or on this web page. That's it. Now your Control can be embedded in a Gadget with these lines in the Gadget's HTML's
OK, that's it, the Control is embedded in the Gadget. Now you can call every
var o = document.getElementById("ATCommandHelper");
AT commands are used to control a phone/modem through a serial connection. These commands are stored as strings, and they're converted to a byte array before we send them to the phone. After the conversation, the byte array is written to the port. The phone receives the command, and executes the proper action. Here is the code that sends the string
command to the COM port
endChar is the 'end command' character - it can be
byte data = new byte[command.Length + 1];
for (int i = 0; i < command.Length; i++)
data[i] = (byte)command[i];
data[command.Length] = endChar;
port.Write(data, 0, command.Length + 1);
OnError("Please check, that your phone is correctly connected to the PC,
and you've selected the proper COM port!");
SMS messages are sent in PDU format, so another conversation is required for them. If you want to know more about PDU format, I recommend this page. The conversion takes place in the functions
string SeptetsToOctets() and
string ConvertMessageToPDUFormat() in my source code. I assume, this PDU-thing will be all clear after reading the page mentioned above and examining my source code.
Maybe you have noticed, that instead of a Settings.html in the Gadget's folder, there is a Settings.html.template. Why? And what is that .template file? Well, I've mentioned earlier, that I'm not too familiar with JS, thus I didn't know how to pass a string array from the Control to Settings.html. The array, I wanted to pass, contains the names of the existing COM ports on the system, so I really need it to populate the ports combobox on the Settings.html. So I have written a template Settings.html, with an empty port list. The
WriteSettingsHTML() function in the
ATCommandHelper's constructor reads that template line by line into a buffer, appends the port name information to it, and writes the buffer to the Settings.html file. Maybe this is not the most elegant solution, but it works.
- First published: 2007.01.29.