Inter instrument communication

Questions about deployment and use of Air Manager Instruments

Moderators: russ, Ralph

Message
Author
fatcharlieuk
Posts: 47
Joined: Tue Dec 22, 2020 7:42 am

Inter instrument communication

#1 Post by fatcharlieuk »

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.

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

Re: Inter instrument communication

#2 Post by Sling »

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

fatcharlieuk
Posts: 47
Joined: Tue Dec 22, 2020 7:42 am

Re: Inter instrument communication

#3 Post by fatcharlieuk »

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.

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

Re: Inter instrument communication

#4 Post by Sling »

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

fatcharlieuk
Posts: 47
Joined: Tue Dec 22, 2020 7:42 am

Re: Inter instrument communication

#5 Post by fatcharlieuk »

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 :-)

toneill
Posts: 58
Joined: Tue Dec 03, 2019 5:46 pm

Re: Inter instrument communication

#6 Post by toneill »

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

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)
Thanks for the help. Greatly appreciated

Ted
Last edited by toneill on Sat Apr 03, 2021 2:41 pm, edited 2 times in total.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Inter instrument communication

#7 Post by Keith Baxter »

@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
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 

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Inter instrument communication

#8 Post by jph »

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

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
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)
Thanks for the help. Greatly appreciated

Ted
There you go ted. Like Keith says, it makes it far easier to read.
Regards, Joe
Joe. CISSP, MSc.

toneill
Posts: 58
Joined: Tue Dec 03, 2019 5:46 pm

Re: Inter instrument communication

#9 Post by toneill »

:) thanks

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

Re: Inter instrument communication

#10 Post by Sling »

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.

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)

Post Reply