📄 dial.bas
字号:
Attribute VB_Name = "Module1"
Type EVENT_SET_INFO
dwWorkMode As Long
lpHandlerParam As Long
dwOutCondition As Long
dwOutParamVal As Long
dwUser As Long
End Type
'EventCode
Const E_CHG_HookState = 36
Const E_CHG_ToneAnalyze = 37
Const E_CHG_ChState = 24
Const E_PROC_AutoDial = 25
Const E_CHG_RcvDTMF = 12
'APP_USER_STATE
Const USER_IDLE = 0
Const USER_GET_PHONE_NUM = 1
Const USER_WAIT_DIAL_TONE = 2
'Const USER_DIALING = 3
Const USER_WAIT_REMOTE_PICKUP = 3
Const USER_TALKING = 4
Const USER_WAIT_HANGUP = 5
Type CH_INFO
'user channel vars
EnCalled As Boolean
lineState As Integer
nStep As Integer
nToTrkCh As Integer
nToUserCh As Integer
pPhoNumBuf As String * 50
nTimeOut As Integer
'trunck channel vars
InUse As Integer
DtmfBuf As String * 100
ToneResult As Integer
End Type
Dim nTotalCh As Integer
Dim ChInfo(0 To 1000) As CH_INFO
Public Declare Function SsmSetEvent Lib "SHP_A3.dll" (ByVal wEvent As Integer, ByVal nReference As Long, ByVal bEnable As Boolean, ByRef pEventSet As EVENT_SET_INFO) As Long
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Function myGetAnIdleChannel() As Integer 'find an ilde trunck channel
Dim i As Integer
For i = 0 To nTotalCh - 1
If (ChInfo(i).InUse = 0) And ChInfo(i).EnCalled Then Exit For
Next i
If i = nTotalCh Then
myGetAnIdleChannel = -1
Else
myGetAnIdleChannel = i
End If
End Function
Public Function InitCtiBoard() As Boolean
'Initialization of CTI driver
Dim fnIni As String * 260
Dim CurPath As String * 260
Dim str1 As String * 200
Dim nDirection As Long
Dim EventSet As EVENT_SET_INFO
EventSet.dwWorkMode = 2
EventSet.lpHandlerParam = CallbackPt(AddressOf EventCallbackProc)
'EventSet.dwUser = Me
CurPath = App.Path + "\ShConfig.ini" + Chr(0)
fnIni = App.Path + "\ShIndex.ini" + Chr(0)
If (SsmStartCti(CurPath, fnIni) <> 0) Then
SsmGetLastErrMsg (str1)
MsgBox str1
InitCtiBoard = False
Else
If (SsmSetEvent(-1, -1, True, EventSet) = -1) Then
MsgBox ("Fail to call SsmSetEvent")
InitCtiBoard = False
End If
nTotalCh = SsmGetMaxCh()
For i = 0 To nTotalCh - 1
ChInfo(i).EnCalled = False
If SsmGetChType(i) = 2 Then ' user channnel
SsmSetASDT i, True
ChInfo(i).pPhoNumBuf = ""
ChInfo(i).nStep = USER_IDLE
Else
'Initialization of channels on trunk-board
If (SsmGetAutoCallDirection(i, nDirection) = 1) Then
If (nDirection = 1 Or nDirection = 2) Then
ChInfo(i).InUse = 0
ChInfo(i).DtmfBuf = ""
SsmSetMinVocDtrEnergy i, 30000
ChInfo(i).EnCalled = True
SsmStartToneAnalyze (i)
End If
End If
End If
Next i
InitCtiBoard = True
End If
End Function
Public Sub InitUserChGrid()
Dim i%
MainForm.UserChGrid.Cols = 3
MainForm.UserChGrid.Row = 0
MainForm.UserChGrid.Col = 0
MainForm.UserChGrid.Text = "Ch"
MainForm.UserChGrid.Col = 1
MainForm.UserChGrid.Text = "User State"
MainForm.UserChGrid.Col = 2
MainForm.UserChGrid.Text = "Called Id"
MainForm.UserChGrid.ColWidth(0) = 30 * 12
MainForm.UserChGrid.ColWidth(1) = 150 * 12
MainForm.UserChGrid.ColWidth(2) = 70 * 12
MainForm.UserChGrid.Rows = 1
For i = 0 To nTotalCh - 1
If (SsmGetChType(i) = 2) Then MainForm.UserChGrid.AddItem (Str(i))
Next i%
End Sub
Public Sub InitTrunkChGrid()
Dim i%
MainForm.TrkChGrid.Cols = 3
MainForm.TrkChGrid.Row = 0
MainForm.TrkChGrid.Col = 0
MainForm.TrkChGrid.Text = "Ch"
MainForm.TrkChGrid.Col = 1
MainForm.TrkChGrid.Text = "Trunk State"
MainForm.TrkChGrid.Col = 2
MainForm.TrkChGrid.Text = "DTMF KEY"
' MainForm.TrkChGrid.Col = 3
' MainForm.TrkChGrid.Text = "ToneAnalyzeResult"
MainForm.TrkChGrid.ColWidth(0) = 30 * 12
MainForm.TrkChGrid.ColWidth(1) = 250 * 12
MainForm.TrkChGrid.ColWidth(2) = 100 * 12
' MainForm.TrkChGrid.ColWidth(3) = 100 * 12
MainForm.TrkChGrid.Rows = 1
For i = 0 To nTotalCh - 1
If (ChInfo(i).EnCalled = True) Then MainForm.TrkChGrid.AddItem (Str(i))
Next i%
End Sub
Public Sub DrawTrunkChState()
Dim state As String
Dim tone As String
Dim i As Integer
Dim TheIndex As Integer
Dim nindex As Integer
nindex = 0
For i = 0 To nTotalCh - 1
If ChInfo(i).EnCalled = True Then
TheIndex = MainForm.TrkChGrid.Cols * (nindex + 1) + 1
Select Case (ChInfo(i).InUse)
Case 0
state = "idle"
Case 1
state = "pickup"
Case 2
state = "dial"
Case 3
state = "wait remote pickup"
Case 4
state = "talking"
Case 5
state = "dialing"
Case 6
state = "send called id and find ring back"
Case 7
state = "not find dial tone,autodial failed"
Case 8
state = "remote user busy,dial over"
Case 9
state = "no voice, autodial over"
Case 10
state = "no voice, autodial over"
Case 11
state = "fax1 voice, autodial over"
Case 12
state = "fax2 voice, autodial over"
Case 13
state = "remote don't pickup,autodial over"
Case 14
state = "remote don't pickup,autodial over"
Case 15
state = "null caller id,autodial over"
Case 16
state = "channel idle no dialing"
End Select
If MainForm.TrkChGrid.TextArray(TheIndex) <> state Then MainForm.TrkChGrid.TextArray(TheIndex) = state
TheIndex = TheIndex + 1
SsmGetDtmfStr i, ChInfo(i).DtmfBuf
If MainForm.TrkChGrid.TextArray(TheIndex) <> ChInfo(i).DtmfBuf Then MainForm.TrkChGrid.TextArray(TheIndex) = ChInfo(i).DtmfBuf
nindex = nindex + 1
End If
Next i
End Sub
Public Sub DrawUserChState()
Dim state As String
Dim i As Integer
Dim TheIndex As Integer
Dim nindex As Integer
nindex = 0
For i = 0 To nTotalCh - 1
If (SsmGetChType(i) = 2) Then
TheIndex = MainForm.UserChGrid.Cols * (nindex + 1) + 1
Select Case (ChInfo(i).nStep)
Case USER_IDLE
state = "idle"
Case USER_GET_PHONE_NUM
state = "get phone num"
Case USER_WAIT_DIAL_TONE
state = "wait dial tone"
Case USER_DIALING
state = "dialing..."
Case USER_WAIT_REMOTE_PICKUP
state = "wait remote pickup"
Case USER_TALKING
state = "talking"
Case USER_WAIT_HANGUP
state = "wait hangup"
End Select
If MainForm.UserChGrid.TextArray(TheIndex) <> state Then MainForm.UserChGrid.TextArray(TheIndex) = state
TheIndex = TheIndex + 1
If MainForm.UserChGrid.TextArray(TheIndex) <> ChInfo(i).pPhoNumBuf Then MainForm.UserChGrid.TextArray(TheIndex) = ChInfo(i).pPhoNumBuf
nindex = nindex + 1
End If
Next i
End Sub
Public Function EventCallbackProc(ByVal wEvent As Integer, ByVal nReference As Long, ByVal dwParam As Long, ByVal dwUser As Long) As Long
Dim ch As Integer
Dim Tch As Integer
Dim PhoNumLen As Integer
Dim dwDtmf As Long
Dim dtmflen As Integer
Dim nParam As Long
ch = nReference
Select Case (wEvent)
Case E_CHG_ToneAnalyze
ChInfo(ch).ToneResult = (dwParam Mod 65536)
Case E_CHG_HookState
If (dwParam = 1) Then 'user-pickup detected
If (ChInfo(ch).nStep = Idle) Then
ChInfo(ch).pPhoNumBuf = ""
SsmClearRxDtmfBuf (ch)
ChInfo(ch).nStep = USER_GET_PHONE_NUM
End If
Else
Select Case (ChInfo(ch).nStep)
Case USER_GET_PHONE_NUM
SsmClearRxDtmfBuf (ch)
ChInfo(ch).pPhoNumBuf = ""
SsmClearRxDtmfBuf (ch)
ChInfo(ch).nStep = USER_IDLE
Case USER_WAIT_REMOTE_PICKUP
SsmHangup (ChInfo(ch).nToTrkCh)
ChInfo(ChInfo(ch).nToTrkCh).InUse = 0
SsmClearRxDtmfBuf (ChInfo(ch).nToTrkCh)
SsmClearRxDtmfBuf (ch)
ChInfo(ch).nStep = USER_IDLE
ChInfo(ch).pPhoNumBuf = ""
SsmClearRxDtmfBuf (ch)
Case USER_TALKING
SsmHangup (ChInfo(ch).nToTrkCh)
SsmStopTalkWith ChInfo(ch).nToTrkCh, ch
SsmClearRxDtmfBuf (ChInfo(ch).nToTrkCh)
ChInfo(ChInfo(ch).nToTrkCh).InUse = 0
ChInfo(ch).nStep = USER_IDLE
ChInfo(ch).pPhoNumBuf = ""
SsmClearRxDtmfBuf (ch)
Case USER_WAIT_HANGUP
SsmStopSendTone (ch) 'stop sending busy tone
SsmClearRxDtmfBuf (ch)
ChInfo(ch).nStep = USER_IDLE
ChInfo(ch).pPhoNumBuf = ""
SsmClearRxDtmfBuf (ch)
SsmHangup (ChInfo(ch).nToTrkCh)
ChInfo(ChInfo(ch).nToTrkCh).InUse = 0
SsmClearRxDtmfBuf (ChInfo(ch).nToTrkCh)
End Select
End If
Case E_CHG_ChState
nParam = (dwParam Mod 65536) 'the dwParam's lword
If (nParam = S_CALL_PENDING) Then
If (ChInfo(ChInfo(ch).nToUserCh).nStep = USER_WAIT_REMOTE_PICKUP) Then
SsmHangup (ch)
ChInfo(ch).InUse = 0
SsmClearRxDtmfBuf (ch)
SsmSendTone ChInfo(ch).nToUserCh, 1 'send busy tone
ChInfo(ChInfo(ch).nToUserCh).nStep = USER_WAIT_HANGUP
ElseIf (ChInfo(ChInfo(ch).nToUserCh).nStep = USER_TALKING) Then
SsmHangup (ch)
SsmStopTalkWith ch, ChInfo(ch).nToUserCh
SsmClearRxDtmfBuf (ch)
ChInfo(ch).InUse = 0
SsmSendTone ChInfo(ch).nToUserCh, 1 'send busy tone
ChInfo(ChInfo(ch).nToUserCh).nStep = USER_WAIT_HANGUP
End If
End If
Case E_PROC_AutoDial 'See Synway's user manual
Select Case (dwParam)
Case 1
ChInfo(ch).InUse = 5
Case 2
ChInfo(ch).InUse = 6
Case 3
ChInfo(ch).InUse = 7
Case 4
ChInfo(ch).InUse = 8
Case 5
ChInfo(ch).InUse = 9
Case 6
ChInfo(ch).InUse = 10
Case 7
SsmTalkWith ChInfo(ch).nToUserCh, ch
ChInfo(ch).InUse = 4
ChInfo(ChInfo(ch).nToUserCh).nStep = USER_TALKING
Case 8
ChInfo(ch).InUse = 11
Case 9
ChInfo(ch).InUse = 12
Case 10
SsmHangup (ch)
ChInfo(ch).InUse = 13
SsmClearRxDtmfBuf (ch)
SsmSendTone ChInfo(ch).nToUserCh, 1 'send busy tone
ChInfo(ChInfo(ch).nToUserCh).nStep = USER_WAIT_HANGUP
Case 11
ChInfo(ch).InUse = 14
Case 12
ChInfo(ch).InUse = 15
End Select
' End If
Case E_CHG_RcvDTMF
If (ChInfo(ch).nStep = USER_GET_PHONE_NUM) Then
PhoNumLen = CInt(MainForm.Text1.Text)
'dwDtmf = nlParam And &HFFFF& 'the latest DTMF received
If (SsmGetRxDtmfLen(ch) >= PhoNumLen) Then
SsmGetDtmfStr ch, ChInfo(ch).pPhoNumBuf 'retrieve phone num
Mid$(ChInfo(ch).pPhoNumBuf, PhoNumLen + 1, 1) = Chr$(0)
Tch = myGetAnIdleChannel()
If (Tch = -1) Then 'no idle trunk channel available
SsmSendTone ch, 1 'send busy tone
ChInfo(ch).nStep = USER_WAIT_HANGUP
Else
SsmPickup (Tch)
ChInfo(Tch).InUse = 1
ChInfo(Tch).nToUserCh = ch
ChInfo(ch).nToTrkCh = Tch
nTemp = SsmAutoDial(Tch, ChInfo(ch).pPhoNumBuf)
If (nTemp = 0) Then
ChInfo(Tch).InUse = 2
ChInfo(ch).nStep = USER_WAIT_REMOTE_PICKUP
Else
SsmHangup (Tch)
ChInfo(Tch).InUse = 0
SsmClearRxDtmfBuf (Tch)
SsmSendTone ch, 1
ChInfo(ch).nStep = USER_WAIT_HANGUP
End If
End If
End If
End If
End Select
End Function
Public Function CallbackPt(ByVal PtValue As Long) As Long
CallbackPt = PtValue
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -