Writing fast on Int Array
Writing fast on Int Array
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.
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.
Re: Writing fast on Int Array
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
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
Re: Writing fast on Int Array
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.
Re: Writing fast on Int Array
With the delay the result is correct {1,1,1,1}
Without the delay the result is {0,0,0,1}
Without the delay the result is {0,0,0,1}
Re: Writing fast on Int Array
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)
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Re: Writing fast on Int Array
I updated the plugin but no change.
Here is the code I used:
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}
Re: Writing fast on Int Array
When posting code to the forum please use a code box it makes it easier for others to read.
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Re: Writing fast on Int Array
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
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
Re: Writing fast on Int Array
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:
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
Re: Writing fast on Int Array
Sorry, I didn't read properly, I didn't notice what you said about the delay and such.