⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mg801a.ctl

📁 短信收发控制(AT命令)
💻 CTL
📖 第 1 页 / 共 2 页
字号:
VERSION 5.00
Object = "{37310E40-8B75-41D8-B6F5-B2BBB6549E4D}#4.0#0"; "scoComm.ocx"
Begin VB.UserControl MG801A 
   ClientHeight    =   3165
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   3855
   InvisibleAtRuntime=   -1  'True
   Picture         =   "MG801A.ctx":0000
   PropertyPages   =   "MG801A.ctx":0442
   ScaleHeight     =   3165
   ScaleWidth      =   3855
   ToolboxBitmap   =   "MG801A.ctx":044D
   Begin scoComm.scCOMM scCOMM1 
      Left            =   420
      Top             =   1020
      _ExtentX        =   847
      _ExtentY        =   847
      Port            =   3
      BaudRate        =   17
   End
   Begin VB.Timer Timer_gsm 
      Enabled         =   0   'False
      Interval        =   100
      Left            =   1140
      Top             =   600
   End
End
Attribute VB_Name = "MG801A"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Attribute VB_Ext_KEY = "PropPageWizardRun" ,"Yes"
Option Explicit
'缺省属性值:
Const m_def_Mode = 0
Const m_def_Sq = 0
Const m_def_Ops = 0
Const m_def_Pnum = ""
Const m_def_Sca = ""

'===============================================
Const Con_str_ok         As String = "OK" & vbCrLf
Const Con_str_error      As String = "ERROR" & vbCrLf
Const Con_int_rt         As Integer = 100
Const Con_int_wt         As Integer = 20
Const Con_int_snum       As Integer = 3
'短消息索引上限
Const Con_int_scope      As Integer = 100

'Const Con_str_send_rev   As String = "> "
'Const Con_str_nmi_rev    As String = "+CMTI:"
Const Con_str_read_rev   As String = "+CMGR:"
Const Con_str_ring       As String = "RING"

'Const Con_str_MR        As String = "00"    'message reference

Const Con_str_at        As String = "AT"
Const Con_str_echo      As String = "E1"
Const Con_str_replong   As String = "V1"
Const Con_str_read      As String = "+CMGR="
Const Con_str_send      As String = "+CMGS="
Const Con_str_del       As String = "+CMGD="
Const Con_str_list      As String = "+CMGL=""ALL"""
Const Con_str_sq        As String = "+CSQ"
Const Con_str_pas       As String = "+CPAS"
Const Con_str_sms       As String = "+CSMS=0"
Const Con_str_pms       As String = "+CPMS=""MT"""
'Const Con_str_nmi       As String = "+CNMI=2,1"
Const Con_str_num       As String = "+CNUM"
Const Con_str_pin       As String = "+CPIN?"
Const Con_str_sca       As String = "+CSCA?"
Const Con_str_lip       As String = "+CLIP=1"
Const Con_str_ops       As String = "+COPS?"
'Const Con_str_off       As String = "*P0"
'Const Con_str_on        As String = "*P1"
Const Con_str_hungup    As String = "H"
Const Con_str_hung      As String = "A"

Const Con_str_num_rev   As String = "+CNUM:"
Const Con_str_sca_rev   As String = "+CSCA:"
Const Con_str_sq_rev    As String = "+CSQ:"
Const Con_str_pms_rev   As String = "+CPMS:"
Const Con_str_pin_rev   As String = "+CPIN:"
Const Con_str_ops_rev   As String = "+COPS:"
Const Con_str_pas_rev   As String = "+CPAS:"
Const Con_str_lis_rev   As String = "+CMGL:"

Private Int_lastorder    As ATorder
Private Int_order        As ATorder
'接收定时器
Private Trece As User_timer
'等待定时器
Private Twait As User_timer
'发送次数
Private Int_snum As Integer
'SIM卡容量
Private Int_sim As Integer
'短消息索引
Private Int_smindex As Integer
'网络商代码
Private Lng_ops As Long
'读短消息使能
Private Bool_readen As Boolean
Private GSM    As User_gsm
Private U_sm As User_sm
'串口接收内容
Private Str_rece As String
'手机号
Private Str_pnum         As String
'短信中心号
Private Str_sca          As String
'网络商
Private Str_ops          As String
'手机信号
Private Int_sq As Integer
'设备逻辑状态
Private Int_state As Integer
'设备物理状态
Private Int_pas As Integer

Public Enum ATorder
    Init_me
    Read_sim
    Init_sm
    Read_sca_num
    Read_sm
    List_sm
    Del_sm
    Send_sm
    Send_pdu
    hungup
    hand
    Nmi
    Send_ctrlz
End Enum

Public Enum Gsm_indicate
    Gsm_init
    Gsm_getpin
    Gsm_insert
    Gsm_ukpin
    Gsm_getnum
    Gsm_uknum
    Gsm_comm
    Gsm_commerr
    Gsm_conerr
    Gsm_conok
    Gsm_rinit
    Gsm_sending
    Gsm_sendfail
    Gsm_sendover
    Gsm_delok
    Gsm_delerr
    Gsm_getsm
    Gsm_writeok
    Gsm_callok
    Gsm_hungup
    Pas_change
    Port_invalid
    Port_used
End Enum

Public Enum Gsm_comm
    Send
    Rece
End Enum

Public Enum Gsm_state
    Lookfor
    Connect
    Setinit
    Normal
End Enum
'===============================================
'属性变量:
Dim m_Mode As Integer
Dim m_Sq As Integer
Dim m_Ops As Long
Dim m_Pnum As String
Dim m_Sca As String
'事件声明:
Event OnComm(ByVal indi As Gsm_comm)
Event OnResult(ByVal indi As Gsm_indicate)

'注意!不要删除或修改下列被注释的行!
'MappingInfo=scCOMM1,scCOMM1,-1,port
Public Property Get Port() As Integer
Attribute Port.VB_Description = "端口号"
Attribute Port.VB_ProcData.VB_Invoke_Property = "通用"
    Port = scCOMM1.Port
End Property

Public Property Let Port(ByVal New_port As Integer)
    scCOMM1.Port() = New_port
    PropertyChanged "port"
End Property

'注意!不要删除或修改下列被注释的行!
'MappingInfo=scCOMM1,scCOMM1,-1,BaudRate
Public Property Get BaudRate() As Integer
Attribute BaudRate.VB_Description = "波特率"
Attribute BaudRate.VB_ProcData.VB_Invoke_Property = "通用"
    BaudRate = scCOMM1.BaudRate
End Property

Public Property Let BaudRate(ByVal New_BaudRate As Integer)
    scCOMM1.BaudRate() = New_BaudRate
    PropertyChanged "BaudRate"
End Property

'注意!不要删除或修改下列被注释的行!
'MappingInfo=scCOMM1,scCOMM1,-1,Parity
Public Property Get Parity() As Integer
Attribute Parity.VB_Description = "校验位"
Attribute Parity.VB_ProcData.VB_Invoke_Property = "通用"
    Parity = scCOMM1.Parity
End Property

Public Property Let Parity(ByVal New_Parity As Integer)
    scCOMM1.Parity() = New_Parity
    PropertyChanged "Parity"
End Property

'注意!不要删除或修改下列被注释的行!
'MappingInfo=scCOMM1,scCOMM1,-1,StopBits
Public Property Get StopBits() As Integer
Attribute StopBits.VB_Description = "停止位"
Attribute StopBits.VB_ProcData.VB_Invoke_Property = "通用"
    StopBits = scCOMM1.StopBits
End Property

Public Property Let StopBits(ByVal New_StopBits As Integer)
    scCOMM1.StopBits() = New_StopBits
    PropertyChanged "StopBits"
End Property

'注意!不要删除或修改下列被注释的行!
'MappingInfo=scCOMM1,scCOMM1,-1,DataBits
Public Property Get DataBits() As Integer
Attribute DataBits.VB_Description = "数据位"
Attribute DataBits.VB_ProcData.VB_Invoke_Property = "通用"
    DataBits = scCOMM1.DataBits
End Property

Public Property Let DataBits(ByVal New_DataBits As Integer)
    scCOMM1.DataBits() = New_DataBits
    PropertyChanged "DataBits"
End Property

'注意!不要删除或修改下列被注释的行!
'MappingInfo=scCOMM1,scCOMM1,-1,Dtr
Public Property Get Dtr() As Integer
Attribute Dtr.VB_Description = "DTR有效"
Attribute Dtr.VB_ProcData.VB_Invoke_Property = "通用"
    Dtr = scCOMM1.Dtr
End Property

Public Property Let Dtr(ByVal New_Dtr As Integer)
    scCOMM1.Dtr() = New_Dtr
    PropertyChanged "Dtr"
End Property

'注意!不要删除或修改下列被注释的行!
'MappingInfo=scCOMM1,scCOMM1,-1,FlowControl
Public Property Get FlowControl() As Integer
Attribute FlowControl.VB_Description = "流控制"
Attribute FlowControl.VB_ProcData.VB_Invoke_Property = "通用"
    FlowControl = scCOMM1.FlowControl
End Property

Public Property Let FlowControl(ByVal New_FlowControl As Integer)
    scCOMM1.FlowControl() = New_FlowControl
    PropertyChanged "FlowControl"
End Property

'注意!不要删除或修改下列被注释的行!
'MappingInfo=scCOMM1,scCOMM1,-1,Rts
Public Property Get Rts() As Integer
Attribute Rts.VB_Description = "RTS有效"
Attribute Rts.VB_ProcData.VB_Invoke_Property = "通用"
    Rts = scCOMM1.Rts
End Property

Public Property Let Rts(ByVal New_Rts As Integer)
    scCOMM1.Rts() = New_Rts
    PropertyChanged "Rts"
End Property

'注意!不要删除或修改下列被注释的行!
'MemberInfo=13,0,0,
Public Property Get Sca() As String
    m_Sca = Str_sca
    Sca = m_Sca
End Property

Public Property Let Sca(ByVal New_Sca As String)
    m_Sca = New_Sca
    Str_sca = m_Sca
    PropertyChanged "Sca"
End Property
'

Private Sub scCOMM1_OnComm()
    '截取ME变换,接收ME数据流
    Dim int_pos As Integer
    Dim int_len As Integer
    Dim int_i As Gsm_indicate
    Dim str_echo As String
    Dim bool_result As Boolean
    Dim u_gsmrece As User_gsmrece
    If scCOMM1.CommEvent = 2 Then
        RaiseEvent OnComm(Rece)
        Str_rece = Str_rece & scCOMM1.ReadData
        u_gsmrece = Fun_gsm_rece(Str_rece)
        Str_rece = u_gsmrece.Rece
        str_echo = u_gsmrece.echo
        bool_result = u_gsmrece.Result
        If u_gsmrece.Rflag = True Then
            u_gsmrece.Rflag = False
            'int_i = Fun_gsm_receproc(str_echo, bool_result)    task
            RaiseEvent OnResult(int_i)
        End If
    End If
End Sub

Private Sub Timer_gsm_Timer()
    If Trece.enabel = True Then
        With Trece
        .value = .value - 1
        If .value <= 0 Then
            .enabel = False
            .timeup = True
            .value = Con_int_rt
        End If
        End With
    End If
    
    If Twait.enabel = True Then
        With Twait
        .value = .value - 1
        If .value <= 0 Then
            .enabel = False
            .timeup = True
            .value = Con_int_wt
        End If
        End With
    End If
    Call Fun_gsm
End Sub

Private Sub UserControl_Initialize()
    Int_state = Lookfor
End Sub

'为用户控件初始化属性
Private Sub UserControl_InitProperties()
    m_Sca = m_def_Sca
    m_Sq = m_def_Sq
    m_Ops = m_def_Ops
    m_Pnum = m_def_Pnum
    m_Mode = m_def_Mode
End Sub

'从存贮器中加载属性值
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)

    scCOMM1.Port = PropBag.ReadProperty("port", 0)
    scCOMM1.BaudRate = PropBag.ReadProperty("BaudRate", 12)
    scCOMM1.Parity = PropBag.ReadProperty("Parity", 0)
    scCOMM1.StopBits = PropBag.ReadProperty("StopBits", 1)
    scCOMM1.DataBits = PropBag.ReadProperty("DataBits", 3)
    scCOMM1.Dtr = PropBag.ReadProperty("Dtr", 0)
    scCOMM1.FlowControl = PropBag.ReadProperty("FlowControl", 0)
    scCOMM1.Rts = PropBag.ReadProperty("Rts", 0)
    m_Sca = PropBag.ReadProperty("Sca", m_def_Sca)
    m_Sq = PropBag.ReadProperty("Sq", m_def_Sq)
    m_Ops = PropBag.ReadProperty("Ops", m_def_Ops)
    m_Pnum = PropBag.ReadProperty("Pnum", m_def_Pnum)
    m_Mode = PropBag.ReadProperty("Mode", m_def_Mode)
End Sub

Private Sub UserControl_Resize()
    Width = 540
    Height = 540
End Sub

Private Sub UserControl_Terminate()
    Call PortClose
End Sub

'将属性值写到存储器
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

    Call PropBag.WriteProperty("port", scCOMM1.Port, 0)
    Call PropBag.WriteProperty("BaudRate", scCOMM1.BaudRate, 12)
    Call PropBag.WriteProperty("Parity", scCOMM1.Parity, 0)
    Call PropBag.WriteProperty("StopBits", scCOMM1.StopBits, 1)
    Call PropBag.WriteProperty("DataBits", scCOMM1.DataBits, 3)
    Call PropBag.WriteProperty("Dtr", scCOMM1.Dtr, 0)
    Call PropBag.WriteProperty("FlowControl", scCOMM1.FlowControl, 0)
    Call PropBag.WriteProperty("Rts", scCOMM1.Rts, 0)
    Call PropBag.WriteProperty("Sca", m_Sca, m_def_Sca)
    Call PropBag.WriteProperty("Sq", m_Sq, m_def_Sq)
    Call PropBag.WriteProperty("Ops", m_Ops, m_def_Ops)
    Call PropBag.WriteProperty("Pnum", m_Pnum, m_def_Pnum)
    Call PropBag.WriteProperty("Mode", m_Mode, m_def_Mode)
End Sub
'
'
'注意!不要删除或修改下列被注释的行!
'MemberInfo=7,1,2,0
Public Property Get Sq() As Integer
Attribute Sq.VB_Description = "返回手机信号质量"
Attribute Sq.VB_MemberFlags = "400"
    m_Sq = Int_sq
    Sq = m_Sq
End Property

Public Property Let Sq(ByVal New_Sq As Integer)
    If Ambient.UserMode = False Then Err.Raise 387
    If Ambient.UserMode Then Err.Raise 382
    m_Sq = New_Sq
    Int_sq = m_Sq
    PropertyChanged "Sq"
End Property

'注意!不要删除或修改下列被注释的行!
'MemberInfo=8,1,2,0
Public Property Get Ops() As Long
Attribute Ops.VB_Description = "返回网络运营商"
Attribute Ops.VB_MemberFlags = "400"
    m_Ops = Lng_ops
    Ops = m_Ops
End Property

Public Property Let Ops(ByVal New_Ops As Long)
    If Ambient.UserMode = False Then Err.Raise 387
    If Ambient.UserMode Then Err.Raise 382
    m_Ops = New_Ops
    Lng_ops = m_Ops
    PropertyChanged "Ops"
End Property

'注意!不要删除或修改下列被注释的行!
'MemberInfo=13,0,2,
Public Property Get Pnum() As String
Attribute Pnum.VB_Description = "设置/返回手机号码"
Attribute Pnum.VB_MemberFlags = "400"
    m_Pnum = Str_pnum
    Pnum = m_Pnum
End Property

Public Property Let Pnum(ByVal New_Pnum As String)
    If Ambient.UserMode = False Then Err.Raise 387
    m_Pnum = New_Pnum
    Str_pnum = m_Pnum
    PropertyChanged "Pnum"
End Property

'==============================方法==========================
Public Function PortOpen() As Boolean
'打开端口
On Error GoTo doerrors
    Err.Clear
    PortOpen = False
    If scCOMM1.PortOpen Then
        Timer_gsm.Enabled = True
        Call Sub_gsminit
        Int_lastorder = -1
        PortOpen = True
    End If
    Exit Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -