Facility Control

 View Only
  • 1.  TCP communication

    Posted 11-18-2023 20:51

    Hi all,

    I'm stuck on a TCP response problem. I can send a TCP message to a server, which sends back a string, but I can't see it in dashboard (in bitfocus companion, I receive it correctly).
    Program:
     
    function callback(success, sentData, resultString, exception)
    {
        ogscript.debug("success: " + success);
        ogscript.debug("sentData: " + sentData);
        ogscript.debug("resultString: " + resultString);
        ogscript.debug("exception: " + exception);
    }
    rosstalk.sendMessageWithResponse(params.getValue("address",0), params.getValue("port",0), params.getValue("StringToSend",0), '', callback);
     
    The debug response:
    02:37:22:188: success: true
     
    02:37:22:191: sentData: CHECK_STATUS
     
    02:37:22:193: resultString: null
     
    02:37:22:194: exception: null
     
     
    If you can help me, thank you very much!
     
    Sylvain


    ------------------------------
    Sylvain Menet
    Technical Manager
    Dreamwall
    ------------------------------


  • 2.  RE: TCP communication

    Posted 11-20-2023 11:56

    Hi Sylvain

    You need to specify a response terminator for the reply message. Since you are just using an empty string, the ogScript is not waiting for a response since it does not have anything to match on.  If the response is terminated by a carriage return or line feed, you'll want to specify it in your call.

    Cheers

    James



    ------------------------------
    James Peltzer
    Ross Video
    ------------------------------



  • 3.  RE: TCP communication

    Posted 11-20-2023 16:52

    Hi James,

    I put a return carriage inside my message:

    rosstalk.sendMessageWithResponse("127.0.0.1", 12345, "CHECK_STATUS", "\n", callback);

    But now, have a got a timed out answer inside dashboard debugger.
    I'm sure that the server send me a response with a return carriage. Can you know whats happen?

    Thx a lot



    ------------------------------
    Sylvain Menet
    Technical Manager
    Dreamwall
    ------------------------------



  • 4.  RE: TCP communication

    Posted 11-21-2023 10:40

    There is a DashBoard quirk where it has a different behavior with sendMessage vs. sendMessageWithResponse: when sendMessage is used, DashBoard will automatically append a carriage return and linefeed to the outgoing message (if one is not already present). When sendMessageWithResponse is used, the carriage return and linefeed are not automatic (you would need to send 'CHECK_STATUS\n'  to add the linefeed). If your server is expecting the incoming message to be terminated this way, it would likely trigger a timeout on the response.

    See this panel for an example:

    <abs contexttype="opengear" gridsize="20" keepalive="true">
       <meta>
          <listener autostart="true" delimitertype="newline" listenport="2468">
             <task tasktype="ogscript">if (event.isMessageEvent())
    {
       ogscript.debug(event.getBytesAsString());
       this.writeString('DONE\n', false);
    }</task>
          </listener>
       </meta>
       <button buttontype="push" height="120" left="80" name="Send with Linefeed" top="120" width="240">
          <task tasktype="ogscript">function callback(success, sentData, resultString, exception)
    {
        ogscript.debug("success: " + success);
        ogscript.debug("sentData: " + sentData);
        ogscript.debug("resultString: " + resultString);
        ogscript.debug("exception: " + exception);
    }
    rosstalk.sendMessageWithResponse('localhost', 2468, 'TESTING\n', '\n', callback);</task>
       </button>
       <button buttontype="push" height="120" left="340" name="Send without Linefeed" top="120" width="240">
          <task tasktype="ogscript">function callback(success, sentData, resultString, exception)
    {
        ogscript.debug("success: " + success);
        ogscript.debug("sentData: " + sentData);
        ogscript.debug("resultString: " + resultString);
        ogscript.debug("exception: " + exception);
    }
    rosstalk.sendMessageWithResponse('localhost', 2468, 'TESTING', '\n', callback);</task>
       </button>
    </abs>
    


    ------------------------------
    James Peltzer
    Ross Video
    ------------------------------



  • 5.  RE: TCP communication

    Posted 11-23-2023 18:36

    Thx a lot James.It works! 

    Best



    ------------------------------
    Sylvain Menet
    Technical Manager
    Dreamwall
    ------------------------------