Page 1 of 1

tcp receiving parameters

PostPosted: Sat Nov 27, 2021 8:56 pm
by satanete666
Hi,

I would like to do an aplication that i can send questions for a videoprojector for example to know wich in put is selected and wait the answer for this side and save in a variable, my problem is that i want to do a script that i want to send to many questions and i would like to be sure what answer is related to waht question , is any way to do like a function that will be wainting until it recive the answer?

Regards

Re: tcp receiving parameters

PostPosted: Wed Dec 01, 2021 3:28 pm
by Martina Protze
Hello,
btw, some projector include in their answer, what it relates to, e.g. if the message starts with "input" you could filter that keyword and allocate the rest to the according "input"-variable.
But I guess your projectors don't do that as you ask for sth that sends a message, waits for an answer and only if that answer is received, THEN a second message is sent out. There are multiple approaches to that. You could for example write each question and logic for the answer to a separate "Function" and call them with an extra script. Functions are called one by another and not simultaneously like Macros. Of course you could also make one general Function which you call by passing in the question and with the "Switch" statement that includes "Cases" the output variable is filled. Another approach would be using a "For loop" with a "Break" statement, meaning a very long for loop which stops with the "break" statement (when a new answer is received).

Manual: Switch
Manual: For Loop / Break
Manual: Functions

Hope that helps :)

Re: tcp receiving parameters

PostPosted: Wed Dec 08, 2021 10:58 pm
by satanete666
Thank you Martina,

But that i want to know if is any command like "on_data_arrival" or something similar to build a function that it will be waiting to the data and after that return the string that i need.

Re: tcp receiving parameters

PostPosted: Mon Dec 13, 2021 5:40 pm
by justyn roy
I usually have a TCP Client to connect to the projector, this sends and receives requests.
Then you use an Event Listener to listen to those responses from the projectors.

Then in the Event Listener, you'd send the projectors' responses to a function to do the work.
Because you need 1 Event Listener per projector/TCP Client, you can add an "ID" to each Event Listener, for example:

Code: Select all
YourProjectorFunction("Projector1", MessageReceived)


Then inside of that function, you'd use the functionality that Martina suggested, this is a generic example as I don't know what the responses from your projectors look like. I'm going to assume that it's PJ Link and this is the example for a shutter.

Code: Select all
//Set the variables from the parameters passed to the function
//One is the message from the projector
//One is the Projector's ID
var thisMessage = MessageReceived.ToString
var thisProjector = ID.ToString

//PJ Link returns a string like: "%1AVMT=30" - we need the value after the "=" sign.
//we use the ".Split" command to make this an 'array' or a 'list' of values using the "=" sign as the known symbol to switch from:
var projReturn = thisMessage.Split("=")

//this variable would look like: ["%1AVMT", 30]
//projReturn[0] is "%1AVMT"
//projReturn[1] is "30"

//Now - we're looking at the whole projector return - does it have AVMT in it? IF it does, we know it's the shutter!
if thisMessage.Contains("AVMT") {
   DebugMessage("This is a shutter message!")
   //What is the value of the message that we split?
   if projReturn[1] = 30 {
      //Shutter is open!
      DebugMessage(thisProjector, "Shutter OPEN!")
   } else {
      //Shutter is Closed!
      DebugMessage(thisProjector, "Shutter CLOSED!")
   }
}


I know this is a lot!
Please let me know if I can clarify this anymore!