Jump to content

Can not receive with TCPReceive


KF5WGB
 Share

Recommended Posts

Hi everybody,

I want to use AutoIt send commands to a HAM logging program which after it receives the <CMD>, responds with a string embedded in <CMD> tags.

The TCPSend does work and I know the Logging program responds with an answer. I have Putty running in the background listening to the same port and I can see

what comes back. What am I missing? code below.

Thanks in advance

73,

KF5WGB -Ralf-

 

 

#include <MsgBoxConstants.au3>

Getresponse()
Local $sReceived
MsgBox($MB_SYSTEMMODAL, "", "Received: " & $sReceived,5); Should show what ACLog sends back... but empty

Func Getresponse()
    TCPStartup() ; Start the TCP service.

    ; Register OnAutoItExit to be called when the script is closed.
    OnAutoItExitRegister("OnAutoItExit")

    ; Assign Local variables the loopback IP Address and the Port.
    Local $sIPAddress = "127.0.0.1"
    Local $iPort = 1180 ; Port used for the connection.
    Local $iSocket = TCPConnect($sIPAddress, $iPort)

   If @error Then
        ; Someone is probably already listening on this IP Address and Port (script already running?).
        Local $iError = @error
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not listen, Error code: " & $iError)
        Return False
     Else
        TCPSend($iSocket,"<CMD><READBMF></CMD>"    );Send to ACLog (HAM logging program) requesting Band, Mode and Frequency

    EndIf


       $sReceived = TCPRecv($iSocket,50)   ; does not receive anything from ACLog

     TCPCloseSocket($iSocket)
   EndFunc

Func OnAutoItExit()
    TCPShutdown() ; Close the TCP service.
EndFunc   ;==>OnAutoItExit

 

Link to comment
Share on other sites

3 hours ago, AutoBert said:

Move Lpcal $sReceived before Getresponse() and declare it Global.

AutoBert,

Moved it and declared it Global. Now I get the response into $sReceived the first time I run the script.

Calling it the 2nd time leaves $sReceived empty again. Closing the App I want to pull responses from and restarting it does not work.

$sReceived stays empty. Monitoring traffic with MobaXterm shows that the script sends the command and the response comes back.

Fun part: Restarting the PC lets gets the data written to $sReceived 1 time and 1 time only :-(

I also put  TCPShutdown() before EndFunc,  to close the TCPService. I thought maybe it has to be closed before the next  TCPConnect command.

Also did not fix the problem.

What I want to do is to listen in the background to the localhost, port 1180 for a specific string. Once ENTER is hit in the "monitored" program, a string like the following is send:

<CMD><ENTEREVENT><QSOCOUNT>765</QSOCOUNT><CALL>LA9A</CALL><BAND>10</BAND><MODE>CW</MODE><MODETEST>CW</MODETEST><COUNTRY>Norway</COUNTRY><DXCC>266</DXCC><CONT>EU</CONT><QSO_DATE>20160810</QSO_DATE><TIME_ON>144300</TIME_ON></CMD>

Once that string is received, the script does some magic and stores the call, band,date and time out of the string in separate variables and uploads the contact to QRZ.com, a HAM online Logging service.

So far I can not get that string into $sReceived more than once. Maybe I want to do something that AutoIt can not do.

Any ideas?

Thanks for any help.

73,

KF5WGB -Ralf-

Link to comment
Share on other sites

Hold your horses,

Just restarted PC and wanted to see if I can reproduce the same thing. Not this time. I am now back to square one. $sReceived is not getting data. String stays empty no matter if I do a restart or use TCPShutdown().

KF5WGB - Ralf -

 

Link to comment
Share on other sites

Test with this script:

#include <MsgBoxConstants.au3>

TCPStartup() ; Start the TCP service.

; Register OnAutoItExit to be called when the script is closed.
OnAutoItExitRegister("OnAutoItExit")

Global $sWaitingFor = '<CMD><ENTEREVENT><QSOCOUNT>'

Do
    $sReceived = Getresponse()
Until StringLeft($sReceived, 27) = $sWaitingFor

MsgBox($MB_SYSTEMMODAL, "", "Received: " & $sReceived, 5); Should show what ACLog sends back... but empty

Func Getresponse()

    ; Assign Local variables the loopback IP Address and the Port.
    Local $sIPAddress = "127.0.0.1"
    Local $iPort = 1180 ; Port used for the connection.
    Local $iSocket = TCPConnect($sIPAddress, $iPort)

    If @error Then
        ; Someone is probably already listening on this IP Address and Port (script already running?).
        Local $iError = @error
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not listen, Error code: " & $iError)
        Return False
    Else
        TCPSend($iSocket, "<CMD><READBMF></CMD>");Send to ACLog (HAM logging program) requesting Band, Mode and Frequency
    EndIf


    $sReceived = TCPRecv($iSocket, 50) ; does not receive anything from ACLog

    TCPCloseSocket($iSocket)
    Return $sReceived
EndFunc   ;==>Getresponse

Func OnAutoItExit()
    TCPShutdown() ; Close the TCP service.
EndFunc   ;==>OnAutoItExit

May be you must adjust line 8 and 12 for your needs.

Link to comment
Share on other sites

Hi Autobert,

Modified the script (the Do -- Until) and got a response 1 time...again. It drove me nuts. I then started two Telnet clients, one listening to the App (server), one to the AutoIt script. Found out that AutoIt 'hammers' the server with the TCPSend's. In the Telnet client I saw 15 to 20 responses before the AutoIt script caught the info.

Once I took out the TCPSend command and used the Telnet client to talk to the Server, it worked perfectly. The script now waits for the 'WaitingFor' string and once received brings up the Msgbox. Now the fun stuff begins. I have to cut up the string and put it back together in the QRZ Web-Service accepted  lingo and upload it.

Not sure what command I can use in AutoIt to upload to a website. Found the download InetGet command. I guess that should work for upload also.

Anyway, thanks a lot for you patience and help

73

KF5WGB - Ralf -

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...