C#通用类库--短信猫操作类2使用方法(原始AT命令)

使用方法很简单,只要实例化类调用其中对应的方法就行,根据返回值再处理!

 myGSM gsm = new myGSM("COM3", 9600);

 打电话:gsm.Call("15000450819");

 发短信:listBox1.Items.Add(gsm.SendMsg("15000450819", "我就再发一条短信CSabcd!,呵呵!").ToString());

 获取手机机器码:listBox1.Items.Add("机器码:" + gsm.GetMachineNo()); 

 获取短消息中心号码:listBox1.Items.Add("短消息中心号码:" + gsm.GetMsgCenterNo());

 获取未读短信:

string[] ss = gsm.GetUnReadMsg();
            foreach (string s in ss)
            {
                if (s != string.Empty && s.Length != 0)
                {
                    listBox1.Items.Add(s);
                }
            }    
获取所有短信:
try
            {
                string[] ss = gsm.GetAllMsg();
                foreach (string s in ss)
                {
                    if (s != string.Empty && s.Length != 0)
                    {
                        listBox1.Items.Add(s);
                    }
                }
            }
            catch { }

 读取指定序号短信:textBox1.Text = gsm.ReadMsgByIndex(3);

 打开设备:

try
            {
                gsm.OpenComm();
                this.cs(true);
                button8.Enabled = false;
            }
            catch { MessageBox.Show("打开设备出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); }
关闭设备:
try
            {
                gsm.CloseComm();
                this.cs(false);
                button8.Enabled = true;
            }
            catch { MessageBox.Show("关闭设备出错!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); }
下面列出该测试界面所有代码:
ExpandedBlockStart.gif 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)
        {
            Invoke(UpdateHandle, 
null );
        }

        
void  Updata1()
        {
            textBox1.Text 
=   " 收到新消息 " ;
            listBox1.Items.Add(gsm.ReadNewMsg());
        }

        
private   void  button1_Click( object  sender, EventArgs e)
        {
            gsm.Call(
" 15000450819 " ); 
        }

        
private   void  button2_Click( object  sender, EventArgs e)
        {
            listBox1.Items.Add(gsm.SendMsg(
" 15000450819 " " 我就再发一条短信CSabcd!,呵呵! " ).ToString());
        }

        
private   void  button3_Click( object  sender, EventArgs e)
        {
            listBox1.Items.Add(
" 机器码: "   +  gsm.GetMachineNo());  
        }

        
private   void  button4_Click( object  sender, EventArgs e)
        {
            listBox1.Items.Add(
" 短消息中心号码: "   +  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   void  button7_Click( object  sender, 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( " 打开设备出错! " " 错误 " , MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }

        
private   void  button9_Click( object  sender, EventArgs e)
        {
            
try
            {
                gsm.CloseComm();
                
this .cs( false );
                button8.Enabled 
=   true ;
            }
            
catch  { MessageBox.Show( " 关闭设备出错! " " 错误 " , 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;
        }
    }
}

 一个C#资源分享平台,专业分享学习高质量代码,每周期布置学习任务,激发学习C#兴趣!(QQ群:128874886)

如有不足之处请指正!欢迎大家多提意见!谢谢!

----------Database-------------- 1.DataTable帮助(DataTableHelper.cs) 2.Access数据库文件操作辅助(JetAccessUtil.cs) 5.查询条件组合辅助(SearchCondition.cs) 6.查询信息实体(SearchInfo.cs) 8.Sql命令操作函数(可用于安装程序的时候数据库脚本执行)(SqlScriptHelper.cs) ----------Device-------------- 声音播放辅助(AudioHelper.cs) 摄像头操作辅助,包括开启、关闭、抓图、设置等功能(Camera.cs) 提供用于操作【剪切板】的方法(ClipboardHelper.cs) 获取电脑信息(Computer.cs) 提供用户硬件唯一信息的辅助(FingerprintHelper.cs) 读取指定盘符的硬盘序列号(HardwareInfoHelper.cs) 提供访问键盘当前状态的属性(KeyboardHelper.cs) 全局键盘钩子。这可以用来在全球范围内捕捉键盘输入。(KeyboardHook.cs) 模拟鼠标点击(MouseHelper.cs) 全局鼠标钩子。这可以用来在全球范围内捕获鼠标输入。(MouseHook.cs) MP3文件播放操作辅助(MP3Helper.cs) 关联文件(ExtensionAttachUtil.cs) 注册文件关联的辅助(FileAssociationsHelper.cs) 打开、保存文件对话框操作辅助(FileDialogHelper.cs) 常用的文件操作辅助FileUtil(FileUtil.cs) INI文件操作辅助(INIFileUtil.cs) 独立存储操作辅助(IsolatedStorageHelper.cs) 序列号操作辅助(Serializer.cs) 获取一个对象,它提供用于访问经常引用的目录的属性。(SpecialDirectories.cs) 简单的Word操作对象(WordCombineUtil.cs) 这个提供了一些实用的方法来转换XML和对象。(XmlConvertor.cs) XML操作(XmlHelper.cs) ----------Format-------------- 参数验证的通用验证程序。(ArgumentValidation.cs) 这个提供了实用方法的字节数组和图像之间的转换。(ByteImageConvertor.cs) byte字节数组操作辅助(BytesTools.cs) 处理数据型转换,数制转换、编码转换相关的(ConvertHelper.cs) CRC校验辅助(CRCUtils.cs) 枚举操作公共(EnumHelper.cs) 身份证操作辅助(IDCardHelper.cs) 检测字符编码的(IdentifyEncoding.cs) RGB颜色操作辅助(MyColors.cs) 日期操作(MyDateTime.cs) 转换人民币大小金额辅助(RMBUtil.cs) 常用的字符串常量(StringConstants.cs) 简要说明TextHelper。(StringUtil.cs) 获取中文字首字拼写,随机发生器,按指定概率随机执行操作(Util.cs) 各种输入格式验证辅助(ValidateUtil.cs) ----------Network-------------- Cookie操作辅助(CookieManger.cs) FTP操作辅助(FTPHelper.cs) HTML操作(HttpHelper.cs) 网页抓取帮助(HttpWebRequestHelper.cs) Net(NetworkUtil.cs) IE代理设置辅助(ProxyHelper.cs) ----------Winform-------------- 跨线程的控件安全访问方式(CallCtrlWithThreadSafety.cs) CheckBoxList(CheckBoxListUtil.cs) 窗口管理(ChildWinManagement.cs) 由马丁·米勒http://msdn.microsoft.com/en-us/library/ms996492.aspx提供一个简单的方法打印工作的一个RichTextBox一个帮手(ExRichTextBoxPrintHelper.cs) 显示,隐藏或关闭动画形式。(FormAnimator.cs) 对窗体进行冻结、解冻操作辅助(FreezeWindowUtil.cs) 窗体全屏操作辅助(FullScreenHelper.cs) GDI操作辅助(GDI.cs) 提供静态方法来读取这两个文件夹和文件的系统图标。(IconReaderHelper.cs) 图片对象比较、缩放、缩略图、水印、压缩、转换、编码等操作辅助(ImageHelper.cs) 输入法帮助,全角 转换为半角(ImeHelper.cs) Winform提示框 的摘要说明。(MessageUtil.cs) 包含互操作方法调用的应用程序中使用。(NativeMethods.cs) 托盘图标辅助(NotifyIconHelper.cs) 打印机(POSPrinter.cs) 图片、光标、图标、位图等资源操作辅助(ResourceHelper.cs) RTF字符格式辅助(RTFUtility.cs) 串口开发辅助(SerialPortUtil.cs) 设置文本属性提供一个ToolStripStatusLabel(SafeToolStripLabel.cs) 只运行一个实例及系统自动启动辅助(StartupHelper.cs) Web页面预览效果图片抓取辅助(WebPageCapture.cs) 供Asp.Net直接调用的包装(WebPreview.cs) 计算机重启、关电源、注销、关闭显示器辅助(WindowsExitHelper.cs)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值