Jump to content

ECAPI -- can autoit do ECAPI?


Recommended Posts

That would be easier to answer if we knew what ECAPI is. Google gives nothing, and this thread is one of the top results so...

;)

I dont know much about it -- waiting on info from the recording company -- but from what I can tell it is a super simple network messaging sort of thing.

The current tool we have** seems to just send a command like "START (1:1)" or "START (1:12)" or "STOP (1:1)" to port 1503 on the recording server. where 1:1 = <card#>:<port#>

There is a tool on the recording server called ECAPI hub where I can see the commands scroll as buttons are pressed on the existing tool. (See attached screen shot)

Is there a way I could just send a string like "START (1:1)" to a certain port at a certain IP, in autoit -- so I can just test to see if it works?

also -- there is this wikipedia article

http://en.wikipedia.org/wiki/User:X!/ECAPI

**(that needs to be replaced because of config changes, and the orignal creater is long gone, which I why I need to make one frmo scratch)

post-24456-12828598180154_thumb.png

Edited by bdb4269
Link to comment
Share on other sites

The current tool we have** seems to just send a command like "START (1:1)" or "START (1:12)" or "STOP (1:1)" to port 1503 on the recording server. where 1:1 = <card#>:<port#>

If it's really that simple, maybe something like this? (replace $vServerIP with the server's IP/name)

; Set Some reusable info
;--------------------------
Local $ConnectedSocket, $szData
Local $vServerIP = @IPAddress1
Local $nPORT = 1503

; Start The TCP Services
;==============================================
TCPStartup()

; Initialize a variable to represent a connection
;==============================================
$ConnectedSocket = -1

;Attempt to connect to SERVER at its IP and PORT 1503
;=======================================================
$ConnectedSocket = TCPConnect($vServerIP, $nPORT)

; If there is an error... show it
If @error Then
    MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)
Else

        TCPSend($ConnectedSocket, "START (1:1)")
EndIf
Link to comment
Share on other sites

Your suggestion worked! (I just had to add CRLF which I found out was required)

I expanded on it, and have gui to allow our supervisors to start and stop recording on 24 ports.

I have never used autoit for TCP connections.

Below is my code -- if you have time to give it a once over and let me know if anything looks hinky, that would be awesome!

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Dim $Checkbox[50]
Dim $Map[50]
$Map[1] = 70
$Map[2] = 71
$Map[3] = 72
$Map[4] = 100
$Map[5] = 101
$Map[6] = 102
$Map[7] = 93
$Map[8] = 92
$Map[9] = 91
$Map[10] = 124
$Map[11] = 125
$Map[12] = 126
$Map[13] = 3
$Map[14] = 4
$Map[15] = 5
$Map[16] = 28
$Map[17] = 27
$Map[18] = 26
$Map[19] = 40
$Map[20] = 39
$Map[21] = 38
$Map[22] = 61
$Map[23] = 62
$Map[24] = 63

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\bbeetle\My Documents\Form1.kxf
$Form1 = GUICreate("Wygant Start/Stop Tool", 250, 400, 354, 124)


$Checkbox[1] = GUICtrlCreateCheckbox("Port " & $Map[1], 20, 20, 100, 20)
$Checkbox[2] = GUICtrlCreateCheckbox("Port " & $Map[2], 20, 50, 100, 20)
$Checkbox[3] = GUICtrlCreateCheckbox("Port " & $Map[3], 20, 80, 100, 20)
$Checkbox[4] = GUICtrlCreateCheckbox("Port " & $Map[4], 20, 110, 100, 20)
$Checkbox[5] = GUICtrlCreateCheckbox("Port " & $Map[5], 20, 140, 100, 20)
$Checkbox[6] = GUICtrlCreateCheckbox("Port " & $Map[6], 20, 170, 100, 20)
$Checkbox[7] = GUICtrlCreateCheckbox("Port " & $Map[7], 20, 200, 100, 20)
$Checkbox[8] = GUICtrlCreateCheckbox("Port " & $Map[8], 20, 230, 100, 20)
$Checkbox[9] = GUICtrlCreateCheckbox("Port " & $Map[9], 20, 260, 100, 20)
$Checkbox[10] = GUICtrlCreateCheckbox("Port " & $Map[10], 20, 290, 100, 20)
$Checkbox[11] = GUICtrlCreateCheckbox("Port " & $Map[11], 20, 320, 100, 20)
$Checkbox[12] = GUICtrlCreateCheckbox("Port " & $Map[12], 20, 350, 100, 20)

$Checkbox[13] = GUICtrlCreateCheckbox("Port " & $Map[13], 150, 20, 100, 20)
$Checkbox[14] = GUICtrlCreateCheckbox("Port " & $Map[14], 150, 50, 100, 20)
$Checkbox[15] = GUICtrlCreateCheckbox("Port " & $Map[15], 150, 80, 100, 20)
$Checkbox[16] = GUICtrlCreateCheckbox("Port " & $Map[16], 150, 110, 100, 20)
$Checkbox[17] = GUICtrlCreateCheckbox("Port " & $Map[17], 150, 140, 100, 20)
$Checkbox[18] = GUICtrlCreateCheckbox("Port " & $Map[18], 150, 170, 100, 20)
$Checkbox[19] = GUICtrlCreateCheckbox("Port " & $Map[19], 150, 200, 100, 20)
$Checkbox[20] = GUICtrlCreateCheckbox("Port " & $Map[20], 150, 230, 100, 20)
$Checkbox[21] = GUICtrlCreateCheckbox("Port " & $Map[21], 150, 260, 100, 20)
$Checkbox[22] = GUICtrlCreateCheckbox("Port " & $Map[22], 150, 290, 100, 20)
$Checkbox[23] = GUICtrlCreateCheckbox("Port " & $Map[23], 150, 320, 100, 20)
$Checkbox[24] = GUICtrlCreateCheckbox("Port " & $Map[24], 150, 350, 100, 20)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


;--------------------------
Local $ConnectedSocket, $szData
Local $vServerIP = "192.168.1.11"
Local $nPORT = 1503

; Start The TCP Services
;==============================================
TCPStartup()

; Initialize a variable to represent a connection
;==============================================
$ConnectedSocket = -1

;Attempt to connect to SERVER at its IP and PORT 1503
;=======================================================
$ConnectedSocket = TCPConnect($vServerIP, $nPORT)


If @error Then
    MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)
    Exit
EndIf








While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    For $i=1 to 48
        if $nMsg = $Checkbox[$i] Then
            StartStop($i)
        EndIf
    Next

WEnd



Func StartStop($port)

If GUICtrlRead($Checkbox[$port]) = $GUI_CHECKED Then
    TCPSend($ConnectedSocket, "START (1:" & $port & ")" & @CRLF)
    While 1
        $response = TCPRecv($ConnectedSocket,100)
        If $response <> "" Then ExitLoop
    WEnd
    If StringRegExp($response,"ERR609") Then
        MsgBox(48,"ERROR", "Port " & $Map[$port] & " was already recording!")
    ElseIf Not(StringRegExp($response,"OK")) Then
        MsgBox(48,"ERROR", "There was some error starting Port " & $Map[$port] & "!  Error message below:" & @CR  & @CR  & $response)
        GUICtrlSetState($Checkbox[$port],$GUI_UNCHECKED)
    Else
        MsgBox(0,"OK", "Port " & $Map[$port] & " started OK")
    EndIf
;~  MsgBox(0,"debug",$response)

ElseIf GUICtrlRead($Checkbox[$port]) = $GUI_UNCHECKED Then
    TCPSend($ConnectedSocket, "STOP (1:" & $port & ")" & @CRLF)
    While 1
        $response = TCPRecv($ConnectedSocket,100)
        If $response <> "" Then ExitLoop
    WEnd
    If StringRegExp($response,"ERR608") Then
        MsgBox(48,"ERROR", "Port " & $Map[$port] & " was already not recording!")
    ElseIf Not(StringRegExp($response,"OK")) Then
        MsgBox(48,"ERROR", "There was some error stoping Port " & $Map[$port] & "!  Error message below:" & @CR  & @CR  & $response)
;~      GUICtrlSetState($Checkbox[$port],$GUI_CHECKED)  ;I figure if there is an error -- better to just leave this unchecked so no chance that supe's dont think it is recording, when it might not be
    Else
        MsgBox(0,"OK", "Port " & $Map[$port] & " stopped OK")
    EndIf
;~  MsgBox(0,"debug",$response)


EndIf

EndFunc
Link to comment
Share on other sites

Your suggestion worked! (I just had to add CRLF which I found out was required)

Good deal! Glad it was that simple. ;)

Here's kind of an initial clean-up of what you posted:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $ConnectedSocket
Global $vServerIP = "192.168.1.11"
Global $nPORT = 1503

Dim $Checkbox[50]
#region Declare $aMap Array
Dim $aMap[50]
$aMap[1] = 70
$aMap[2] = 71
$aMap[3] = 72
$aMap[4] = 100
$aMap[5] = 101
$aMap[6] = 102
$aMap[7] = 93
$aMap[8] = 92
$aMap[9] = 91
$aMap[10] = 124
$aMap[11] = 125
$aMap[12] = 126
$aMap[13] = 3
$aMap[14] = 4
$aMap[15] = 5
$aMap[16] = 28
$aMap[17] = 27
$aMap[18] = 26
$aMap[19] = 40
$aMap[20] = 39
$aMap[21] = 38
$aMap[22] = 61
$aMap[23] = 62
$aMap[24] = 63
#endregion

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\bbeetle\My Documents\Form1.kxf
$Form1 = GUICreate("Wygant Start/Stop Tool", 250, 400, 354, 124)

$vStartingY = 20
For $x = 1 to 12
    $Checkbox[$x] = GUICtrlCreateCheckbox("Port " & $aMap[$x], 20, $vStartingY, 100, 20)
    $Checkbox[$x+12] = GUICtrlCreateCheckbox("Port " & $aMap[$x+12], 150, $vStartingY, 100, 20)
    $vStartingY += 30
Next

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


;--------------------------
_Connect_To_Server()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            TCPShutdown()
            Exit
    EndSwitch
    For $i = 1 To UBound($Checkbox)-1
        If $nMsg = $Checkbox[$i] Then
            StartStop($i)
        EndIf
    Next

WEnd

Func _Connect_To_Server()
    ConsoleWrite('@@ (' & @ScriptLineNumber & ') :(' & @HOUR & ':' & @MIN & ':' & @SEC & ') _Connect_To_Server()' & @CR) ;### Function Trace
    ; Start The TCP Services
    ;==============================================
    TCPStartup()

    ; Initialize a variable to represent a connection
    ;==============================================
    $ConnectedSocket = -1

    ;Attempt to connect to SERVER at its IP and PORT 1503
    ;=======================================================
    $ConnectedSocket = TCPConnect($vServerIP, $nPORT)


    If @error Then
        MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)
        TCPShutdown()
        Exit
    EndIf
EndFunc

Func StartStop($vPort)
    ConsoleWrite('@@ (' & @ScriptLineNumber & ') :(' & @HOUR & ':' & @MIN & ':' & @SEC & ') StartStop() --> Port #' & $vPort & @CR) ;### Function Trace
    If GUICtrlRead($Checkbox[$vPort]) = $GUI_CHECKED Then
        TCPSend($ConnectedSocket, "START (1:" & $vPort & ")" & @CRLF)
        While 1
            $response = TCPRecv($ConnectedSocket, 100)
            If $response <> "" Then ExitLoop
        WEnd
        If StringRegExp($response, "ERR609") Then
            MsgBox(48, "ERROR", "Port " & $aMap[$vPort] & " was already recording!")
        ElseIf Not (StringRegExp($response, "OK")) Then
            MsgBox(48, "ERROR", "There was some error starting Port " & $aMap[$vPort] & "!  Error message below:" & @CR & @CR & $response)
            GUICtrlSetState($Checkbox[$vPort], $GUI_UNCHECKED)
        Else
            MsgBox(0, "OK", "Port " & $aMap[$vPort] & " started OK")
        EndIf
;~  MsgBox(0,"debug",$response)

    ElseIf GUICtrlRead($Checkbox[$vPort]) = $GUI_UNCHECKED Then
        TCPSend($ConnectedSocket, "STOP (1:" & $vPort & ")" & @CRLF)
        While 1
            $response = TCPRecv($ConnectedSocket, 100)
            If $response <> "" Then ExitLoop
        WEnd
        If StringRegExp($response, "ERR608") Then
            MsgBox(48, "ERROR", "Port " & $aMap[$vPort] & " was already not recording!")
        ElseIf Not (StringRegExp($response, "OK")) Then
            MsgBox(48, "ERROR", "There was some error stoping Port " & $aMap[$vPort] & "!  Error message below:" & @CR & @CR & $response)
;~      GUICtrlSetState($Checkbox[$vPort],$GUI_CHECKED)  ;I figure if there is an error -- better to just leave this unchecked so no chance that supe's dont think it is recording, when it might not be
        Else
            MsgBox(0, "OK", "Port " & $aMap[$vPort] & " stopped OK")
        EndIf
;~  MsgBox(0,"debug",$response)
    EndIf

EndFunc   ;==>StartStop

So when your tool starts, you want it to go through and stop recording on all of the ports? Because that's what it's doing currently... (Once the tool hits the While...Wend loop, it runs the StartStop function to check all of your controls, and if any of them is unchecked then it does some stuff, and it's doing that like once a second, which probably isn't ideal)

There's no command to just check to see if recording is already running is there? If there was I could see you using a ListView, then getting that info when the tool opened and letting them right-click to change it.

Edited by exodius
Link to comment
Share on other sites

This is awesome! Thanks much for this. I always like to see how other people do and organize stuff. I learn best that way!

One thing though. The tool currently does not stop recording on all ports when it starts up. (I know because I was testing this while they had ports already started, and those ports were never stopped)

My understanding is that the startstop function is only run if GUIGetMsg() returns the ControlID of one of the checkboxs, and that GUIGetMsg() only returns the ControlID of one of the checkboxs if it changed state.

Am I misunderstanding that?

Edited by bdb4269
Link to comment
Share on other sites

This is awesome! Thanks much for this. I always like to see how other people do and organize stuff. I learn best that way!

One thing though. The tool currently does not stop recording on all ports when it starts up. (I know because I was testing this while they had ports already started, and those ports were never stopped)

My understanding is that the startstop function is only run if GUIGetMsg() returns the ControlID of one of the checkboxs, and that GUIGetMsg() only returns the ControlID of one of the checkboxs if it changed state.

Am I misunderstanding that?

Well there are a few things I'm finding after a 2nd look at the code I posted for you:

1. You're right in your understanding of GuiGetMsg(), but the special properties of GuiGetMsg() don't keep it from executing the StartStop function repeatedly as part of that loop - it just was throttling down the CPU usage so it didn't bog your system down.

2. You were correct, it seems that the $GUI_Unchecked flag doesn't get set until after a checkbox has been checked once, so that's why it wasn't going through and stopping all recording ports when it loaded.

Which still left us with a StartStop function that was just executing over and over... Which I've largely solved by switching to OnEvent Mode and tracking whether or not the checkboxes are checked by expanding the Checkbox array.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GuiOnEventMode", 1)

Global $ConnectedSocket
Global $vServerIP = "192.168.1.11"
Global $nPORT = 1503

Dim $Checkbox[50][2]
#region Declare $aMap Array
Dim $aMap[50]
$aMap[1] = 70
$aMap[2] = 71
$aMap[3] = 72
$aMap[4] = 100
$aMap[5] = 101
$aMap[6] = 102
$aMap[7] = 93
$aMap[8] = 92
$aMap[9] = 91
$aMap[10] = 124
$aMap[11] = 125
$aMap[12] = 126
$aMap[13] = 3
$aMap[14] = 4
$aMap[15] = 5
$aMap[16] = 28
$aMap[17] = 27
$aMap[18] = 26
$aMap[19] = 40
$aMap[20] = 39
$aMap[21] = 38
$aMap[22] = 61
$aMap[23] = 62
$aMap[24] = 63
#endregion

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\bbeetle\My Documents\Form1.kxf
$Form1 = GUICreate("Wygant Start/Stop Tool", 250, 400, 354, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "_GUI_EVENT_CLOSE")

$vStartingY = 20
For $x = 1 to 12
    $Checkbox[$x][0] = GUICtrlCreateCheckbox("Port " & $aMap[$x], 20, $vStartingY, 100, 20)
    GUICtrlSetOnEvent(-1, "_StartStop_Handler")
    $Checkbox[$x][1] = $GUI_UNCHECKED
    $Checkbox[$x+12][0] = GUICtrlCreateCheckbox("Port " & $aMap[$x+12], 150, $vStartingY, 100, 20)
    GUICtrlSetOnEvent(-1, "_StartStop_Handler")
    $Checkbox[$x+12][1] = $GUI_UNCHECKED
    $vStartingY += 30
Next

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

_Connect_To_Server()

While 1

    Sleep (100)
WEnd

Func _Connect_To_Server()
    ConsoleWrite('@@ (' & @ScriptLineNumber & ') :(' & @HOUR & ':' & @MIN & ':' & @SEC & ') _Connect_To_Server()' & @CR) ;### Function Trace
    ; Start The TCP Services
    ;==============================================
    TCPStartup()

    ; Initialize a variable to represent a connection
    ;==============================================
    $ConnectedSocket = -1

    ;Attempt to connect to SERVER at its IP and PORT 1503
    ;=======================================================
    $ConnectedSocket = TCPConnect($vServerIP, $nPORT)


    If @error Then
        MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error)
        TCPShutdown()
        Exit
    EndIf
EndFunc

Func _GUI_EVENT_CLOSE()
    TCPShutdown()
    Exit
EndFunc

Func _StartStop_Handler()
    For $i = 1 To UBound($Checkbox)-1
        _StartStop($i)
    Next
EndFunc

Func _StartStop($vPort)
    ConsoleWrite('@@ (' & @ScriptLineNumber & ') :(' & @HOUR & ':' & @MIN & ':' & @SEC & ') StartStop() --> Port #' & $vPort & @CR) ;### Function Trace
    If GUICtrlRead($Checkbox[$vPort][0]) = $GUI_CHECKED And $Checkbox[$vPort][1] <> $GUI_CHECKED Then
        ConsoleWrite ("$Checkbox[" & $vPort & "] - $GUI_CHECKED" & @CRLF)
        TCPSend($ConnectedSocket, "START (1:" & $vPort & ")" & @CRLF)
        While 1
            $response = TCPRecv($ConnectedSocket, 100)
            If $response <> "" Then ExitLoop
        WEnd
        If StringRegExp($response, "ERR609") Then
            MsgBox(48, "ERROR", "Port " & $aMap[$vPort] & " was already recording!")
        ElseIf Not (StringRegExp($response, "OK")) Then
            MsgBox(48, "ERROR", "There was some error starting Port " & $aMap[$vPort] & "!  Error message below:" & @CR & @CR & $response)
            GUICtrlSetState($Checkbox[$vPort], $GUI_UNCHECKED)
        Else
            MsgBox(0, "OK", "Port " & $aMap[$vPort] & " started OK")
        EndIf

        $Checkbox[$vPort][1] = $GUI_CHECKED
;~  MsgBox(0,"debug",$response)

    ElseIf GUICtrlRead($Checkbox[$vPort][0]) = $GUI_UNCHECKED And $Checkbox[$vPort][1] <> $GUI_UNCHECKED Then
        ConsoleWrite ("$Checkbox[" & $vPort & "] - $GUI_UNCHECKED" & @CRLF)
        TCPSend($ConnectedSocket, "STOP (1:" & $vPort & ")" & @CRLF)
        While 1
            $response = TCPRecv($ConnectedSocket, 100)
            If $response <> "" Then ExitLoop
        WEnd
        If StringRegExp($response, "ERR608") Then
            MsgBox(48, "ERROR", "Port " & $aMap[$vPort] & " was already not recording!")
        ElseIf Not (StringRegExp($response, "OK")) Then
            MsgBox(48, "ERROR", "There was some error stoping Port " & $aMap[$vPort] & "!  Error message below:" & @CR & @CR & $response)
;~      GUICtrlSetState($Checkbox[$vPort],$GUI_CHECKED)  ;I figure if there is an error -- better to just leave this unchecked so no chance that supe's dont think it is recording, when it might not be
        Else
            MsgBox(0, "OK", "Port " & $aMap[$vPort] & " stopped OK")
        EndIf
        $Checkbox[$vPort][1] = $GUI_UNCHECKED
;~  MsgBox(0,"debug",$response)
    EndIf
EndFunc   ;==>StartStop

If you aren't already, I would suggest running this in SciTE first so you can see all of the Consolewrites that it does as you press the different checkboxes, should be enlightening.

Edited by exodius
Link to comment
Share on other sites

I see what you are talking about how the StartStop() keeps getting run.

I was trying to figure out why, and I figured that it is because when nothing is checked or unchecked $nMsg is equal to zero, and it was comparing $nMsg to array values that = 0. (because I have the array going up to 50, but only 1-24 have non-null values)

So i just changed this part, and it seems to be working fine now without executing the StartStop() unless something is checked or unchecked.

if ($nMsg = $Checkbox[$i]) And Not($nMsg = 0) Then
    StartStop($i)
EndIf
Edited by bdb4269
Link to comment
Share on other sites

I see what you are talking about how the StartStop() keeps getting run.

I was trying to figure out why, and I figured that it is because when nothing is checked or unchecked $nMsg is equal to zero, and it was comparing $nMsg to array values that = 0. (because I have the array going up to 50, but only 1-24 have non-null values)

So i just changed this part, and it seems to be working fine now without executing the StartStop() unless something is checked or unchecked.

if ($nMsg = $Checkbox[$i]) And Not($nMsg = 0) Then
    StartStop($i)
EndIf

Just so you know, this does the same thing as what you posted:

if $nMsg = $Checkbox[$i] And $nMsg <> 0 Then
    StartStop($i)
EndIf
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...