来电显示.frm
资源名称:来电显示.rar [点击查看]
上传用户:chinaplant
上传日期:2010-01-23
资源大小:2k
文件大小:4k
源码类别:
Modem编程
开发平台:
Visual Basic
- VERSION 5.00
- Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
- Begin VB.Form Form1
- ClientHeight = 3105
- ClientLeft = 60
- ClientTop = 345
- ClientWidth = 2940
- LinkTopic = "Form1"
- ScaleHeight = 3105
- ScaleWidth = 2940
- StartUpPosition = 3 '窗口缺省
- Begin MSCommLib.MSComm MSComm1
- Left = 0
- Top = 0
- _ExtentX = 1005
- _ExtentY = 1005
- _Version = 393216
- DTREnable = -1 'True
- End
- Begin VB.TextBox Text2
- Height = 375
- Left = 120
- TabIndex = 1
- Top = 2520
- Width = 2655
- End
- Begin VB.Timer Timer1
- Interval = 60
- Left = 6960
- Top = 2400
- End
- Begin VB.TextBox Text1
- Height = 2295
- Left = 120
- MultiLine = -1 'True
- TabIndex = 0
- Top = 120
- Width = 2655
- End
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Public COMBUF, COMLIN As String
- Private Sub Form_Load()
- call Init_CallID()
- End Sub
- '****************************************************
- Private Function Init_CallID() As String
- '返回所有可用串行口
- Dim C As Integer,L As Integer
- Dim T As Single
- On Error GoTo NotCOM
- '检测可用串口
- For C = 1 To 6
- If MSComm1.PortOpen Then MSComm1.PortOpen = False
- MSComm1.CommPort = C
- If Not MSComm1.PortOpen Then MSComm1.PortOpen = True'没串口时出错并跳到NOTCOM标号
- MSComm1.Output = "AT#CID=1" + vbCr '打开MODEM的
- T = Timer
- Do
- COMBUF = COMBUF + MSComm1.Input
- L = InStr(1, COMBUF, "OK")
- if L<>0 them
- MSComm1.Output = "ATS0=0" + vbCr
- Exit Function 'GOTO NotCOM 用于初始化所有串口的MODEM,
- end if
- Loop Until Timer - T > 1
- NotCOM:
- Next C
- If C = 4 Then MsgBox "没有可用串口!"
- if L = 0 then msgbox "没有MODEM或MODEM不支持来电显示!"
- End Function
- Private Function INIT_MODEM(ByVal COMNUM As Long) As Long
- 'MODEM是否联接指定串口
- Dim T As Single
- Dim L As Integer
- INIT_MODEM = 0
- If MSComm1.PortOpen Then MSComm1.PortOpen = False
- MSComm1.CommPort = COMNUM
- If Not MSComm1.PortOpen Then MSComm1.PortOpen = True
- MSComm1.Output = "AT#CID=1" + vbCr
- T = Timer
- Do
- COMBUF = COMBUF + MSComm1.Input
- L = InStr(1, COMBUF, "OK")
- Loop Until L <> 0 Or Timer - T > 1
- If L <> 0 Then
- INIT_MODEM = 1
- Else
- Exit Function
- End If
- MSComm1.Output = "ATS0=0" + vbCr
- End Function
- Private Sub MSComm1_OnComm()
- '串行口接收事件处理
- Dim CH, ST As String
- Dim LC As Integer
- Select Case MSComm1.CommEvent
- '接收到Rthreshold个字符
- Case comEvReceive
- COMBUF = COMBUF + MSComm1.Input
- '读取串口数据
- Do
- LC = InStr(1, COMBUF, Chr(10))
- If LC = 0 Then Exit Do
- COMLIN = Left(COMBUF, LC)
- COMBUF = Mid(COMBUF, LC + 1)
- CH = Left(COMLIN, 1)
- If "" < CH And CH < Chr(127) And DEBFLG = 1 Then
- Text1.Text = Text1.Text + COMLIN
- Text1.SelStart = Len(Text1.Text)
- End If
- '截取来电号码,并显示
- If InStr(1, COMLIN, "NMBR = ") <> 0 Then
- ST = Mid(COMLIN, 8)
- Text2.Text = "" + Left$(ST, Len(ST) - 2) + " "
- End If
- Loop
- End Select
- End Sub