Facility Control

 View Only
  • 1.  Communication over TCP - Request and Response

    Posted 10-26-2015 15:03
    I'd like to use the Dashboard to communicate with other devices through TCP commands and receive responses. I'm having difficulty making this work, even though it appears all of the correct commands exist. I've tried both the ogscript commands (Send TCP String, Send TCP bytes, and Send TCP String with Response) and the rosstalk commands (Send Message, and Send Message With Response). These do send commands, but they do not allow the device to send a response. While looking at the forum, I found this post, and I subsequently built a listener, but had no luck. I must be missing something (hopefully basic). How should I set this up?


  • 2.  RE: Communication over TCP - Request and Response

    Posted 10-26-2015 15:59

    Hi Joshua.

    You can use a listener to send and receive a response but you might find another function called rosstalk.sendWithResponse helpful.

    Here is a demo panel that makes use of both sendWithResponse and also uses a listener tag. It should give you an idea of how both work. Just copy and paste into a new custom panel and give it a shot.

    `
    if (event.isMessageEvent())

    {

    var rec = event.getBytesAsString().trim();

    var response = '';

    for (var i = rec.length - 1; i >= 0; i--)

    {

    response += rec.charAt(i);

    }
    this.writeString('REVERSE: ' + response + 'n', false);

    }

    function callback(success, sentData, resultString, exception)

    {

    ogscript.rename('ResponseOutput', resultString);

    }

    rosstalk.sendMessageWithResponse('localhost', 12345, params.getValue('Message', 0) + 'n', 'n', callback);

    //rosstalk.sendMessageWithResponse('[host]', [port], '[data]', '[response terminator]', [callback function]);

    `

    #DashBoard


  • 3.  RE: Communication over TCP - Request and Response

    Posted 10-26-2015 16:00
    Note (due to issues with how our forum mangles code), the 'n' bits should actually be linefeed characters.

    #DashBoard


  • 4.  RE: Communication over TCP - Request and Response

    Posted 10-26-2015 17:59
    Nice to meet you James, and thanks for your help.

    This is good direction and I have set up this demo grid on my system. It probably isn't working as you intended, which makes me think I have some configuration / network issue. The code you gave me is executing correctly (I did replace the n bits with linefeed characters as you asked), but I am only getting the response: Read timed out.

    I did use debugging to determine that the listener event is being triggered (which gets me largely there), but the sendWithReponse callback is not being triggered correctly. Can you think of any network issues that would cause this? [This is all localhost communication, I am on an internal network, no firewall running, so I wouldn't expect network issues for this type of thing].

    Thanks

    #DashBoard


  • 5.  RE: Communication over TCP - Request and Response

    Posted 10-26-2015 18:04
    It sounds like the response terminator is never being reached.

    Is the listener task sending the linefeed in its response? You should have had to fix 3 missing linefeeds.

    #DashBoard


  • 6.  RE: Communication over TCP - Request and Response

    Posted 10-26-2015 18:16
    That did it. I missed the linefeed in the listener code. And thanks again.

    #DashBoard


  • 7.  RE: Communication over TCP - Request and Response

    Posted 10-26-2015 20:51
    Ok, I've implemented this to work for TCP communication, and the example I've been given works, but I'm still not getting the communication I want. The device I am communicating with usually responds using the same TCP socket built for sending. This means that I have no means of telling this device to send it's responses to another port (where my listener is).

    Earlier James mentioned that it is possible to send and receive responses using just the listener. This might be the method I need. Does anyone have some insight into how I might do that?

    Thanks!

    #DashBoard


  • 8.  RE: Communication over TCP - Request and Response

    Posted 10-27-2015 18:02
    With some help I figured out what I was doing wrong. I was not sending the correct type of character to my device to indicate the end of a request. Instead of using a linefeed character

    [Backslash]n

    I needed to use a

    [Backslash]0

    This worked for me. You have also already provided a good answer for the question I had about the listener. You can see how to send and receive with the same listener in this dashboard here.

    Thanks again

    #DashBoard