An example: Using CPort Delphi Component to read data from your cellphone
Posted by Daniel - 11,731 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)
Leave a Reply
Hi, my name is Daniel Nugraha, a single male live on an island called Java, Indonesia. This is the place for me to share my interest in computer programming.
-
Get my Full Feed Here
Comments - Thanks Guys :)
Rangga Kusuma: Gan, Tengkiu buat postingan yang sangat berguna. Kebetulan ada project utk bikin sms gateway, dan converter Agan sangat berguna utk...
Chuck Norton: I actually went ahead & bolted over to Justin’s Get The Image plugin here: http://justintadlock.com/ar...
Chuck Norton: Question: is it possible to insert something like [custfieldimg=”joice1.jpg,15 0,1:1″] into the actual templates instead of...
Therese Lachance: Hi, Any idea how to have ContuttoPDF fetch the correct page language?
tresloukadu: yo how did u fixed when the tags shows <? and it shows < “& l t ; ” ?? please send me an email.













