An example: Using CPort Delphi Component to read data from your cellphone
Posted by Daniel - 9,261 Views
CPort is a Delphi component created by Dejan Crnila. it provide interfaces for Delphi programmers to use the serial communication ports. If you need to utilize serial modem or any other serial communication devices in your Delphi application, you should use this component.
This short article will give you an example of using CPort Delphi Component to read the raw data returned from a cellular phone as responses to the GSM AT-Command given, such as ATE1 (echo) and AT+CMGL (read sms). We will use Siemens cellphone for this purpose.
In order to be able to read data from the cellphone (with the assumption that you had installed the CPort Delphi Component) you need to do three steps in general:
- Set the cellphone connection settings such as the serial port to connect and the baud rate.
- Send the AT-Command to the cellphone
- Parse the responses
Fortunately CPort has a setup dialog where we can easily set the connection parameters of the cellphone. You can do it by executing the ShowSetupDialog; procedure.
To send the command with CPort you can use WriteStr(const Str:string); method, where Str is the command string to send. Below is an example:
var s : string;
begin
s := strCommand + Postfix;
Comm1.WriteStr(s);
end;
There is a Postfix parameter. According to the GSM AT-Command specification this character is needed to indicate the end of the command. For example to ask the cellphone to return a string data about its model, the complete command string is,
To read the responses with CPort you can use ReadStr(var Str:string; Count:integer); method inside the CPort’s OnRxChar event procedure block, where Str is the string returned and Count is the buffer length. Following is the example:
var Str: String;
begin
Comm1.ReadStr(Str, Count);
Memo1.Text := Memo1.Text + Str;
end;
When you send a command string to the cellphone, CPort will trigger the OnRxChar event procedure. Write your code between that procedure block to handle the data returned by the cellphone. In the above example, the data is stored in the Str variable and then displayed inside the Memo control as string.
To get a better understanding of this article, you can download the AT-CMD Tester project source code. It uses the same code as mentioned above. This code has been tested using the following Siemens cellphones: C35i, C45, ME45 and CX65 with the appropriate data cable for each phone via serial port.
Related Resoursces:
- Visual Basic Version of ASCII-to-PDU and PDU-to-ASCII Converter Functions
- Delphi SMSCodec - SMS Processing Component
- C Version of ASCII To PDU Converter
- SMS and the PDU format
__________________________
The following posts are programmatically considered as related to the current post by YARPP Plugin:
- CPort Component (Serial port interface component for Delphi)
- MPEG Audio Component (A Delphi component to play audio files)
- Delphi SMSCodec (SMS Processing Component)
- Runtime-Form-Creation. Automatically creating child forms in a Delphi MDI application with a component array
- XP Menu Component (MS-Office XP style on Delphi menu and toolbar)
Related posts brought to you by Yet Another Related Posts Plugin.
Latest from Programming
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- SmartImageResizer Plugin, WordPress plugin based on Joe Lencioni’s Smart Image Resizer
- Resize Image or Crop Image with Joe Lencioni’s Smart Image Resizer, WordPress Setup
- Free Softwares to help you learn Regular Expression or to enhance your RegEx skill
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
Leave a Reply
Latest Blog Entries
- Sweet Home 3D, a free home design software
- 26x Optical Zoom on a Compact Digital Camera?
- Windows 7 Release Candidate is now available
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
- The Lack of Chances is the Source of Poverty, Can we make a different?
- SmartFTP Client is no longer Free. What would be the best replacement for it?
- Kantaris Media Player, The most suitable Free Media Player on my Audio Environment
Categories
Neighbours and Friends
- Anti Teori
- Busby SEO Test Page
- Deny Sri
- Digital Media Convert
- Freeware Maniac
- Oeroek
- RidhoCyber
- Suraja Web
Comments - Thanks Guys :)
Therese Lachance: Hi, Any idea how to have ContuttoPDF fetch the correct page language?
Marlena Albu: Super Blog, Dude! I am constantly on the watch for new and interesting sites and postings about audio equipment… which is what...
tresloukadu: yo how did u fixed when the tags shows <? and it shows < “& l t ; ” ?? please send me an email.
Sean: This is a great piece of code and thanks for adding the updates. Sean’s last blog post: Not All Text Message Marketing Is Created...
rodhy: Thank for your code, it very usefull for me. best regard.
Most Popular Entries
- Passing arguments to your VB.NET console application
- ConsoleProgressBar - Simple Progress Bar Function for your VB.Net Console Application
- ASCII To PDU Converter (Convert ASCII to PDU and vice versa)
- An example: Using CPort Delphi Component to read data from your cellphone
- Microsoft Excel Import External Data Problem: When Microsoft Query doesn’t recognize some of your parameters
Software Collections
- Sweet Home 3D, a free home design software
- SmartFTP Client is no longer Free. What would be the best replacement for it?
- Kantaris Media Player, The most suitable Free Media Player on my Audio Environment
- TCPView for Windows, Tool to check TCP and UDP Connections on your system
- The Code Snippet Plugin, my favourite syntax highlighter plugin for WordPress
Blogging Related Stuff
- Change the WordPress permalink structure to the best format, and yes it’s a little bit scary :D
- Something is wrong, the Google Search Result from my blog looks bad, don’t laugh please :D
- Several tips to reduce Blog Noise, especially when your blog covers more than one niche
- How to remove your indexed pages or even your entire site from Google and Yahoo!

















