Implementation of sms cat Software (C #) Simple implementation of AT command Debugger

Source: Internet
Author: User

The software sends text messages using the C # class library to implement a simple at commandProgramSimply put the class library partCodePost it
There are too many bugs and they are posted for reference only.

Running interface:

Gsmmodem. CSSource code:

 
1:UsingSystem;
 
2:UsingSystem. Io. ports;
 
3:UsingSystem. Threading;
 
4: 
 
5:NamespaceShixun Network
 
6:{
7:ClassGsmmodem
 
8:{
 
9:// Constructor
 
10:PublicGsmmodem ()
 
11:{
 
12:// Serial port Initialization
 
13:_ Sp. newline ="\ R \ n";
 
14:_ Sp. readtimeout = 2500;
15:_ Sp. rtsenable =True;
 
16:// _ Sp. dtrenable = true;
 
17: 
 
18:// _ Sp. Handshake = handshake. requesttosendxonxoff;
 
19:}
 
20: 
 
21:PublicGsmmodem (StringComport,IntBaudrate)
 
22:{
23:// Serial port Initialization
 
24:_ Sp. portname = comport;
 
25:_ Sp. baudrate = baudrate;
 
26:_ Sp. newline ="\ R \ n";
 
27:_ Sp. readtimeout = 2500;
 
28:_ Sp. rtsenable =True;
 
29:// _ Sp. dtrenable = true;
 
30:
31:// _ Sp. Handshake = handshake. requesttosendxonxoff;
 
32:}
 
33:// Attributes
 
34:PrivateSerialPort_ Sp =NewSerialPort();
 
35: 
 
36:// Public bool autodelmsg = false; // set whether to automatically delete the text message archive in the SIM card after reading the text message (it is recommended to set it to true when receiving text messages frequently)
37:// Read and write can be performed during design and runtime. True: automatic deletion; false: automatic deletion.
 
38:// The default value is true.
 
39:
 
40:// Port number
 
41:Public StringComport
 
42:{
 
43:Get
 
44:{
 
45:Return_ Sp. portname;
46:}
 
47:Set
 
48:{
 
49:_ Sp. portname =Value;
 
50:}
 
51:}
 
52: 
 
53:// Baud rate
 
54:Public intBaudrate
 
55:{
56:Get
 
57:{
 
58:Return_ Sp. baudrate;
 
59:}
 
60:Set
 
61:{
 
62:_ Sp. baudrate =Value;
 
63:}
 
64:}
 
65: 
66:// Whether to enable
 
67:Public boolIsopen
 
68:{
 
69:Get
 
70:{
 
71:Return_ Sp. isopen;
 
72:}
 
73:}
 
74: 
 
75:// Open the device
76:Public voidOpencomm ()
 
77:{
 
78:Try
 
79:{
 
80:_ Sp. open ();
 
81:}
 
82:Catch(ExceptionEx)
 
83:{
 
84:Throw(Ex );
 
85:}
86:}
 
87: 
 
88:// Close the device
 
89:Public voidClosecomm ()
 
90:{
 
91:Try
 
92:{
 
93:_ Sp. Close ();
 
94:}
 
95:Catch(ExceptionEx)
96:{
 
97:Throw(Ex );
 
98:}
 
99:}
 
100: 
 
101:// Send the AT command to return the data returned by the device
 
102:Public StringSendatcommand (StringAtcmd)
 
103:{
 
104:_ Sp. discardinbuffer ();
 
105:Try
106:{
 
107:_ Sp. writeline (atcmd );
 
108:}
 
109:Catch(ExceptionEx)
 
110:{
 
111:Throw(Ex );
 
112:}
 
113: 
 
114:Try
 
115:{
116:Thread. Sleep (100 );
 
117:Return_ Sp. readexisting ();
 
118:}
 
119:Catch(ExceptionEx)
 
120:{
 
121:Throw(Ex );
 
122:}
 
123:}
 
124: 
125:Public StringWrite (Byte[] Byte1,IntA,IntB)
 
126:{
 
127:Try
 
128:{
 
129:_ Sp. Write (byte1, A, B );
 
130:}
 
131:Catch(ExceptionEx)
 
132:{
133:Throw(Ex );
 
134:}
 
135: 
 
136:Try
 
137:{
 
138:Thread. Sleep (100 );
 
139:Return_ Sp. readexisting ();
 
140:}
 
141:Catch(ExceptionEx)
142:{
 
143:Throw(Ex );
 
144:}
 
145:}
 
146:}
 
147: 
 
148:}
 
149: 

Welcome!

Attachment:

Project files

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.