Inter instrument communication
-
- Posts: 48
- Joined: Tue Dec 22, 2020 7:42 am
Inter instrument communication
Hi all,
Please forgive if the answer to my query is on the forum. I am trying to get two instruments to talk to one another.
I have followed Tony's tutorial and searched here. The tutorial video is nice and clear and answers to queries re. inter-instruent communication on this forum make sense - I just can't get my code to work.
I'm using the v4 BETA on a Windows10 laptop.
here are my two instruments:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Instrument 1 (creator)
var_id = si_variable_create("selector_position", "INT", 0)
function Knob_callback(direction)
si_variable_write(var_id, direction)
end
Knob_id = dial_add("circle.png", 25,25,50,50, Knob_callback)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Instrument 2 (subscriber)
function selector_callback(data)
if data == 1 then
txt_set(mytext1,"one!")
else txt_set(mytext1,"not one!")
end
end
si_variable_subscribe("selector_position", "INT", selector_callback)
mytext1 = txt_add("hello world", "font:DejaVuSansMono.ttf; size:20; color: blue; halign:left;", 0, 0, 300, 20)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
I've created a panel with just these two instruments. But the text box resolutely stays at "not one" whichever way I turn the knob.
I cannot see my mistake - I have been over it lots of times but I'm blind to the error!
Any help would be very much appreciated.
Many thanks,
Roger.
Please forgive if the answer to my query is on the forum. I am trying to get two instruments to talk to one another.
I have followed Tony's tutorial and searched here. The tutorial video is nice and clear and answers to queries re. inter-instruent communication on this forum make sense - I just can't get my code to work.
I'm using the v4 BETA on a Windows10 laptop.
here are my two instruments:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Instrument 1 (creator)
var_id = si_variable_create("selector_position", "INT", 0)
function Knob_callback(direction)
si_variable_write(var_id, direction)
end
Knob_id = dial_add("circle.png", 25,25,50,50, Knob_callback)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-- Instrument 2 (subscriber)
function selector_callback(data)
if data == 1 then
txt_set(mytext1,"one!")
else txt_set(mytext1,"not one!")
end
end
si_variable_subscribe("selector_position", "INT", selector_callback)
mytext1 = txt_add("hello world", "font:DejaVuSansMono.ttf; size:20; color: blue; halign:left;", 0, 0, 300, 20)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
I've created a panel with just these two instruments. But the text box resolutely stays at "not one" whichever way I turn the knob.
I cannot see my mistake - I have been over it lots of times but I'm blind to the error!
Any help would be very much appreciated.
Many thanks,
Roger.
Re: Inter instrument communication
Hi Roger,
Glad the tutorials are still proving useful. Your code is fine but because inter instrument communication goes via the plugin, the plugin needs to be running. For the plugin to run the sim needs to be running. Easy mistake to make. This is one of the few things you can’t test end to end without the sim.
Tony
Glad the tutorials are still proving useful. Your code is fine but because inter instrument communication goes via the plugin, the plugin needs to be running. For the plugin to run the sim needs to be running. Easy mistake to make. This is one of the few things you can’t test end to end without the sim.
Tony
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
-
- Posts: 48
- Joined: Tue Dec 22, 2020 7:42 am
Re: Inter instrument communication
Hi Tony,
Thanks for the quick reply. You're right - I wasn't running the sim! Doh!
Of course, now you tell me i can see it plainly written above the inter-instrument communication section of the API wiki, that the simulator needs to be running the plugin! My only defence is that having watched the video and mimicked your actions, I didn't actually read that part as I was just clicking where you clicked.
It's a tiny thing, but if you still have the access to edit your videos, might it be worth a quick caption at the beginning, highlighting this? Yes, of course, one should RTFM, but I'm only in my '60s and I think youthful enthusiasm took over
Your video series is probably the most comprehensive and clear set of tutorials I have ever come across - thanks for having put so much effort into producing them. They have been a font of knowledge and have enabled me to build my own sim cockpit panel. Brilliant work.
Cheers,
Roger.
Thanks for the quick reply. You're right - I wasn't running the sim! Doh!
Of course, now you tell me i can see it plainly written above the inter-instrument communication section of the API wiki, that the simulator needs to be running the plugin! My only defence is that having watched the video and mimicked your actions, I didn't actually read that part as I was just clicking where you clicked.
It's a tiny thing, but if you still have the access to edit your videos, might it be worth a quick caption at the beginning, highlighting this? Yes, of course, one should RTFM, but I'm only in my '60s and I think youthful enthusiasm took over
Your video series is probably the most comprehensive and clear set of tutorials I have ever come across - thanks for having put so much effort into producing them. They have been a font of knowledge and have enabled me to build my own sim cockpit panel. Brilliant work.
Cheers,
Roger.
Re: Inter instrument communication
Thanks Roger. Glad to be of assistance and happy that you have it going now.
The tutorial videos could do with an update to include all of the new features introduced since they were produced. If I ever get round to refreshing them I’ll try and remember to mention the sim running for iic.
Tony
The tutorial videos could do with an update to include all of the new features introduced since they were produced. If I ever get round to refreshing them I’ll try and remember to mention the sim running for iic.
Tony
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
-
- Posts: 48
- Joined: Tue Dec 22, 2020 7:42 am
Re: Inter instrument communication
Thanks Tony all working well now - just as an aside, did you ever make your battery charger available to the community? I can't see it in the list.
It would save a lot of heartache for those of us developing panels and instruments
It would save a lot of heartache for those of us developing panels and instruments
Re: Inter instrument communication
Hi Tony
I am also having this problem with inter-instrument communication. The plug-in is running and I have tried everything I can think of but I am not getting any success.
In my case I am using a hardware switch to write to the si_variable and then I am trying to read it and display an image in the second instrument. I created a test panel and simply cannot get the second instrument to pick up the si_variable.
Here is the code for the first instrument
and the second
Thanks for the help. Greatly appreciated
Ted
I am also having this problem with inter-instrument communication. The plug-in is running and I have tried everything I can think of but I am not getting any success.
In my case I am using a hardware switch to write to the si_variable and then I am trying to read it and display an image in the second instrument. I created a test panel and simply cannot get the second instrument to pick up the si_variable.
Here is the code for the first instrument
Code: Select all
-- Create a new variable
var_id = si_variable_create("gpu_state", "FLOAT", 1)
function D20_pressed(position)
print ("D20 pressed -- position is --> "..position)
if position ==0 then si_variable_write(var_id, 0)
elseif position ==1 then si_variable_write(var_id, 0) --change the value when switch position is changed
end
end
hw_switch_add("ARDUINO_MEGA2560_D_D20",D20_pressed)
and the second
Code: Select all
image_id_off = img_add("gpu_off.png",0,0,150,100)
image_id_on= img_add("gpu_connected.png",0,0,150,100)
function gpu_state_callback (data1)
print ("GPU state is ==> "..data1)
if data1==0 then visible (image_id_off, true)
visible (image_id_on, false)
elseif data1==1 then visible (image_id_off, false)
visible (image_id_on, true)
end
end
si_variable_subscribe("gpu_state", "FLOAT",gpu_state_callback)
Ted
Last edited by toneill on Sat Apr 03, 2021 2:41 pm, edited 2 times in total.
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: Inter instrument communication
@toneill
Please help us to assist you.
There is a button above </>
click on that and place your code within the code quotes. Makes it easier for all to read and help.
No need to retype. Just edit your post please.
Thank's
Keith
Please help us to assist you.
There is a button above </>
click on that and place your code within the code quotes. Makes it easier for all to read and help.
No need to retype. Just edit your post please.
Thank's
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
Re: Inter instrument communication
There you go ted. Like Keith says, it makes it far easier to read.toneill wrote: ↑Sat Apr 03, 2021 1:47 pm Hi Tony
I am also having this problem with inter-instrument communication. The plug-in is running and I have tried everything I can think of but I am not getting any success.
In my case I am using a hardware switch to write to the si_variable and then I am trying to read it and display an image in the second instrument. I created a test panel and simply cannot get the second instrument to pick up the si_variable.
Here is the code for the first instrument
Thanks for the help. Greatly appreciatedCode: Select all
-- Create a new variable var_id = si_variable_create("gpu_state", "FLOAT", 1) function D20_pressed(position) print ("D20 pressed -- position is --> "..position) if position ==0 then si_variable_write(var_id, 0) elseif position ==1 then si_variable_write(var_id, 0) --change the value when switch position is changed end end hw_switch_add("ARDUINO_MEGA2560_D_D20",D20_pressed) and the second image_id_off = img_add("gpu_off.png",0,0,150,100) image_id_on= img_add("gpu_connected.png",0,0,150,100) function gpu_state_callback (data1) print ("GPU state is ==> "..data1) if data1==0 then visible (image_id_off, true) visible (image_id_on, false) elseif data1==1 then visible (image_id_off, false) visible (image_id_on, true) end end si_variable_subscribe("gpu_state", "FLOAT",gpu_state_callback)
Ted
Regards, Joe
Joe. CISSP, MSc.
Re: Inter instrument communication
There is an error in the sending instrument.
A big tip for anyone reading this. I've been harping on about the un-necessary use of if..else and this is just another example. Please everyone there is no need to use if..else in almost all cases for switch, dial etc callbacks when you will be sending data via iic or to a sim dataref or variable. This does not apply when using commands/events. You can just use the data you have when sending to a sim dataref or as in this case a si variable. You can easily invert it if needed or even do something else to generate the outgoing data from incoming pos and/or dir data. In this case we just use it directly.
Why say if something is 0 send 0, elseif that something is 1 send 1. When you can just send the original 0 or 1. It is not required and just adds un-necessasy code.
Ted try this instead.
A big tip for anyone reading this. I've been harping on about the un-necessary use of if..else and this is just another example. Please everyone there is no need to use if..else in almost all cases for switch, dial etc callbacks when you will be sending data via iic or to a sim dataref or variable. This does not apply when using commands/events. You can just use the data you have when sending to a sim dataref or as in this case a si variable. You can easily invert it if needed or even do something else to generate the outgoing data from incoming pos and/or dir data. In this case we just use it directly.
Why say if something is 0 send 0, elseif that something is 1 send 1. When you can just send the original 0 or 1. It is not required and just adds un-necessasy code.
Ted try this instead.
Code: Select all
-- Create a new variable
var_id = si_variable_create("gpu_state", "FLOAT", 1)
function D20_pressed(position)
print ("D20 pressed -- position is --> "..position)
si_variable_write(var_id, position)
end
hw_switch_add("ARDUINO_MEGA2560_D_D20",D20_pressed)
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