Implementation of sms cat Software (C #) Implementation of sms cat (simplified test version)

Source: Internet
Author: User

In the previous article, we completed a C # class library for SMS cats and provided APIs for sending and receiving text messages. This article provides the use of this API and implements a simple sms cat software, which has been able to complete the basic functions of the SMS cat.

The previous project file can generate the gsmmodem. dll file.ProgramIt is implemented by calling Fang fa in this file. Running interface:

Program Implementation function: automatically scans the computer's serial port and displays it in the combox control for the user to choose from; provides two baud rate options, 115200 (not enough can be added through attributes); can send text messages of less than 70 words; read text messages by index number; new message arrival prompt; read new message. The read information only supports USC2 encoding. garbled characters are displayed in the content of the 7-bit text message. You can solve this problem by adding 7bit encoding decoding.

Okay. Let's start to explain how to implement it.

Create a project, add the reference browsing tab, select MODEM. DLL to open, and then add a namespaceUsing gsmmodem;Then we can use the class we implemented in the previous article.

For details about this C # class library, refer:
Implementation of sms cat Software (C #) <6> sending and receiving sms c # implementation (API)

 
1:PrivateGsmmodemGM =NewGsmmodem(); // Instantiate the device class

Scan the computer serial port and add the combox1 control:

 
1: 
2:Foreach(StringSInSerialPort. Getportnames ())
 
3:{
 
4:Combobox1.items. Add (s );
 
5:}
    • Send SMS:
1:Key to text message sendingCode
2:Try
3: {
4:GM. sendmsg (textbox1.text, textbox2.text); // call the device method to send a text message
5:}
6:Catch
7: {
8:Label6.text ="Failed to send";
9:Label6.forecolor =Color. Red;
10:Return;
11:}
  • Read SMS:

     
    1:Read key text message Codes
     
    2:Try
     
    3: {
     
    4:GM. readmsgbyindex (Convert. Toint32 (textbox3.text ),OutMsgcenter,OutPhone,OutMSG,OutTime); // call the method of the device object to read the SMS by serial number
     
    5:Textbox4.text ="SMS center :"+ Msgcenter +"\ R \ n"+"Mobile Phone number :"+ Phone +"\ R \ n"+
    6:"Text message content :"+ MSG +"\ R \ n"+"Sent :"+ Time. substring (0, 4) +"-"+
     
    7:Time. substring (4, 2) +"-"+ Time. substring (6, 2) +""+ Time. substring (8, 2) +
     
    8:":"+ Time. substring (10, 2) +":"+ Time. substring (12, 2 );
     
    9:Label9.text ="Read successful";
     
    10:Label9.forecolor =Color. Green;
     
    11:}
    12:Catch
     
    13: {
     
    14:Label9.text ="Reading failed";
     
    15:Label9.forecolor =Color. Red;
     
    16:Return;
     
    17:}
  • Delete SMS:
     
    1:Delete text message key code
     
    2:Try
     
    3: {
    4:GM. deletemsgbyindex (Convert. Toint32 (textbox3.text); call the device method to delete
     
    5:}
     
    6:Catch
     
    7: {
     
    8:Label9.text ="Deletion failed";
     
    9:Label9.forecolor =Color. Red;
     
    10:Return;
     
    11:}
  • New SMS prompt:

This part is troublesome. For more information about delegation, callback functions, and events, see msdn.

 
1: 
 
2:// Delegate the callback function delegate that receives the text message
3: Delegate voidUpdatadelegate();// There can be parameters, which are not required here
 
4: UpdatadelegateUpdatehandle =Null;
 
5: 
 
6:Private voidForm1_load (ObjectSender,EventargsE)
 
7:{......
8:GM. onrecieved + =NewGsmmodem.Onrecievedhandler(Gm_onrecieved );
 
9: 
 
10:Updatehandle =NewUpdatadelegate(Updatelabel8 );// Instantiate the delegate
 
11: 
 
12: }
 
13: 

 GM. onrecieved + =NewGsmmodem.Onrecievedhandler(Gm_onrecieved );After receiving the text message, the system automatically runs the gm_onrecieved function.

1:VoidGm_onrecieved (ObjectSender,EventargsE)
 
2:{
 
3:Invoke (updatehandle,Null);
 
4:}

There is only one sentence in the function: Call the function pointed to by the callback function handle updatehandle.
Updatehandle =NewUpdatadelegate(Updatelabel8 );// Instantiate the delegate
Indicates that the name of the function to be called is updatelabel8.

1:VoidUpdatelabel8 ()
 
2:{
 
3:Label8.text ="New Message available";
 
4:Label8.forecolor =Color. Green;
 
5:}

The function body changes the text property of the control, prompting you to receive a new message. You can also directly read the text message content here.
Read new messages:

1:GM. readmsgbyindex (GM. newmsgindex,OutMsgcenter,OutPhone,OutMSG,OutTime );

Call the serial number to read the text message: the serial number is provided by newmsgindex.

Attachment: project documents

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.