Fog Creek Software
Discussion Board

Answering Machine (MsCOMM)

I am trying to design a application for call center, using MsCOMM (no TAPI) in VB6.
It is able to dial & Recieve calls, (Most of Codes are CUT & PASTE ;). But now i want to record the conversartion.
So, please guide me how to record a comuunication ( if possible in some compressed format ).
Code As follows :
Option Explicit

'flow control variables. Strings for now. Integers taking enumerated constants would be better
'Const phSending = 0
'Const phReceiving = 1

Dim Phase As String
Dim Stage As String

Dim ReceiveBuffer As String
Const ReceivingInterval = 100

Private Sub Command1_Click()
    Dim strBuffer As String
    Dim i As Integer
    MSComm1.Settings = "56000,N,8,1"
    MSComm1.CommPort = 2
    MSComm1.InputLen = 0 'Default anyway
    MSComm1.RThreshold = 1 'Fire OnComm event with a single character in input buffer
    MSComm1.PortOpen = True
    Transact "ATE0", 500  'command to tell the modem not to echo the "AT" back
    Stage = "Initialising Modem"

End Sub

Sub Transact(SendText As String, TimeOut As Integer)
    WriteLog "Sending: " & SendText
    Timer1.Interval = TimeOut 'milliseconds
    ReceiveBuffer = ""
    MSComm1.Output = SendText & vbCr
    Timer1.Enabled = True
    Phase = "Sending"

End Sub

Private Sub Timer1_Timer()
    Dim strBuffer As String
    WriteLog "Timer: Interval: " & Timer1.Interval & " Stage: " & Stage & " Phase: " & Phase
    Select Case Phase
        Case "Sending"
            WriteLog "Nothing Received"
        Case "Receiving"
            strBuffer = TrimBoth(ReceiveBuffer)
            WriteLog "Received: " & strBuffer

            Select Case Stage
                Case "Initialising Modem"
                    If Right$(strBuffer, 2) = "OK" Then
                        Transact "ATS0=2", 300 ' Set Modem S0 register to 2 (Answer on two rings)
                        Stage = "Setting S Reg"
                        Phase = "Sending"
                        WriteLog "Modem not responding"
                    End If
                Case "Setting S Reg"
                    Select Case Left$(strBuffer, 2)
                        Case "OK"
                          Stage = "Listening"
                          Phase = "Receiving"
                            Listen 300

                        Case Else
                              'some sort of error
                    End Select
                Case "Listening"
                    Select Case strBuffer
                        Case "OK"
                        Case "RING"
                            WriteLog "Incoming call"
                        Case "CONNECT" 'The connect message may have some protocol information appended.
                            WriteLog "Connected"
                    End Select
            End Select
    End Select
    Timer1.Enabled = False
End Sub

Function TrimRight(Intext As String) As String
    'strip blanks, tabs, line feeds etc from end of string
    Dim Text As String
    Text = Intext
    If Len(Intext) > 0 Then
        Do While Asc(Right$(Text, 1)) <= 32
            Text = Left$(Text, Len(Text) - 1)
        TrimRight = Text
    End If
End Function

Private Sub MSComm1_OnComm()
WriteLog "OnComm: " & MSComm1.CommEvent
    Select Case MSComm1.CommEvent
        Case comEvSend '1 Send event.
        Case comEvReceive '2 Receive event.
            Phase = "Receiving"
            ReceiveBuffer = ReceiveBuffer & MSComm1.Input
            WriteLog "ReceiveBuffer: " & ReceiveBuffer
            Timer1.Enabled = False
            Timer1.Interval = ReceivingInterval
            Timer1.Enabled = True
        Case comEvCTS '3 Change in clear-to-send line.
        Case comEvDSR '4 Change in data-set ready line.
        Case comEvCD '5 Change in carrier detect line.
        Case comEvRing '6 Ring detect.
        Case comEvEOF '7 End of file.
        Case comEventBreak '1001 A Break signal was received.
        Case comEventFrame '1004 Framing Error. The hardware detected a framing error.
        Case comEventOverrun '1006 Port Overrun. A character was not read from the hardware before the next character arrived and was lost.
        Case comEventRxOver '1008 Receive Buffer Overflow. There is no room in the receive buffer.
        Case comEventRxParity '1009 Parity Error. The hardware detected a parity error.
        Case comEventTxFull '1010 Transmit Buffer Full. The transmit buffer was full while trying to queue a character.
        Case comEventDCB '1011 Unexpected error retrieving Device Control Block (DCB) for the port.
    End Select
End Sub

Function TrimLeft(Intext As String) As String
    Dim Text As String
    If Len(Intext) > 0 Then
    Text = Intext
    Do While Asc(Text) <= 32
        Text = Mid$(Text, 2)
    TrimLeft = Text
    End If
End Function

Function TrimBoth(Intext As String) As String
    TrimBoth = TrimLeft(TrimRight(Intext))
End Function

Sub WriteLog(Text As String)
    'This could be modified to write to a log file
    Dim strBuffer As String
    strBuffer = TrimBoth(Text)
    If Len(strBuffer) > 0 Then
        Debug.Print Now & " " & strBuffer
    End If
End Sub
Sub Listen(TimeOut As Integer)
    WriteLog "Listening: " & TimeOut & " millisecs"
    Timer1.Interval = TimeOut 'milliseconds
    ReceiveBuffer = ""
    Timer1.Enabled = True
    Phase = "Receiving"

End Sub

Sunday, May 2, 2004

Do you want us to send that to Bangalore?

Sunday, May 2, 2004

look at this site:

Sunday, May 2, 2004

Thanx someOne, it was really useful, no not in india(for No Name).

Monday, May 3, 2004

is anybody can help me to regarding following problem
i m making an application for my company
in which i have to record machine run & stop time
there are 2 conditions i.e i have 2 check boxes
one is for machine run
second is for ok for run
both signals are comming from m/c to pc thru com port
i got both signals now ,
my proble is that i want a logic to record a time in msflexgrid
if m/c run is =ok
job clamped= ok
then the ligic should come in picture
and when m/c run signal off then stop time should record in flexgrid in 1st row
& when again m/c run signal appears start ime should record in 1st row in 2nd col & time differance should come in 1st row in 3rd col
again if he same activity happens then the same logic but in 2nd row,
and when both signals disappears i.e now the job is completed then the whole data to transfer to excel file in columnwise format.
and again ready for next job.
Awaiting for ur helping hand.

Friday, May 14, 2004

*  Recent Topics

*  Fog Creek Home