📄 fax.bas
字号:
CallBack_MessageProc FaxMsg.E_MSG_OFFLINE, m_TrkCh(nCh).nToFaxCh, 0, Fax.hWnd
End If
HangUp (nCh)
End If
'event generated by the driver when DTMF is received
Case ShEvent.E_CHG_RcvDTMF
dwDtmf = nlParam Mod 65536 'the latest DTMF received
temp = Chr(dwDtmf)
m_TrkCh(nCh).szDtmf = m_TrkCh(nCh).szDtmf + temp
m_TrkCh(nCh).nIndex = m_TrkCh(nCh).nIndex + 1
If (dwDtmf = 49 Or dwDtmf = 50) Then '1 or 2
If (m_TrkCh(nCh).nStep = TrkChState.TRK_PLAY_VOC1) Then
m_TrkCh(nCh).nFirstDtmf = m_TrkCh(nCh).nFirstDtmf + 1
If (m_TrkCh(nCh).nFirstDtmf = 1) Then
m_TrkCh(nCh).nDtmfChose = dwDtmf
SsmPlayIndexString nCh, "2"
SsmStopTimer (m_TrkCh(nCh).nTimer)
m_TrkCh(nCh).nTimer = -1
m_TrkCh(nCh).nStep = TrkChState.TRK_PLAY_VOC2
End If
End If
End If
'event generated by the driver when the timer is overtime
Case ShEvent.E_SYS_TIMEOUT
SsmStopTimer (m_TrkCh(nCh).nTimer)
m_TrkCh(nCh).nTimer = -1
HangUp (nCh)
'event generated by the driver when the result of tone analysis changes
Case ShEvent.E_CHG_ToneAnalyze
dwToneAnalyze = nlParam Mod 65536 'the result of tone analysis
If (dwToneAnalyze = 7) Then 'F1 tone
If (m_TrkCh(nCh).nStep = TrkChState.TRK_PLAY_VOC2) Then
m_FaxCh(m_TrkCh(nCh).nToFaxCh).nDirection = FaxDir.C_RECEIVE_FAX 'receive
SsmStopPlayIndex (nCh) 'stop playing
SsmTalkWith nCh, m_TrkCh(nCh).nToFaxCh
m_FaxCh(m_TrkCh(nCh).nToFaxCh).nAnswered = 1
m_TrkCh(nCh).nStep = TrkChState.TRK_FAXING
CallBack_MessageProc FaxMsg.E_MSG_RCV_FAX, m_TrkCh(nCh).nToFaxCh, nCh, Fax.hWnd
ElseIf (m_TrkCh(nCh).nStep = TrkChState.TRK_FAXING) Then
m_FaxCh(m_TrkCh(nCh).nToFaxCh).nAnswered = 1
End If
ElseIf (dwToneAnalyze = 8) Then 'F2 tone
If (m_TrkCh(nCh).nStep = TrkChState.TRK_PLAY_VOC2) Then
m_FaxCh(nCh).nDirection = FaxDir.C_SEND_FAX 'send
SsmStopPlayIndex (nCh) 'i 'stop playing
SsmTalkWith nCh, m_TrkCh(nCh).nToFaxCh
m_FaxCh(nCh).nAnswered = 1
m_TrkCh(i).nStep = TrkChState.TRK_FAXING
CallBack_MessageProc FaxMsg.E_MSG_SEND_FAX, m_TrkCh(nCh).nToFaxCh, nCh, Fax.hWnd
ElseIf (m_TrkCh(nCh).nStep = TrkChState.TRK_FAXING) Then
m_FaxCh(m_TrkCh(nCh).nToFaxCh).nAnswered = 1
End If
End If
'event generated by the driver when the playing stops
Case ShEvent.E_PROC_PlayEnd
If (m_TrkCh(nCh).nStep = TrkChState.TRK_PLAY_VOC2) Then
SsmTalkWith nCh, m_TrkCh(nCh).nToFaxCh
If (m_TrkCh(nCh).nDtmfChose = 49) Then
m_FaxCh(m_TrkCh(nCh).nToFaxCh).nDirection = FaxDir.C_SEND_FAX 'send
CallBack_MessageProc FaxMsg.E_MSG_SEND_FAX, m_TrkCh(nCh).nToFaxCh, nCh, Fax.hWnd
Else
m_FaxCh(m_TrkCh(nCh).nToFaxCh).nDirection = FaxDir.C_RECEIVE_FAX 'receive
CallBack_MessageProc FaxMsg.E_MSG_RCV_FAX, m_TrkCh(nCh).nToFaxCh, nCh, Fax.hWnd
End If
End If
' event generated by the driver when the fax channel state turns to be idle
Case FaxMsg.E_MSG_FAX_IDLE
SsmStopTalkWith nCh, m_TrkCh(nCh).nToFaxCh
m_TrkCh(nCh).nStep = TrkChState.TRK_IDLE
m_FaxCh(m_TrkCh(nCh).nToFaxCh).bUseful = False
HangUp (nCh)
'event generated by the driver when the task of auto-dialing progresses
Case ShEvent.E_PROC_AutoDial
If (m_TrkCh(nCh).nStep = TrkChState.TRK_DIALING) Then
Select Case (nlParam)
Case AutoDial.DIAL_NO_DIALTONE
m_TrkCh(nCh).szChErrMsg = "No dial tone"
HangUp (nCh)
Case AutoDial.DIAL_BUSYTONE
m_TrkCh(nCh).szChErrMsg = "Busy tone"
HangUp (nCh)
Case AutoDial.DIAL_ECHO_NOVOICE
m_TrkCh(nCh).szChErrMsg = "Silent after ringback tone"
HangUp (nCh)
Case AutoDial.DIAL_NOVOICE
m_TrkCh(nCh).szChErrMsg = "Silent after dial tone"
Case AutoDial.DIAL_VOICEF1
m_TrkCh(nCh).szChErrMsg = "The receiver's fax machine answers and it is in transmitting process"
HangUp (nCh)
Case AutoDial.DIAL_NOANSWER
m_TrkCh(nCh).szChErrMsg = "Nobody answers"
HangUp (nCh)
' called party picked up (voice detected)
Case AutoDial.DIAL_VOICE
'turn on 'DTMF_stop_play' switch
SsmSetDtmfStopPlay nCh, True
SsmPlayIndexString nCh, "1" 'play voice 1
SsmClearRxDtmfBuf (nCh) 'clear DTMF buffer
m_TrkCh(nCh).nTimer = SsmStartTimer(15000, 1)
m_TrkCh(nCh).nStep = TrkChState.TRK_PLAY_VOC1
'//F2 tone detected
Case AutoDial.DIAL_VOICEF2
SsmTalkWith nCh, m_TrkCh(nCh).nToFaxCh
m_FaxCh(m_TrkCh(nCh).nToFaxCh).nAnswered = 1
m_FaxCh(m_TrkCh(nCh).nToFaxCh).nDirection = FaxDir.C_SEND_FAX 'send
m_TrkCh(i).nStep = TrkChState.TRK_FAXING
CallBack_MessageProc FaxMsg.E_MSG_SEND_FAX, m_TrkCh(nCh).nToFaxCh, nCh, Fax.hWnd
Case AutoDial.DIAL_INVALID_PHONUM
m_TrkCh(nCh).szChErrMsg = "empty phone number"
HangUp (nCh)
End Select
End If
' event generated by us when faxing task is available
Case FaxMsg.E_MSG_HAVETASK
SsmPickup (nCh) 'pick up
szRecFile = "channel" + Format(nCh) + ".pcm"
If (m_TrkCh(nCh).bRecord) Then
SsmRecToFile nCh, szRecFile, -1, 0, -1, -1, 0 'record
' turn on record mixer
SsmSetRecMixer nCh, True, 0
End If
If (SsmAutoDial(nCh, m_TrkCh(nCh).szCallNo) = -1) Then 'auto-dialing failed
SsmGetLastErrMsg (strbErrMsg)
m_TrkCh(nCh).szChErrMsg = strbErrMsg
HangUp (nCh)
Else
m_TrkCh(nCh).nCallFlag = 1
m_TrkCh(nCh).nStep = TrkChState.TRK_DIALING
End If
End Select
End Sub
'state transition for fax channel
Public Sub FaxProc(ByVal Event1 As Long, ByVal nwParam As Long, ByVal nlParam As Long)
Dim strTemp As String ' name of file to receive
Dim i As Long ' channel number
'Dim j As Long
i = nwParam
Select Case (Event1)
' event indicating the start of faxing
Case FaxMsg.E_MSG_SEND_FAX
If (m_FaxCh(i).nStep = FaxChStep.FAX_IDLE) Then
m_TrkCh(m_FaxCh(i).nTrunkCh).nCallFlag = -1
m_FaxCh(i).szSendFile = Fax.TxFileName.Text
If (m_FaxCh(i).szSendFile <> "") Then
If (SsmFaxStartSend(i, m_FaxCh(i).szSendFile) = -1) Then 'send
SsmGetLastErrMsg (strbErrMsg)
m_FaxCh(i).szChErrMsg = strbErrMsg
m_FaxCh(i).nStep = FaxChStep.FAX_IDLE
m_FaxCh(i).szRcvPathFile = ""
m_FaxCh(i).szSendFile = ""
m_TrkCh(m_FaxCh(i).nTrunkCh).nStep = TrkChState.TRK_FAXING
CallBack_MessageProc FaxMsg.E_MSG_FAX_IDLE, m_FaxCh(i).nTrunkCh, i, Fax.hWnd
Else
m_FaxCh(i).nStep = FaxChStep.FAX_CHECK_END
End If
Else
CallBack_MessageProc FaxMsg.E_MSG_FAX_IDLE, m_FaxCh(i).nTrunkCh, i, Fax.hWnd
End If
End If
'the event is triggered when faxing is started
Case FaxMsg.E_MSG_RCV_FAX
If (m_FaxCh(i).nStep = FaxChStep.FAX_IDLE) Then
m_FaxCh(i).szRcvPathFile = Fax.RxFilePath.Text
m_FaxCh(i).szRcvPathFile = m_FaxCh(i).szRcvPathFile & "\"
' fax file name + channel ID
strTemp = Fax.RxFileName.Text '"DefaultFax.tif"
m_FaxCh(i).szRcvPathFile = m_FaxCh(i).szRcvPathFile & strTemp
If (SsmFaxStartReceive(i, m_FaxCh(i).szRcvPathFile) = -1) Then 'receive
SsmGetLastErrMsg (strbErrMsg)
m_FaxCh(i).szChErrMsg = strbErrMsg
m_FaxCh(i).nStep = FaxChStep.FAX_IDLE
m_FaxCh(i).szRcvPathFile = ""
m_FaxCh(i).szSendFile = ""
m_TrkCh(m_FaxCh(i).nTrunkCh).nStep = TrkChState.TRK_FAXING
CallBack_MessageProc FaxMsg.E_MSG_FAX_IDLE, m_FaxCh(i).nTrunkCh, i, Fax.hWnd
Else
m_FaxCh(i).nStep = FaxChStep.FAX_CHECK_END
End If
End If
'check faxing status
Case ShEvent.E_PROC_FaxEnd
If (m_FaxCh(i).nStep = FaxChStep.FAX_CHECK_END) Then
m_FaxCh(i).nCheckEnd = nlParam
Select Case m_FaxCh(i).nCheckEnd
'成功完成 faxing is complete successfully
Case 1
m_FaxCh(i).nStep = FaxChStep.FAX_IDLE
m_FaxCh(i).szRcvPathFile = ""
m_FaxCh(i).szSendFile = ""
'm_FaxCh(i).szSendPath = ""
CallBack_MessageProc FaxMsg.E_MSG_FAX_IDLE, m_FaxCh(i).nTrunkCh, i, Fax.hWnd
' error
Case 2
If ((SsmFaxGetPages(i) > 0) Or (SsmFaxGetSendBytes(i) > 0)) Then
'WriteLog ("Failed to fax : failure in page phase")
Else
If (m_FaxCh(i).nAnswered = 1) Then
'WriteLog ("Failed to fax : failure in handshake phase")
ElseIf (m_FaxCh(i).nAnswered = 0) Then
'WriteLog ("Failed to fax : the receiver doesn't press key 'start' or time out when waiting for key 'start'")
End If
End If
m_FaxCh(i).nStep = FaxChStep.FAX_IDLE
m_FaxCh(i).szRcvPathFile = ""
m_FaxCh(i).szSendFile = ""
CallBack_MessageProc FaxMsg.E_MSG_FAX_IDLE, m_FaxCh(i).nTrunkCh, i, Fax.hWnd
End Select
End If
' a faxing page is finished
Case ShEvent.E_CHG_FaxPages
m_FaxCh(i).szPage = Format(nlParam)
' event indicating the hangup of the remote fax machine
Case FaxMsg.E_MSG_OFFLINE
If (m_FaxCh(i).nStep = FaxChStep.FAX_CHECK_END) Then
SsmFaxStop (i)
m_FaxCh(i).nStep = FaxChStep.FAX_IDLE
m_FaxCh(i).szRcvPathFile = ""
m_FaxCh(i).szSendFile = ""
End If
End Select 'end of switch of event1
End Sub
'hang up channel
Public Sub HangUp(ByVal nChannel As Long)
Dim nCh As Long
nCh = nChannel
SsmHangup (nCh) 'remote hangup
SsmStopRecToFile (nCh) 'stop recording
m_TrkCh(nCh).nStep = TrkChState.TRK_IDLE
m_TrkCh(nCh).szCallerId = ""
If (m_TrkCh(nCh).bLinked) Then
m_FaxCh(m_TrkCh(nCh).nToFaxCh).bUseful = False 'the channel is useful
m_TrkCh(nCh).bLinked = False
End If
m_TrkCh(nCh).bUseful = False 'useful
m_TrkCh(nCh).nFirstDtmf = 0
m_TrkCh(nCh).szDtmf = ""
End Sub
'search for idle fax channel
Public Function FindAnIdleFaxCh() As Long
Dim nCheck As Long
Dim i As Long
For i = 0 To m_nTotalCh - 1
nCheck = SsmGetChType(i)
If (nCheck = -1) Then
'WriteLog ("Fail to call SsmGetChType")
ElseIf ((nCheck = ChType.FAX_CH Or nCheck = ChType.SOFTFAX_CH) _
And (m_FaxCh(i).nStep = FaxChStep.FAX_IDLE) And (m_FaxCh(i).bUseful = False)) Then
FindAnIdleFaxCh = i
GoTo breakPoint
Return
End If
Next i
FindAnIdleFaxCh = -2
breakPoint:
End Function
'search for idle trunk channel
Public Function FindAnIdleTrunkCh() As Long
Dim i As Long
For i = 0 To m_nTotalCh - 1
If (m_TrkCh(i).bEnCalled = True And m_TrkCh(i).bUseful = False _
And m_TrkCh(i).nStep = TrkChState.TRK_IDLE) Then
FindAnIdleTrunkCh = i
GoTo breakPoint
End If
Next i
FindAnIdleTrunkCh = -1
breakPoint:
End Function
Public Sub WriteLog(ByVal szLog As String)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -