The usage method is simple. You only need to call the corresponding method of the instantiation class, and then process the method based on the returned value!
Mygsm GSM = new mygsm ("com3", 9600 );
Call: GSM. Call ("15000450819 ");
SMS: listbox1.items. Add (GSM. sendmsg ("15000450819", "I will send another SMS csabcd !, Haha! "). Tostring ());
Obtain the mobile phone machine code: listbox1.items. Add ("machine code:" + GSM. getmachineno ());
Obtain the SMS center number: listbox1.items. Add ("SMS center number:" + GSM. getmsgcenterno ());
Get unread SMS:
String [] Ss = GSM. getunreadmsg ();
Foreach (string s in SS)
{
If (s! = String. Empty & S. length! = 0)
{
Listbox1.items. Add (s );
}
}
Get all text messages: Try
{
String [] Ss = GSM. getallmsg ();
Foreach (string s in SS)
{
If (s! = String. Empty & S. length! = 0)
{
Listbox1.items. Add (s );
}
}
}
Catch {}
Read the text message with the specified serial number: textbox1.text = GSM. readmsgbyindex (3 );
Open the device:
Try
{
GSM. opencomm ();
This. CS (true );
Button8.enabled = false;
}
Catch {MessageBox. Show ("An error occurred while opening the device! "," Error ", messageboxbuttons. OK, messageboxicon. Error );}
Disable the device: Try
{
GSM. closecomm ();
This. CS (false );
Button8.enabled = true;
}
Catch {MessageBox. Show ("An error occurred while disabling the device! "," Error ", messageboxbuttons. OK, messageboxicon. Error );}
The following lists all Code on the test interface: View Code using system;
using system. collections. generic;
using system. componentmodel;
using system. data;
using system. drawing;
using system. text;
using system. windows. forms;
using myclasslibrary;
Namespace Myclassslibrarytest
{
Public Partial Class Frmgsm: Form
{
Public Frmgsm ()
{
Initializecomponent ();
}
Mygsm GSM = New Mygsm ( " Com3 " , 9600 );
Delegate Void Updatadelegate ();
Updatadelegate updatehandle = Null ;
Private Void Frmgsm_load ( Object Sender, eventargs E)
{
GSM. getnewmsg + = New Mygsm. onrecievedhandler (my_onrecieved );
Updatehandle = New Updatadelegate (updata1 );
This . CS ( False );
Button8.enabled = True ;
}
void my_onrecieved ( Object sender, eventargs e)
{< br> invoke (updatehandle, null );
}
void updata1 ()
{< br> textbox1.text = " receive new message " ;
listbox1.items. add (GSM. readnewmsg ();
}
private void button#click ( Object sender, eventargs e)
{< br> GSM. call ( " 15000450819 " );
}
private void button2_click ( Object sender, eventargs e)
{< br> listbox1.items. add (GSM. sendmsg ( " 15000450819 " , " I will send a text message csabcd !, Haha! " ). tostring ();
}
private void button3_click ( Object sender, eventargs e)
{< br> listbox1.items. add ( " machine code: " + GSM. getmachineno ();
}
Private VoidButton4_click (ObjectSender, eventargs E)
{
Listbox1.items. Add ("Short Message Center Number:" +GSM. getmsgcenterno ());
}
Private Void Button5_click ( Object Sender, eventargs E)
{
String [] SS = GSM. getunreadmsg ();
Foreach ( String S In SS)
{
If (S ! = String . Empty && S. Length ! = 0 )
{
Listbox1.items. Add (s );
}
}
}
Private Void Button6_click ( Object Sender, eventargs E)
{
Try
{
String [] SS = GSM. getallmsg ();
Foreach ( String S In SS)
{
If (S ! = String . Empty && S. Length ! = 0 )
{
Listbox1.items. Add (s );
}
}
}
Catch {}
}
Private VoidButton7_click (ObjectSender, eventargs E)
{
Textbox1.text=GSM. readmsgbyindex (3);
}
Private Void Button8_click ( Object Sender, eventargs E)
{
Try
{
GSM. opencomm ();
This . CS ( True );
Button8.enabled = False ;
}
Catch {MessageBox. Show ( " An error occurred while opening the device! " , " Error " , Messageboxbuttons. OK, messageboxicon. Error );}
}
Private Void Button9_click ( Object Sender, eventargs E)
{
Try
{
GSM. closecomm ();
This . CS ( False );
Button8.enabled = True ;
}
Catch {MessageBox. Show ( " An error occurred while disabling the device! " , " Error " , Messageboxbuttons. OK, messageboxicon. Error );}
}
Private Void CS ( Bool B)
{
Button1.enabled = B;
Button2.enabled = B;
Button3.enabled = B;
Button4.enabled = B;
Button5.enabled = B;
Button6.enabled = B;
Button7.enabled = B;
Button8.enabled = B;
Button9.enabled = B;
}
}
}
A c # Resource Sharing Platform, professional sharing and learning of high-quality code, assignment of learning tasks per cycle, stimulate learning C # interest! (Qq group: 128874886)
If you have any shortcomings, please correct them! You are welcome to give more comments! Thank you!