给你一段代码做个参考吧!
Dim jsxx As String
Dim jieshou As String
Private Sub Command1_Click()
Text1.Text = ""
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Command3_Click()
'设置缓冲区大小为1024,属性RThreshold=2
' OnComm 事件被用于捕获 communications 事件及错误。
Dim EVMsg$ '存放事件消息的字符串
Dim ERMsg$ '存放错误消息的字符串
'根据事件消息进行分支
Select Case
'以下为事件消息
Case comEvReceive
Dim N As Long
Dim Buffer As Variant
Dim Var As Variant
txtreceived.Text = Text1.Text
'txtReceived为接收信息的文本框,FILESTART为文件传送的开始标志,在文件内容传送开始前发送出,当文本框中出现FILESTART时,就打开接收文件接收
If InStr(1, txtreceived.Text, "FILESTART") <> 0 Then
N = MSComm1.InBufferCount
Buffer = MSComm1.Input
Dim hSend
Dim Temp As String
hSend = FreeFile
Temp = App.Path + "\" + txtreceived.Text
Open Temp For Binary Access Write As hSend
'Var = Space(N)
' Var = Buffer
'txtSend.SelStart = Len(txtSend.Text) ’用另一文本框接受文件,文本框显示出完整的文本文件
'txtSend.SelLength = 0
'txtSend.SelText = Buffer
Put hSend, , Buffer '写入文件后,打开文件不全
Close hSend
Else
'显示其他信息,如:Modom回应信息,通话聊天信息等
Buffer = MSComm1.Input
txtreceived.SelStart = Len(txtreceived.Text)
txtreceived.SelLength = 0
txtreceived.SelText = Buffer
jieshou = jieshou & txtreceived.SelText
Text5.Text = jieshou
End If
Case comEvSend
Case comEvCTS
EVMsg$ = "Change in CTS Detected"
Case comEvDSR
EVMsg$ = "Change in DSR Detected"
Case comEvCD
EVMsg$ = "Change in CD Detected"
Case comEvRing
EVMsg$ = "The Phone is Ringing"
Case comEvEOF
EVMsg$ = "End of File Detected"
' Error messages.
Case comBreak
ERMsg$ = "
信号中断!
"
Case comCDTO
ERMsg$ = "
Carrier Detect Timeout
"
Case comCTSTO
ERMsg$ = "
Clear-To-Send Timeout
"
Case comDCB
ERMsg$ = "
Error retrieving DCB
"
Case comDSRTO
ERMsg$ = "
Data-Set-Ready Timeout
"
Case comFrame
ERMsg$ = "
接收帧错误!请调整速率参数。
"
Case comOverrun
ERMsg$ = "
溢出错误!
"
Case comRxOver
'ERMsg$ = "Receive Buffer Overflow"
Case comRxParity
ERMsg$ = "
奇偶校验错误!请调整奇偶校验参数。
"
Case comTxFull
ERMsg$ = "
传输缓冲区已满!
"
Case Else
ERMsg$ = "
未知错误!
"
If Len(EVMsg$) Then
' Display event messages in the status bar.
StatusBar1.Panels("状态:").Text = "状态:" & EVMsg$
' Enable timer so that the message in the status bar
' is cleared after 2 seconds
Timer2.Enabled = True
ElseIf Len(ERMsg$) Then
' Display event messages in the status bar.
StatusBar1.Panels("状态:").Text = "状态:" & ERMsg$
' Display error messages in an alert message box.
Beep
'Ret = MsgBox(ERMsg$, vbOKOnly, "系统提示:")
End If
End Select
End Sub
Private Sub Command4_Click()
If Combo1.Text = "选择号码" Then
Combo1.Text = "1070"
End If
'Call Openport
'MSComm1.Output = "AT" + Chr(13)
'mywin = Waiting("OK", 3)
' If errorcode Then
' MsgBox "你的Modem未准备好,电话占线"
' End If
'MSComm1.Output = "AT%B" & Chr$(13)
'%B 查看黑名单中的数字。 如果黑名单生效,AT%B 显示在前两个小时内尝试呼叫失败的次数列表。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "ATDT" & Combo1.Text & vbCrLf
'拨电话号码
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
Timer3.Enabled = True
StatusBar1.Panels("状态:").Text = "状态:正在拨号......"
Wait = Waiting("CONNECT", 2)
If errorcode Then
StatusBar1.Panels("状态:").Text = "状态:对方占线,请稍候再拔......"
MSComm1.Output = "ATH0" & Chr$(13)
'调制解调器挂断
Else
'MSComm1.Output = "AT+FCLASS=?" & Chr$(13)
'+FCLASS=? 返回支持的调制解调器模式。AT+FCLASS=? 询问调制解调器支持的模式所在的范围。调制解调器返回:0, 1, 8, 80 (数据,传真,语音和 VoiceView)。
'Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
' If InStr(Buffer, "8") > 0 Then
' jieshou = jieshou + "
" + Buffer
' txtreceived.Text = jieshou
MSComm1.Output = "AT+FCLASS=8" & Chr$(13)
'+FCLASS=8 进入语音模式。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
'MSComm1.Output = "AT+VIP" & Chr$(13)
'AT+VIP 使调制解调器将所有的语音参数初始化为默认值。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
'MSComm1.Output = "AT+VIT=3" & Chr$(13)
'DTE/DCE (计算机/调制解调器) 未活动计时器
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VLS=?" & Chr$(13)
'+VLS=? 模拟源/目标选择和 DTMF/音频报告。使用 AT+VLS=? 命令要求调制解调器报告 DTMF/音频功能。对于语音模式(扩音电话和应答机)中的每一种系统配置,调制解调器报告用于配置启用的功能。对于每一种配置,调制解调器显示以下三种不同语音状态下的音调报告功能:语音传送数据、语音接收数据和语音命令状态。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VLS=7" & Chr$(13)
' +VLS=n 模拟源/目标选择。"
'一般用途的模拟来源/目标命令可在语音模式下向系统附加各种模拟设备。扩音电话开/关
'TAM 支持以下各种 IS-101 模拟源/目标配置:
'n = 0 调制解调器挂机,本地电话连接至电信公司.关闭扩音电话。断开模拟设备和挂断调制解调器。
'n = 1 调制解调器摘机,调制解调器连接至电信公司。
'n = 2 调制解调器摘机,本地电话连接至调制解调器。
'n = 3 调制解调器摘机,本地电话连接至电信公司,调制解调器连接至本地电话。
'n = 4 扬声器连接至调制解调器,调制解调器挂机 (播放留言)。
'n = 5 扬声器连接至调制解调器,调制解调器摘机 (屏蔽呼叫在扩音电话工作时 (电话静音功能) 禁用/断开麦克风模拟源 (仅留下扬声器)。)。
'n = 6 麦克风连接至调制解调器,调制解调器挂机 (录制问候语)。
'n = 7 连接内置扬声器和内置麦克风及调制解调器摘机。(打开扩音电话)。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VLS=6" & Chr$(13)
' +VLS=n 模拟源/目标选择。"
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VLS=5" & Chr$(13)
' +VLS=n 模拟源/目标选择。"
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VLS=4" & Chr$(13)
' +VLS=n 模拟源/目标选择。"
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VLS=3" & Chr$(13)
' +VLS=n 模拟源/目标选择。"
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VLS=2" & Chr$(13)
' +VLS=n 模拟源/目标选择。"
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VLS=1" & Chr$(13)
' +VLS=n 模拟源/目标选择。"
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VSM=?" & Chr$(13)
'+VSM=? 返回支持的压缩方式和取样规范。调制解调器报告支持的语音压缩方式和取样率:
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VSM=0,7200" & Chr$(13)
'+VSM=cml,vsr 压缩方式和取样规范。AT+VSM=cml,vsr 启用压缩方式和取样规范,在此 cml 表示压缩方式标记而 vsr 表示语音取样率。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VLS?" & Chr$(13)
'+VLS? 报告当前的模拟源/目标配置。AT+VLS? 报告当前模拟源/目标配置,及该配置下调制解调器向计算机报告的所有事件代码列表。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
'End If
End If
End Sub
Private Sub Command5_Click()
Dim waveOutOpen As Long
Dim tempopen As Long
Dim tempwrit As Long
Dim wavplay As Long
Dim waveOutWrite As Long
On Error GoTo errhandler
MSComm1.Output = "AT+fclass=8" & Chr$(13)
'+FCLASS=8 进入语音模式。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VLS=4" & Chr$(13)
'模拟源/目标配置。
'n = 0 调制解调器挂机,本地电话连接至电信公司
'n = 1 调制解调器摘机,调制解调器连接至电信公司。
'n = 2 调制解调器摘机,本地电话连接至调制解调器。
'n = 3 调制解调器摘机,本地电话连接至电信公司,调制解调器连接至本地电话。
'n = 4 扬声器连接至调制解调器,调制解调器挂机 (播放留言)。
'n = 5 扬声器连接至调制解调器,调制解调器摘机 (屏蔽呼叫)。
'n = 6 麦克风连接至调制解调器,调制解调器挂机 (录制问候语)。
'n = 7 连接麦克风和扬声器,调制解调器摘机 (扩音电话)。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VBT=1" & Chr$(13)
MSComm1.Output = "AT+VSR=7200" & Chr$(13)
MSComm1.Output = "AT+VBS=4" & Chr$(13)
MSComm1.Output = "ATS30=60" & Chr$(13)
MSComm1.Output = "ATA" & Chr$(13)
uDeviceID =
CommonDialog1.Filter = "*.wav"
CommonDialog1.Action = 1
'wavplay = mciExecute("play " + CommonDialog1.FileName)
'tempopen = waveOutOpen(uDeviceID, 0)
'tempwrit = waveOutWrite(com1, CommonDialog1.FileName, 10240)
errhandler:
Exit Sub
End Sub
Private Sub Command6_Click()
MSComm1.Output = "ATH0" & Chr$(13)
'调制解调器挂断
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
StatusBar1.Panels("状态:").Text = "状态:"
End Sub
Private Sub Form_Load()
Me.Show
'初始化,为各控件的相关属性赋值
dd = Date
Text5.Text = Mid("星期天星期一星期二星期三星期四星期五星期六", Weekday(dd, vbSunday) * 3 - 2, 3)
Label3.Caption = "串口设置'波特率,奇偶校验,数据位,停止位'"
Text3.Text = "9600,n,8,1"
Text1.Text = ""
Text2.Text = ""
Text2.SetFocus
Frame1.Caption = "串口选择"
Option1.Caption = "COM1"
Option1.Value = False
Option2.Caption = "COM2"
Frame2.Caption = "显示方式"
Option3.Caption = "文本"
Option3.Value = False
Option4.Caption = "ASCii"
Command1.Caption = "清除接收"
Command2.Caption = "退出"
oldset = Text3.Text
Timer1.Enabled = True
Timer2.Enabled = False
Timer3.Enabled = False
stoptiming.Enabled = False
starttiming.Enabled = True
Combo1.AddItem "1070"
Combo1.AddItem "1251"
Combo1.AddItem "1254"
Combo1.AddItem "013031570250"
Combo1.AddItem "06126797"
Combo1.AddItem "06580270"
For g = 1 To 4
On Error Resume Next
If g = 1 Then
= 1
If Not err Then Option1.Value = True: MsgBox "COM1口工作": Exit For
Else
If g = 2 Then
err = 0: = 2
If Not err Then Option1.Value = False: Option2.Value = True: MsgBox "COM2口工作": Exit For
Else
If g = 3 Then
= 3
If Not err Then Option1.Value = False: Option2.Value = False: Option3.Value = True: MsgBox "COM3口工作": Exit For
Else
If g = 4 Then
err = 0: = 4
If Not err Then Option1.Value = False: Option2.Value = False: Option3.Value = False: Option4.Value = True: MsgBox "COM4口工作": Exit For
Else
If err Then MsgBox "COM1、COM2、COM3、COM4都不能打开,程序终止": End
End If
End If
End If
End If
Next g
Timer1.Enabled = True
'定时器开始工作
MSComm1.Settings = Text3.Text
'波特率9600,无校验,8位数据位,1位停止位
MSComm1.OutBufferSize = 1024
'设置输出缓冲区大小
MSComm1.InBufferSize = 1024 '设置输入缓冲区大小
MSComm1.InputLen = 512 '每次从输入缓冲区中取一个字符
MSComm1.RTSEnable = True ' RTS信号为高
MSComm1.RThreshold = 2
'产生MSCOMM -EV - RECEIVE事件
MSComm1.PortOpen = True
'打开串口
cd = MSComm1.CDHolding
'取载波检测信号线原始状态
MSComm1.Output = "ATQ0" & Chr$(13)
'启用调制解调器发送结果码。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "ATV1" & Chr$(13)
'以文本的形式发送结果码。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "ATX4" & Chr$(13)
'启用扩展结果码、拨号音检测和忙音检测
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "ATE1" & Chr$(13) '确定调制解调器在命令方式时,您在键盘上输入的字符是否回应到屏幕上(本地回应)。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "ATB0" & Chr$(13)
' Bn 通信标准选项。 在 ITU 与 Bell 标准之间作出确定。
'参数:n = 0 - 3, 15, 16
'n = 0 ITU V.22 使用 1200bps 的传输速率
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "ATN0" & Chr$(13)
'在始发呼叫或应答呼叫时,仅以 S37 寄存器和 ATB 命令指定的速率开始握手
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "ATM2" & Chr$(13)
'在拨号后扬声器始终打开,直到调制解调器检测到载波信号为止,拨号时除外
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT&D0" & Chr$(13)
'&Dn 数据终端就绪选项 在您的计算机准备与调制解调器交换信号时,计算机向调制解调器发送数据终端就绪 (DTR) 信号。 AT&Dn 控制 DTR 选项。
'参数:n = 0, 1, 2, 3
'n = 0 忽略 DTR,视为开启状态。
'n = 1 如果调制解调器处于在线方式时未检测到 DTR,将进入命令方式,发出 OK 结果码并保持连接状态。
'n = 2 如果调制解调器处于在线方式时,未检测到 DTR,调制解调器将挂断 (默认设置)。
'n = 3 调制解调器在检测到 DTR 从 On 过渡到 Off 时重置。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT&K3" & Chr$(13) '启用 RTS/CTS 流控制
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT&Q0" & Chr$(13)
'在异步方式、带缓冲模式下通信,
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT&S0" & Chr$(13)
'DSR 始终打开.&Sn 数据设置就绪选项 .在您的调制解调器准备与计算机交换信号时,调制解调器发送数据设置就绪 (DSR) 信号。 AT&Sn 选择 DSR 操作。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT&V" & Chr$(13)
'查看当前配置 AT&V 显示 S 寄存器的当前配置和命令。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
'MSComm1.Output = "AT&G1" & Chr$(13)
'V.22bis 保护音频选项。n = 0 无保护音频 (默认值) n = 1 550-Hz 保护音频 n = 2 1800-Hz 保护音频
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
End Sub
Private Sub starttiming_Timer()
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "RING") > 0 Then
MSComm1.Output = "ATA" & Chr$(13)
MSComm1.Output = "AT+FCLASS=8" & Chr$(13)
'+FCLASS=8 进入语音模式。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VSP=1" & Chr$(13)
'
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VGS=128" & Chr$(13)
'
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VGM=64" & Chr$(13)
'
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VTS=1" & Chr$(13)
'在语音模式下生成 DTMF 和音频。AT+VTS=n 命令使调制解调器产生参数串指定的 DTMF 音频序列 (或其它音频,例如,拨号音、忙音或静噪音)。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
MSComm1.Output = "AT+VLS=1" & Chr$(13)
'模拟源/目标配置。
'n = 0 调制解调器挂机,本地电话连接至电信公司
'n = 1 调制解调器摘机,调制解调器连接至电信公司。
'n = 2 调制解调器摘机,本地电话连接至调制解调器。
'n = 3 调制解调器摘机,本地电话连接至电信公司,调制解调器连接至本地电话。
'n = 4 扬声器连接至调制解调器,调制解调器挂机 (播放留言)。
'n = 5 扬声器连接至调制解调器,调制解调器摘机 (屏蔽呼叫)。
'n = 6 麦克风连接至调制解调器,调制解调器挂机 (录制问候语)。
'n = 7 连接麦克风和扬声器,调制解调器摘机 (扩音电话)。
Buffer = MSComm1.Input '获 得 Modem的 响 应 信 息
If InStr(Buffer, "AT") > 0 Then
jieshou = jieshou + "
" + Buffer
txtreceived.Text = jieshou
End If
' End If
End If
End Sub
Private Sub stoptiming_Timer()
Timer3.Enabled = False
StatusBar1.Panels("连接时间:").Text = "连接时间:" & format(startTime, "hh:nn:ss")
End Sub
'发送数据:当在发送文本框进行回车操作时,将文本内容送出。
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
'13为回车符
KeyAscii = 0
'清按键,使本次按键失效
MSComm1.Output = Text2.Text & Chr$(13)
'发送数据
End If
End Sub
'修改参数,通过修改Text3的内容,可以修改波特率等参数
Private Sub Text3_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
KeyAscii = 0
err = 0
On Error Resume Next
MSComm1.PortOpen = False
MSComm1.Settings = Text3.Text
MSComm1.PortOpen = True
If err Then
err = 0
MSComm1.PortOpen = False
MSComm1.Settings = oldset
MSComm1.PortOpen = True
Text3 = oldset
End If
oldset = Text3.Text
On Error GoTo 0
End Sub
'滚动显示
Private Sub Timer1_Timer()
If a Then
If Label3.MouseIcon = 0 Then
Text4.Text = "事件"
''要触发的“事件”
a = False
End If
End If
StatusBar1.Panels("状态:").Text = "状态:"
Static js%
Dim i%, s$, ss(100) As Integer
If JSStr <> "" Then
js = js + 1
For i = 0 To 8
ss(i) = ss(i + 1)
Next i
ss(9) = Chr(13) + Chr(10) + Trim(str(js)) + ":\" + JSStr
For i = 1 To 9
s = s + ss(i)
Next i
Text1.Text = Right(s, Len(s) - 2)
JSStr = ""
End If
End Sub
Private Sub Timer2_Timer()
Dim Buffer As Variant
Dim str As String
Dim ringtime As Date
Dim startTime As Date
ringtime = Now()
Text6.Text = ringtime
'For i = 0 To MSComm1.InBufferCount - 1
'Debug.Print Buffer(i);
jieshou = jieshou + Buffer
txtreceived.Text = jieshou
'Next
StatusBar1.Panels("响铃时间:").Text = "响铃时间:" & format(ringtime, "hh:nn:ss") & " "
End Sub
Private Sub Openport()
'初 始 化 Modem
If Not MSComm1.PortOpen Then
= 1
MSComm1.RThreshold = 1
MSComm1.OutBufferSize = 1024
MSComm1.InBufferSize = 1024
MSComm1.Settings = "115200,n,8,1"
MSComm1.PortOpen = True
End If
End Sub
Private Function Waiting(strings As String, waittime As Integer) As String
'接 收 Modem的 返 回 信 息
Dim Endtime As Long
Dim receivestring As String
Endtime = Timer + waittime
receivestring = ""
errorcode = 0
Do
DoEvents
If MSComm1.InBufferCount Then
receivestring = receivestring + MSComm1.Input
If InStr(1, receivestring, strings) Then
Exit Do
End If
End If
If Timer >= Endtime Or errorcode Then
errorcode = 1
Exit Do
End If
Loop
Waiting = receivestring
End Function