• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

用MSComm控件实现来电显示

发布: 2007-7-01 21:48 | 作者: admin | 来源: | 查看: 15次 | 进入软件测试论坛讨论

领测软件测试网

来电显示的实现
MODEM的AT命令CID和VCID是设置是不是来电显示的,如果电信开通了来电显示功能
就能通过MODEM来显示对方的电话号码。那么首先设置CID=1或是VCID=1

般来说来电显示的信息为:
DATE = MMDD "来电日期 MMDD
TIME = HHMM "来电时间 HHMM
NMBR = ######## "来电号码
程序实现如下,设置MSComm1的相关设置,并建两个Label为Label1和Label2
Function OpenCID(OpenCLose As Boolean) As Boolean
´打开或是关毕来电显示功能
    On Error Resume Next
    Dim ArrCID(1) As String
    ArrCID(0) = "at#cid=" & IIf(openclode, 1, 0)
    ArrCID(1) = "at#vcid=" & IIf(openclode, 1, 0)
    MSComm1.RThreshold = 0
    For i = 0 To 1
        MSComm1.Output = ArrCID(i) & vbCr
        EndTime = Timer + 0.5
        Do While bStop = False
            nTemp = nTemp + 1
            If MSComm1.InBufferCount >= 2 Then
                sTemp = MSComm1.Input
                If InStr(sTemp, "OK") = 0 Then
                    bStop = True
                    OpenCID = True
                    Exit Function
                End If
            End If
            If Timer >= EndTime Or ErrorCode Then Exit Do
        Loop
    Next i
    OpenCID = False
    MSComm1.RThreshold = 1
End Function
下面的函数显示来电号码并在窗体上的Label1的Label2上显示出来
Private Sub MSComm1_OnComm()
    On Error Resume Next
    Static Buffer As String
     ´ 收到多于 RThreshold 属性设置的字符数(RThreshold 属性必须大于 0)。
            ´label1 = "收到" + Str(MSComm1.InBufferCount) + "个字符"
            Buffer = Buffer + MSComm1.Input
            Buffer = UCase(Buffer)

         ´   Exit Sub
            If InStr(1, Buffer, "RING", vbTextCompare) Then
            ´收到震铃
                ´Comm1.Output = "ATA" + Chr(13) ´命令 Modem 摘机响应
                Buffer = "" ´清缓冲区字符
                ´mciExecute "sound " & SystemPath & "\ringin.wav"
                Label1 = "状态:收到震铃"
                Zhen = True
                frmCallID.Show
                frmCallID.ChangRing
             
               
            ElseIf InStr(1, Buffer, "CONNECT", vbTextCompare) Then
            ´对方应答呼叫
                Buffer = "" ´清缓冲区字符
                Label1 = "状态:已经建立连接"
            ElseIf InStr(1, Buffer, "BUSY", vbTextCompare) Then
            ´对方线路忙
                Buffer = "" ´清缓冲区字符
                Label1 = "状态:对方线路忙"
            ElseIf InStr(1, Buffer, "No DIA", vbTextCompare) Then
                Buffer = "" ´清缓冲区字符
                Label1 = "状态:拨出号码错,请检查电话线"
                Command1_Click
            ElseIf InStr(1, Buffer, "No CARRIER", vbTextCompare) Then
            ´对方未摘机或未响应
                Buffer = "" ´清缓冲区字符
                Label1 = "状态:对方未摘机"
          
            ElseIf InStr(1, Buffer, "NMBR =", vbTextCompare) Then
             tmpStr = InStr(1, Buffer, "NMBR", vbTextCompare)
             CallNum = Right(Buffer, Len(Buffer) - lll - 6)
             Label2.Caption = "对方电话:" + CallNum

                ´Buffer = "" ´清缓冲区字符
            ElseIf InStr(1, Buffer, "OK", vbTextCompare) And Asc(Right(Buffer, 1)) = 10 Then
              If Zhen = False Then Buffer = "" ´清缓冲区字符
             If Command1.Caption = "挂断" Then
              Label2.Caption = "状态:已经播通电话:" + txtCallNum
            End If
            End If
End Sub


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网