Writing fast on Int Array

Peer support for Air Manager desktop users

Moderators: russ, Ralph

Message
Author
alkargr
Posts: 14
Joined: Tue Feb 25, 2020 6:34 pm

Writing fast on Int Array

#1 Post by alkargr »

When I try to write on the same dataref with offset in the same function, only the last entry is updated.

function x()
if a==1 then xpl_dataref_write("custom/something", "INT[8]", {1}, 0)
if b==1 then xpl_dataref_write("custom/something", "INT[8]", {1}, 1)
if c==1 then xpl_dataref_write("custom/something", "INT[8]", {1}, 2)
if d==1 then xpl_dataref_write("custom/something", "INT[8]", {1}, 3)
end

gives ==> {0,0,0,1} when a,b,c,d=1

It works with a timer of >100millisec to make each update with a delay, but using timers will introduce other problems in the instrument's code. Is there any workaround, or am I doing something wrong?
The only solution I can think of is to split the array dataref into separate datarefs, but that doesn't help either.

User avatar
Corjan
Posts: 2941
Joined: Thu Nov 19, 2015 9:04 am

Re: Writing fast on Int Array

#2 Post by Corjan »

Hi,

This should give { 1, 1, 1, 1 } I would imagine.
Will have a look this week if I can find the cause of this issue.

Are you saying that if you add the delay you also end up with { 1, 1, 1, 1 } ?

Corjan

User avatar
Ralph
Posts: 7933
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Writing fast on Int Array

#3 Post by Ralph »

Are you sure that all of these are writeable? It's not exactly the same, but I did a couple of writes on a float array yesterday, that worked fine for each position (offset). Also be sure that you're using the latest plugin.

alkargr
Posts: 14
Joined: Tue Feb 25, 2020 6:34 pm

Re: Writing fast on Int Array

#4 Post by alkargr »

With the delay the result is correct {1,1,1,1}
Without the delay the result is {0,0,0,1}

User avatar
Sling
Posts: 5242
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Writing fast on Int Array

#5 Post by Sling »

Why not just simply do this instead. You can even omit the 0 index if you are always starting at 0 because AM assumes it to be the default if nothing is specified.

Code: Select all


xpl_dataref_write("custom/something", "INT[8]", {a,b,c,d}, 0)


alkargr
Posts: 14
Joined: Tue Feb 25, 2020 6:34 pm

Re: Writing fast on Int Array

#6 Post by alkargr »

I updated the plugin but no change.

Here is the code I used:

Code: Select all

a=1
function updateArray()
    if a==1 then xpl_dataref_write("custom/something", "INT[8]", {1}, 0) end
    if a==1 then xpl_dataref_write("custom/something", "INT[8]", {1}, 1) end
    if a==1 then xpl_dataref_write("custom/something", "INT[8]", {1}, 2) end
    if a==1 then xpl_dataref_write("custom/something", "INT[8]", {1}, 3) end
end

function btn_pressed()
    updateArray()
end
hw_button_add("Test button", btn_pressed)

---RESULT==> {0,0,0,1}

-----WITH TIMER
function updateArray_callback(count)
    if count==1 then  if a==1 then xpl_dataref_write("custom/something", "INT[8]", {1}, 0) end end
    if count==2 then  if a==1 then xpl_dataref_write("custom/something", "INT[8]", {1}, 1) end end
    if count==3 then  if a==1 then xpl_dataref_write("custom/something", "INT[8]", {1}, 2) end end
    if count==4 then  if a==1 then xpl_dataref_write("custom/something", "INT[8]", {1}, 3) end end
end

timer_start(1000, 100, 4, updateArray_callback)

-- RESULT==> {1,1,1,1}

User avatar
Sling
Posts: 5242
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Writing fast on Int Array

#7 Post by Sling »

When posting code to the forum please use a code box it makes it easier for others to read.

User avatar
Corjan
Posts: 2941
Joined: Thu Nov 19, 2015 9:04 am

Re: Writing fast on Int Array

#8 Post by Corjan »

Hi,


Just added the code box.

Like Sling said, doing one xpl_dataref_write makes more sense.
But then again, the other method should also work in theory. Will investigate tomorrow or the day after...


Corjan

alkargr
Posts: 14
Joined: Tue Feb 25, 2020 6:34 pm

Re: Writing fast on Int Array

#9 Post by alkargr »

Thank you for the replies, sorry for the code block!

There are other functions that might be called and should update the same dataref at different indexes. Even if I update multiple values only once per function, some values are updated, but others not.

You can try this code:

Code: Select all

function updateArray()
    --does multiple checks and calls other functions to decide each value
    --gathers all the values and then updates the dataref
    xpl_dataref_write("custom/something", "INT[8]", {1,1,1,1}) 
end
function updateArray2()
     xpl_dataref_write("custom/something", "INT[8]", {1,1,1,1}, 4)
end
function updateArray3()
     xpl_dataref_write("custom/something", "INT[8]", {1,1,1,1}, 8)
end

function btn_pressed()
    updateArray()
    updateArray2()
    updateArray3()
end
hw_button_add("Test button", btn_pressed)

--RESULT ==> {1,1,1,1,0,0,0,0,1,1,1,1}  the second function doesn't update the values

User avatar
Ralph
Posts: 7933
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Writing fast on Int Array

#10 Post by Ralph »

Sorry, I didn't read properly, I didn't notice what you said about the delay and such.

Post Reply