1

Can I put two libraries in one session?

Тема: Can I put two libraries in one session?

Hi,

I need to get the sensor unit and run a report, Can I put two libraries in one session?

Example:

var sess = wialon.core.Session.getInstance();
        sess.loadLibrary("resourceReports");
        sess.loadLibrary("unitSensors");

or some suggest, thanks.

2

Can I put two libraries in one session?

Re: Can I put two libraries in one session?

Denisse, of course You can.

Head of Wialon Local Department
Gurtam
3

Can I put two libraries in one session?

Re: Can I put two libraries in one session?

Thank you, but I have a problem because perhaps the proccess of execute the two libraries cause a collision because the first execute found the sensors and execute the report ok but, the second time only to get sensors or report its depend.

Is this is because threads in the process?

Add a code of example.


var res_flags = wialon.item.Item.dataFlag.base | wialon.item.Resource.dataFlag.reports;
    var unit_flags = wialon.item.Item.dataFlag.base | wialon.item.Unit.dataFlag.sensors | wialon.item.Unit.dataFlag.lastMessage;
        
        
        
        
        var sess = wialon.core.Session.getInstance(); // get instance of current Session
        sess.loadLibrary("resourceReports"); // load Icon Library
        //sess.loadLibrary("unitSensors");
        sess.updateDataFlags( // load items to current session
            [{
                type: "type", 
                data: "avl_resource", 
                flags:res_flags , 
                mode: 0
            }, // especificación del recurso
        {
                    type: "type", 
                    data: "avl_unit", 
                    flags: unit_flags, 
                    mode: 0
                }], // especificacion de unidades
                    
                function (code) { // updateDataFlags callback
                    if (code) { 
                        msg(wialon.core.Errors.getErrorText(code)); 
                        return; 
                    } // exit if error code
                    
/******************************************************************************************************************************/
                 
                var res = sess.getItems("avl_resource");
                if(!res || !res.length){
                    msg("Resources not found");
                    return;
                }
                
                for (var i = 0; i< res.length; i++) // construct Select object using found resources
                    $("#res").append("<option value='" + res[1].getId() + "'>" + res[1].getName() + "</option>");

        getTemplates(); // update report template list
            
        $("#res").change( getTemplates ); // bind action to select change
                
                 // get loaded 'avl_unit's items 
            var units = sess.getItems("avl_unit");
            if (!units || !units.length){ 
                    msg("Units not found"); 
                    return; 
                } // check if units found

            for (var i = 0; i< units.length; i++){ // construct Select object using found units
                var u = units[i]; // current unit in cycle
                // append option to select
                $("#units").append("<option value='"+ u.getId() +"'>"+ u.getName()+ "</option>");
            }
                        
                        //getSensors(); // get Sensors for currently selected unit
            // bind actions to selects 
            //$("#units").change( getSensors );
                        // getSensors(); // get Sensors for currently selected unit
            // bind actions to selects 
            //$("#units").change( getSensors ); 
            //$("#sensors").change( getSensorInfo );
            // bind action to select change event
            $("#units").change( getSelectedUnitInfo );
                
                
        }
    );
        var sess1 = wialon.core.Session.getInstance();
        sess1.loadLibrary("unitSensors");
        sess1.updateDataFlags(
                [//pecificación del recurso
        {
                    type: "type", 
                    data: "avl_unit", 
                    flags: unit_flags, 
                    mode: 0
                }], // especificacion de unidades
                    
                function (code) { // updateDataFlags callback
                    if (code) { 
                        msg(wialon.core.Errors.getErrorText(code)); 
                        return; 
                    } // exit if error code
                    
                    var units = sess1.getItems("avl_unit");
            if (!units || !units.length){ 
                    msg("Units not found"); 
                    return; 
                } // check if units found

            for (var i = 0; i< units.length; i++){ // construct Select object using found units
                var u = units[i]; // current unit in cycle
                // append option to select
                $("#units").append("<option value='"+ u.getId() +"'>"+ u.getName()+ "</option>");
            }
                        
                         getSensors(); // get Sensors for currently selected unit
            // bind actions to selects 
            $("#units").change( getSensors ); 
            
            // bind action to select change event
            //$("#units").change( getSelectedUnitInfo );
                
                
        }
            );
4

Can I put two libraries in one session?

Re: Can I put two libraries in one session?

Denisse, look at this playground example with corrected code:

https://sdk.wialon.com/playground/1ySsARS7
Head of Wialon Local Department
Gurtam
5

Can I put two libraries in one session?

Re: Can I put two libraries in one session?

Thank you for this information deal