zoukankan      html  css  js  c++  java
  • 短信猫软件的实现(C#)<二> AT指令调试器的简单实现

    软件发送短信部分打算用C#类库实现 首先实现了一个简单的发送AT指令的程序 简单的把类库部分代码贴出来
    Bug太多,贴出来仅供参考。

    运行界面:

    image

    GSMMODEM.cs源代码:

      1:  using System;
      2:  using System.IO.Ports;
      3:  using System.Threading;
      4:   
      5:  namespace 时讯网
      6:  {
      7:      class GSMMODEM
      8:      {
      9:          //构造函数
     10:          public GSMMODEM()
     11:          {
     12:              //串口初始化
     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:          public GSMMODEM(string ComPort, int BaudRate)
     22:          {
     23:              //串口初始化
     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:          //属性
     34:          private SerialPort _sp = new SerialPort();
     35:   
     36:          //public bool AutoDelMsg = false;             //设置是否在阅读短信后自动删除SIM卡内短信存档(建议在经常接收短信时设置为 true)
     37:          //设计和运行时都可以读写,true 自动删除   false 不自动删除
     38:          //默认为 true
     39:  
     40:          //端口号
     41:          public string ComPort
     42:          {
     43:              get
     44:              {
     45:                  return _sp.PortName;
     46:              }
     47:              set
     48:              {
     49:                  _sp.PortName = value;
     50:              }
     51:          }
     52:   
     53:          //波特率
     54:          public int BaudRate
     55:          {
     56:              get
     57:              {
     58:                  return _sp.BaudRate;
     59:              }
     60:              set
     61:              {
     62:                  _sp.BaudRate = value;
     63:              }
     64:          }
     65:   
     66:          //是否开启
     67:          public bool IsOpen
     68:          {
     69:              get
     70:              {
     71:                  return _sp.IsOpen;
     72:              }
     73:          }
     74:   
     75:          //打开设备
     76:          public void OpenComm()
     77:          {
     78:              try
     79:              {
     80:                  _sp.Open();
     81:              }
     82:              catch (Exception ex)
     83:              {
     84:                  throw (ex);
     85:              }
     86:          }
     87:   
     88:          //关闭设备
     89:          public void CloseComm()
     90:          {
     91:              try
     92:              {
     93:                  _sp.Close();
     94:              }
     95:              catch (Exception ex)
     96:              {
     97:                  throw (ex);
     98:              }
     99:          }
    100:   
    101:          //发送AT指令,返回由设备返回的数据
    102:          public string SendATCommand(string ATCmd)
    103:          {
    104:              _sp.DiscardInBuffer();
    105:              try
    106:              {
    107:                  _sp.WriteLine(ATCmd);
    108:              }
    109:              catch (Exception ex)
    110:              {
    111:                  throw (ex);
    112:              }
    113:   
    114:              try
    115:              {
    116:                  Thread.Sleep(100);
    117:                  return _sp.ReadExisting();
    118:              }
    119:              catch (Exception ex)
    120:              {
    121:                  throw (ex);
    122:              }
    123:          }
    124:   
    125:          public string Write(byte[] byte1, int a, int b)
    126:          {
    127:              try
    128:              {
    129:                  _sp.Write(byte1, a, b);
    130:              }
    131:              catch (Exception ex)
    132:              {
    133:                  throw (ex);
    134:              }
    135:   
    136:              try
    137:              {
    138:                  Thread.Sleep(100);
    139:                  return _sp.ReadExisting();
    140:              }
    141:              catch (Exception ex)
    142:              {
    143:                  throw (ex);
    144:              }
    145:          }
    146:      }
    147:   
    148:  }
    149:   

    欢迎拍砖!

    附件:

    工程项目文件

  • 相关阅读:
    Codeforces Round #526 (Div. 2) E. The Fair Nut and Strings
    Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path
    S2SH项目实现分页功能
    S2SH项目实现分页功能
    HibernateDaoSupport类的使用
    object references an unsaved transient instance
    object references an unsaved transient instance
    启动Tomcat报WEB-INFlibj2ee.jar jar not loaded异常的解决办法
    启动Tomcat报WEB-INFlibj2ee.jar jar not loaded异常的解决办法
    解决eclipse中出现Resource is out of sync with the file system问题
  • 原文地址:https://www.cnblogs.com/Engin/p/1868368.html
Copyright © 2011-2022 走看看