📄 call.bas
字号:
Attribute VB_Name = "Call"
Option Explicit
'Event struct(synway define)
Type EVENT_SET_INFO
dwWorkMode As Long
lpHandlerParam As Long
dwOutCondition As Long
dwOutParamVal As Long
dwUser As Long
End Type
Public Declare Function SsmSetEvent Lib "SHP_A3.dll" (ByVal wEvent As Integer, _
ByVal nReference As Integer, _
ByVal bEnable As Boolean, _
ByRef pEventSet As EVENT_SET_INFO) As Integer
'**********************************************************************
'
'ch0 -> ch1 -> ch2
'
'**********************************************************************
Public Type CH_INFO
bEnCalled As Boolean
nStep As Integer 'User-defined status
szCallerId As String * 20 'CallerId
szDtmf As String 'DTMF
nTimer As Integer 'Timer
nLinkCh As Integer
bIsPick As Boolean 'if ch1 pick up
bIsFlash As Boolean 'if ch2 pick up
szOwnNum As String 'assigned phone number
bFlag As Boolean 'if ch0 hang up
nFLinkCh As Integer 'Original part
szExtensionNum As String
bChk As Boolean 'Check if receiving number was done
End Type
Const TRK_IDLE = 0
Const TRK_WAIT_CONNECT = 1
Const TRK_WAIT_DTMF = 2
Const TRK_CHECK_HOOK = 3
Const TRK_TALKING = 4
Const TRK_FLASH = 5
Const USER_IDLE = 6
Const USER_TALKING = 7
Const USER_WAIT_DTMF = 8
Const USER_F_WAIT = 9
Const USER_F_TALK = 10
Const USER_F_HANG = 11
Const USER_WAIT_HANG = 12
Public ChInfo(0 To 1000) As CH_INFO
Public nMaxCh As Integer
Const E_CHG_RcvDTMF = &HC
Const E_CHG_ChState = &H18
Const E_SYS_TIMEOUT = &H30
Const E_CHG_FlashCount = &H23
Const E_CHG_HookState = &H24
Const E_MSG_RELEASE = &H50
Const E_MSG_PICKUP = &H51
Const E_F_FLASH = &H52
Const E_MSG_CONN = &H53
'Initialize board
Function InitCtiBoard() As Boolean
Dim ErrMsg As String * 260
Dim szConfig As String * 260
Dim szIndex As String * 260
Dim i As Integer
Dim nPhoNum As Integer
nPhoNum = 0
szConfig = App.Path + "\ShConfig.ini" + Chr(0)
szIndex = App.Path + "\ShIndex.ini" + Chr(0)
'Load configuration file and initialize system
If (SsmStartCti(szConfig, szIndex) <> 0) Then
SsmGetLastErrMsg (ErrMsg) 'Get error message
MsgBox (ErrMsg)
InitCtiBoard = False
Else
'Judge if the number of initialized boards is the same as
' that of boards specified in the configuration file
If (SsmGetMaxUsableBoard() <> SsmGetMaxCfgBoard()) Then
SsmGetLastErrMsg (ErrMsg) ' Get error message
MsgBox (ErrMsg)
InitCtiBoard = False
Else
'Get the maximum number of the channels
nMaxCh = SsmGetMaxCh()
If (nMaxCh = -1) Then
MsgBox ("Fail to call SsmGetMaxCh")
End If
'initialize the variables
For i = 0 To nMaxCh - 1
ChInfo(i).szOwnNum = ""
Select Case SsmGetChType(i)
Case 0, 4, 6, 7, 8, 11, 12
ChInfo(i).nStep = TRK_IDLE
ChInfo(i).bEnCalled = True
Case 2
ChInfo(i).nStep = USER_IDLE
ChInfo(i).bEnCalled = True
ChInfo(i).szOwnNum = Format(2000 + nPhoNum)
nPhoNum = nPhoNum + 1
Case Else
ChInfo(i).nStep = -1
ChInfo(i).bEnCalled = False
End Select
ChInfo(i).bIsFlash = False
ChInfo(i).bIsPick = False
ChInfo(i).nLinkCh = -1
ChInfo(i).nTimer = -1
ChInfo(i).szCallerId = ""
ChInfo(i).szDtmf = ""
ChInfo(i).bFlag = False
ChInfo(i).nFLinkCh = -1
ChInfo(i).szExtensionNum = ""
ChInfo(i).bChk = False
Next i
InitCtiBoard = True
End If
End If
End Function
Public Sub InitCircuitListCtrl()
Dim i%
MainForm.ChGrid.Cols = 4
MainForm.ChGrid.Row = 0
MainForm.ChGrid.Col = 0
MainForm.ChGrid.Text = "Ch"
MainForm.ChGrid.Col = 1
MainForm.ChGrid.Text = "ChState"
MainForm.ChGrid.Col = 2
MainForm.ChGrid.Text = "CallerId"
MainForm.ChGrid.Col = 3
MainForm.ChGrid.Text = "DTMF"
MainForm.ChGrid.ColWidth(0) = 60 * 12
MainForm.ChGrid.ColWidth(1) = 178 * 12
MainForm.ChGrid.ColWidth(2) = 100 * 12
MainForm.ChGrid.ColWidth(3) = 150 * 12
MainForm.ChGrid.Rows = 1
For i = 0 To nMaxCh - 1
If ChInfo(i).bEnCalled Then MainForm.ChGrid.AddItem (Str(i) + ":" + ChInfo(i).szOwnNum)
Next i
End Sub
Public Sub UpdateChListCtrl()
Dim szNewStat As String * 100
Dim szOldStat As String * 100
Dim i As Integer
Dim nIndex%
nIndex = 0
For i = 0 To nMaxCh - 1
If ChInfo(i).bEnCalled Then
Select Case (ChInfo(i).nStep)
Case TRK_IDLE
szNewStat = "Idle"
Case TRK_WAIT_CONNECT
szNewStat = "Connecting"
Case TRK_WAIT_DTMF
szNewStat = "Playing dial extension NO"
Case TRK_CHECK_HOOK
szNewStat = "Waiting for answering"
Case TRK_TALKING
szNewStat = "Talking"
Case TRK_FLASH
szNewStat = "Call is being diverted "
Case USER_IDLE
szNewStat = "Idle"
Case USER_TALKING
szNewStat = "Talking"
Case USER_WAIT_DTMF
szNewStat = "Playing dial extension NO"
Case USER_F_WAIT
szNewStat = "Wait for pickup"
Case USER_F_TALK
szNewStat = "Talking"
Case USER_F_HANG
szNewStat = "Opposite is busy"
Case USER_WAIT_HANG
szNewStat = "Wait for hangup"
End Select
szOldStat = MainForm.ChGrid.TextMatrix(nIndex + 1, 1)
If (szOldStat <> szNewStat) Then
MainForm.ChGrid.TextMatrix(nIndex + 1, 1) = szNewStat
End If
szOldStat = MainForm.ChGrid.TextMatrix(nIndex + 1, 2)
If (szOldStat <> ChInfo(i).szCallerId) Then
MainForm.ChGrid.TextMatrix(nIndex + 1, 2) = ChInfo(i).szCallerId
End If
szOldStat = MainForm.ChGrid.TextMatrix(nIndex + 1, 3)
If (szOldStat <> ChInfo(i).szDtmf) Then
MainForm.ChGrid.TextMatrix(nIndex + 1, 3) = ChInfo(i).szDtmf
End If
nIndex = nIndex + 1
End If
Next i
End Sub
Function CheckChIsUseable(ByVal nCh As Integer) As Boolean
Dim nTemp As Integer
nTemp = SsmGetChType(nCh)
If nTemp <> 2 Then
CheckChIsUseable = False
Else
If (SsmGetHookState(nCh) = 0) And (ChInfo(nCh).bIsFlash = False) _
And (ChInfo(nCh).bIsPick = False) Then
CheckChIsUseable = True
Else
CheckChIsUseable = False
End If
End If
End Function
'Callback Procedure
Function EventCallbackProc(ByVal uMsg As Integer, ByVal wParam As Long, ByVal lParam As Long, ByVal dwUser As Long) As Long
Dim nCh As Integer
Dim i%
Dim nEventCode As Integer
Dim nNewState As Integer
Dim cNewDtmf As String
Dim nRes As Integer
nEventCode = uMsg
Select Case nEventCode
'Event generated by the driver when the status of channel changes
Case E_CHG_ChState
nCh = wParam
nNewState = CInt(lParam And &HFFFF&) 'New state // 32-bits(high 16bits:old state,low 16bits:new state)
Select Case nNewState
Case S_CALL_RINGING 'remote ringing
If ChInfo(nCh).nStep = TRK_IDLE Then
If SsmPickup(nCh) = -1 Then
MsgBox ("Fail to call SsmPickup")
End If
If SsmClearRxDtmfBuf(nCh) = -1 Then 'Clear received DTMF buffer
MsgBox ("Fail to call SsmClearRxDtmfBuf")
End If
ChInfo(nCh).szDtmf = ""
ChInfo(nCh).nStep = TRK_WAIT_CONNECT
End If
Case S_CALL_TALKING 'talking status
If ChInfo(nCh).nStep = TRK_WAIT_CONNECT Then
SsmClearFileList (nCh)
ChInfo(nCh).szCallerId = ""
If SsmGetCallerId(nCh, ChInfo(nCh).szCallerId) = -1 Then
MsgBox ("Fail to call SsmGetCallerId")
End If
If SsmAddToFileList(nCh, "..\..\..\..\..\DemoVoc\Welcom1.voc", 6, 0, -1) = -1 Or _
SsmAddToFileList(nCh, "..\..\..\..\..\DemoVoc\Welcom2.voc", 6, 0, -1) = -1 Then 'add file to the play list
MsgBox ("Fail to call SsmAddToFile")
End If
If SsmPlayFileList(nCh) = -1 Then 'Play "welcome"
MsgBox ("Fail to call SsmPlayFileList")
End If
ChInfo(nCh).nTimer = SsmStartTimer(15000, 1) 'start timer
If (ChInfo(nCh).nTimer = -1) Then
MsgBox ("Fail to call SsmStartTimer")
End If
ChInfo(nCh).nStep = TRK_WAIT_DTMF
End If
Case S_CALL_PENDING 'remote hangup
Select Case ChInfo(nCh).nStep
Case TRK_WAIT_DTMF
SsmStopPlayFileList (nCh)
SsmStopTimer (ChInfo(nCh).nTimer) 'stop timer
ChInfo(nCh).nTimer = -1
If SsmHangup(nCh) = -1 Then
MsgBox ("Fail to call SsmHangup")
End If
ChInfo(nCh).nLinkCh = -1
ChInfo(nCh).szExtensionNum = ""
ChInfo(nCh).nStep = TRK_IDLE
ChInfo(nCh).szCallerId = ""
ChInfo(nCh).szDtmf = ""
Case TRK_CHECK_HOOK
ChInfo(ChInfo(nCh).nLinkCh).bIsPick = False
SsmStopRing (ChInfo(nCh).nLinkCh) 'stop ring to ch1
SsmStopPlay (nCh)
If SsmHangup(nCh) = -1 Then
MsgBox ("Fail to call SsmHangup")
End If
ChInfo(ChInfo(nCh).nLinkCh).szCallerId = ""
ChInfo(ChInfo(nCh).nLinkCh).nLinkCh = -1
ChInfo(nCh).nLinkCh = -1
ChInfo(nCh).nStep = TRK_IDLE
ChInfo(nCh).szCallerId = ""
ChInfo(nCh).szDtmf = ""
Case TRK_TALKING
If SsmStopTalkWith(ChInfo(nCh).nLinkCh, nCh) = -1 Then
MsgBox ("Fail to call SsmStopTalkWith")
End If
EventCallbackProc E_MSG_RELEASE, ChInfo(nCh).nLinkCh, 0, 0
If SsmHangup(nCh) = -1 Then
MsgBox ("Fail to call SsmHangup")
End If
ChInfo(nCh).nStep = TRK_IDLE
ChInfo(nCh).nLinkCh = -1
ChInfo(nCh).szCallerId = ""
ChInfo(nCh).szDtmf = ""
Case TRK_FLASH
ChInfo(ChInfo(nCh).nLinkCh).bFlag = True
SsmStopPlay nCh
If SsmHangup(nCh) = -1 Then
MsgBox ("Fail to call SsmHangup")
End If
ChInfo(nCh).nStep = TRK_IDLE
ChInfo(nCh).nLinkCh = -1
ChInfo(nCh).szCallerId = ""
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -