Write to local/score device directly from a Serial device

Hi, I would like to set “play” in a local/score device to true from a Serial device when a button is pressed but haven’t managed to do it. I have tried using the “return” technique but this only seems to work for “children” of the serial device and not for other devices. eg. I’ve tried this to no avail:

return [{address: “score:/play”, value: true}];

I have also tried a method that has otherwise worked for me in script processes in the Score timeline. eg.

import Ossia 1.0 as Ossia
import Score 1.0 as Score     // have tried with and without this (also using the "Ossia" scope rather than the Score scope below) - nothing works
......
......
Score.Device.write("score:/play", true);

Hope this makes sense. Any suggestions please?

Thanks

Edit: Here is the full Serial device script:

import Ossia 1.0 as Ossia
import Score 1.0 as Score

Ossia.Serial
{
    property var lastmsg: ""
	function openListening(address) {}
    function closeListening(address) {}

    function onMessage(message) { // evaluated each time a message is received
     	//console.log(message);
 
        var redVal, greenVal, blueVal;
       if(message != lastmsg) {
        const msgAr = message.split(" ");
        //console.log(message);
        lastmsg = message;
        redVal = msgAr[1];
        greenVal = msgAr[2];
        blueVal = msgAr[3];
             if(redVal == "1") {
                 redVal = true;
                // return [{address: "Arduino:/red", value: true}];
       Score.Device.write("score:/play", true);
             } else {
                     redVal = false;
            }
             if(greenVal == "1") {
                 greenVal = true;
             } else {
                     greenVal = false;
             } 
             if(blueVal == "1") {
                 blueVal = true;
             } else {
                     blueVal = false;
             }
            
        return [{address: "/volume", value: msgAr[0] / 1023}, {address: "/red", value: redVal}, {address: "/green", value: greenVal}, {address: "/blue", value: blueVal}];  
 
 }
     	
	}

    	function createTree() {
        return [
        {
			name: "volume",
			//bind: "Pi:/Vol",
            type:  Ossia.Type.Float,
            min: 0,
            max: 1023,
            access: Ossia.Access.Get,
			bounding: Ossia.Bounding.Clip,
            repetition_filter: Ossia.Repetitions.Filtered
         },
         {
			name: "red",
            type:  Ossia.Type.Bool,
            access: Ossia.Access.Get,
            repetition_filter: Ossia.Repetitions.Filtered
         },
         {
			name: "green",
            type:  Ossia.Type.Bool,
            access: Ossia.Access.Get,
            repetition_filter: Ossia.Repetitions.Filtered
         },
         {
			name: "blue",
            type:  Ossia.Type.Bool,
            access: Ossia.Access.Get,
            repetition_filter: Ossia.Repetitions.Filtered
         }

                   
                 
                 
                 ]; 
	}
}

Hey Iain, Glad to see you are back at it !
Maybe the Mapper device can help you there (only guessing).

the Mapper maps a value from one device to another.
It should in theory serve as a “go between” your serial device and score’s local device.
Hope this helps.

1 Like

Thanks Thibaud - I see, got it to work!