0
Beantwoord

Displaying text feedback from an HTTP request

Iain Brew 8 jaar geleden in iRidium Script bijgewerkt 8 jaar geleden 9

I have a Matrox Monarch HD recording device which uses HTTP commands for operation. It can also provide feedback, however I am not having much luck at getting this feedback to display on a text item on a page. I tried putting the commands in the 'feedback' section of the driver, however discovered the will not work for HTTP Custom, only JS methods will.


The syntax for sending a command is as follows:


/Monarch/syncconnect/sdk.aspx?command=<command>


This works fine for starting and stopping recordings, however I really would like to show feedback on my control panel to give my end users confidence that recordings are actually happening, or alert them if there is an issue.


/Monarch/syncconnect/sdk.aspx?command=GetStatus


will return:


RECORD: READY/ON, STREAM: DISABLED, NAME:DIS-REC-1


I want to be able to have the 'RECORD: READY/ON' section displayed as text on a page, with the remainder of the string hidden.


In addition, when you start a recording:

/Monarch/syncconnect/sdk.aspx?command=StartRecording


it will return:


SUCCESS/FAILED



Could someone advise the JS code to make this work, as I am able to read code but not write it.


Thank you!


Beantwoord

pls try this

http_request_parse.irpz


IR.AddListener(IR.EVENT_START, 0, function()
{
   // create HTTP device
   IR.CreateDevice(IR.DEVICE_CUSTOM_HTTP_TCP, "Monarch", "192.168.0.66", 123);
   // send requests on client Start
   sendRequests();            
});


function sendRequests() 
{
   // request 1
   // answer: SUCCESS
   IR.GetDevice("Monarch").SendEx({ 
         Type: "GET",                                                                    
         Url:  "/Monarch/syncconnect/sdk.aspx?command=StartRecording",
         Headers: {},       
         cbReceiveText:       function(text, code, headers)  
         {
            IR.GetPage("Page 1").GetItem("Item 1").Text = text;              
         },
   });
   
   // request 2
   // answer: RECORD: READY, STREAM: DISABLED, NAME:DIS-REC-1
   IR.GetDevice("Monarch").SendEx({ 
         Type: "GET",                                                                    
         Url:  "/Monarch/syncconnect/sdk.aspx?command=GetStatus",
         Headers: {},       
         cbReceiveText:       function(text, code, headers)  
         {
            var params = text.split(",");
            for (i = 0; i < params.length; i++)
            {
               var state = params[i].split(":");
               IR.Log(params[i]);
               switch(state[0])
               {
               case "RECORD":
                  IR.GetPage("Page 1").GetItem("Item 2").Text =  state[1];
               break;
               case " STREAM":
                  IR.GetPage("Page 1").GetItem("Item 3").Text =  state[1];
               break;
               case " NAME":
                  IR.GetPage("Page 1").GetItem("Item 4").Text =  state[1];
               break;
               }
            }
         }
   });
}

Hello

I am having luck with this code! What's the best way to have it automatically 'read' the device when I enter a page? Should I add it to a button, or will it be automatically called by iRidium?

It is better to use the listener of page opening, like this:


IR.AddListener(IR.EVENT_START, 0, function()
{
   // cerate driver            
})

IR.AddListener(IR.EVENT_ITEM_SHOW, IR.GetPage("Page 1"), function()
{
   // send request of equipment state when open Page 1        
});

IR.AddListener(IR.EVENT_ITEM_SHOW, IR.GetPage("Page 2"), function()
{
   // send request of equipment state when open Page 2        
});

Thanks, so my code should look like this (i.e. when I enter the page, it will automatically read/request the state from the device)


// Code to read record status of DIS-REC-1 and display on Home page


IR.AddListener(IR.EVENT_START, 0, function()


{
// DIS-REC1 is the name of the TCP HTTP device in the project
IR.GetDevice("DIS-REC1");
   sendRequests();            
});


IR.AddListener(IR.EVENT_ITEM_SHOW, IR.GetPage("Home"), function()
{
// send request of equipment when 'Home' page is opened    
})


function sendRequests() 
{
   // request 1
   // answers: SUCCESS, FAILED
   IR.GetDevice("DIS-REC1").SendEx({ 
         Type: "GET",                                                         
                    Url:  "/Monarch/syncconnect/sdk.aspx?command=StartRecording",
         Headers: {},       
         cbReceiveText:       function(text, code, headers)  
         {
            IR.GetPage("Home").GetItem("DIS-REC-1_Status").Text =  state[1];              
         },
   });
     
}

http_request_parse.irpz


//------ create HTTP device on Project start
IR.AddListener(IR.EVENT_START, 0, function()
{
   IR.CreateDevice(IR.DEVICE_CUSTOM_HTTP_TCP, "DIS-REC", "192.168.0.66", 80);        
});

//------ send command on Item Press
IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetPage("Page 1").GetItem("Item 9"),function()
{
   // command=StartRecording
   // answer: SUCCESS / FAILED
   IR.GetDevice("DIS-REC").SendEx({ 
         Type: "GET",                                                                    
         Url:  "/Monarch/syncconnect/sdk.aspx?command=StartRecording",
         Headers: {},       
         cbReceiveText:       function(text, code, headers)  
         {
            IR.GetPage("Page 1").GetItem("Item 1").Text = text;              
         },
   });
}); 

//------ send command on Popup Show
IR.AddListener(IR.EVENT_ITEM_SHOW, IR.GetPage("Popup 1"), function()
{ 
   // command=GetStatus
   // answer: RECORD: READY, STREAM: DISABLED, NAME:DIS-REC-1
   IR.GetDevice("DIS-REC").SendEx({ 
         Type: "GET",                                                                    
         Url:  "/Monarch/syncconnect/sdk.aspx?command=GetStatus",
         Headers: {},       
         cbReceiveText:       function(text, code, headers)  
         {
            var params = text.split(",");
            for (i = 0; i < params.length; i++)
            {
               var state = params[i].split(":");
               //IR.Log(params[i]);
               
               var param_name = state[0].replace(/\s/g,"");         
               switch(param_name)
               {
                  case "RECORD":
                     IR.GetPage("Page 1").GetItem("Item 2").Text =  state[1];
                  break;
                  case "STREAM":
                     IR.GetPage("Page 1").GetItem("Item 3").Text =  state[1];
                  break;
                  case "NAME":
                     IR.GetPage("Page 1").GetItem("Item 4").Text =  state[1];
                  break;
               }
            }
         }
   });
});

Thank you! Will give that a go. I am not very good at coding, but can read it.

Thank you for the responses - I did have it briefly working yesterday (I am not sure how) but it's refusing to work for me today. Could I send you my project file - maybe this will be easier as I already have the driver and text items set up?

Hi, on the forum we can share the code fragments that could be useful for all of us, but if we just write a specified code instead of you it will take really much time, support team cannot do it, sorry.


If you post the project here we or somebody from community will try to help. Or maybe it is better to contact one of certified specialists.


+1

Thank you for the response. I am working with JamWare to resolve this issue.