1. ## Gables VHF COM radio interfacing (howto guide)

Here I am back with the second part of Gabels interfacing tutorial. Before reading this post please familiarize yourself with the first part here: http://www.mycockpit.org/forums/inte...wto-guide.html

This article includes basic description of VHF COM interfacing. I would like to say that the principle is quite similar to the VHF NAV interfacing which is described in a great detail in another article in this section so I will just mention the differences here.

Encoders differences
The main difference in encoders is their number and their logic. There are only four encoders in COM radio but there were seven of them in NAV radio which could sound strange because the range of COM VHF band is much greater than NAV. The encoders are here quite different: The whole parf of the frequency must be coded by two encoders (range 118 - 136 means 19 steps). Each encoder has 4 or 5 outputs at each time which together gives 9 outputs. This is not sufficient for 19 steps so Gabels did it in the way that two outputs on each encoder are active at each time. It means 4 active switches for the whole part of frequency at any time which gives you quite high number of combinations available. Due to the fact that more than one switch is active on each encoder (and each encoder has only one common ground input) there are diodes behind each output. If the diodes were missing the switch would electrically connect the two outputs together which would cause false readings. There are 18 diodes on each side of COM radio + 2 diodes on the frequency switch giving together 38 diodes in each COM radio.

Frequency selector differences
In the NAV radio a standard turn two position switch was used which was capable of switching lot of channels independently so we could switch all the common grounds for all the encoders at each time. In COM radio there is unfortunately only standard two position switch capable of switching only two channels at a time. It means that I had to connect both "sides" of frequencies to the USB card, connect the frequency selector as a simple switch to the joystick card and use software to determine the active frequency. Due to that both active and standby frequencies are decoded at my computer (but only the active is being sent to FSX via Simconnect). The other switching channel of frequency selector is used for light bulbs switching.

Software interfacing
As I have said the software can see all the encoders all the time so both frequencies are known. Because of that the script is twice as long as it would be in NAV instrument where only the active frequency was sent to PC. Also note that I had to combine multiple conditions to determine the frequency set as the whole part is coded by combination of 4 switches, the decimal part is combination of 2 switches and only the last number (zero, two, five, or seven) is coded by single switches).

My VBScript for HIDMacros

Sub COM1set
if ((HIDMacros.IsButtonPressed("COM1", 11)/(-128))+(HIDMacros.IsButtonPressed("COM1", 16)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 23)/(-128))+(HIDMacros.IsButtonPressed("COM1", 24)/(-128))= 4 then
com1_wholeright_18 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 10)/(-128))+(HIDMacros.IsButtonPressed("COM1", 16)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 23)/(-128))+(HIDMacros.IsButtonPressed("COM1", 24)/(-128))= 4 then
com1_wholeright_19 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 10)/(-128))+(HIDMacros.IsButtonPressed("COM1", 15)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 24)/(-128))= 4 then
com1_wholeright_20 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 15)/(-128))+(HIDMacros.IsButtonPressed("COM1", 16)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 24)/(-128))= 4 then
com1_wholeright_21 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 14)/(-128))+(HIDMacros.IsButtonPressed("COM1", 16)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 24)/(-128))= 4 then
com1_wholeright_22 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 14)/(-128))+(HIDMacros.IsButtonPressed("COM1", 15)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 24)/(-128))= 4 then
com1_wholeright_23 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 11)/(-128))+(HIDMacros.IsButtonPressed("COM1", 15)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 24)/(-128))= 4 then
com1_wholeright_24 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 11)/(-128))+(HIDMacros.IsButtonPressed("COM1", 14)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 24)/(-128))= 4 then
com1_wholeright_25 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 10)/(-128))+(HIDMacros.IsButtonPressed("COM1", 14)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 24)/(-128))= 4 then
com1_wholeright_26 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 10)/(-128))+(HIDMacros.IsButtonPressed("COM1", 11)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 24)/(-128))= 4 then
com1_wholeright_27 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 11)/(-128))+(HIDMacros.IsButtonPressed("COM1", 16)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 24)/(-128))= 4 then
com1_wholeright_28 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 10)/(-128))+(HIDMacros.IsButtonPressed("COM1", 16)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 24)/(-128))= 4 then
com1_wholeright_29 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 10)/(-128))+(HIDMacros.IsButtonPressed("COM1", 15)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 23)/(-128))= 4 then
com1_wholeright_30 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 15)/(-128))+(HIDMacros.IsButtonPressed("COM1", 16)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 23)/(-128))= 4 then
com1_wholeright_31 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 14)/(-128))+(HIDMacros.IsButtonPressed("COM1", 16)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 23)/(-128))= 4 then
com1_wholeright_32 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 14)/(-128))+(HIDMacros.IsButtonPressed("COM1", 15)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 23)/(-128))= 4 then
com1_wholeright_33 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 11)/(-128))+(HIDMacros.IsButtonPressed("COM1", 15)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 23)/(-128))= 4 then
com1_wholeright_34 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 11)/(-128))+(HIDMacros.IsButtonPressed("COM1", 14)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 23)/(-128))= 4 then
com1_wholeright_35 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 10)/(-128))+(HIDMacros.IsButtonPressed("COM1", 14)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 22)/(-128))+(HIDMacros.IsButtonPressed("COM1", 23)/(-128))= 4 then
com1_wholeright_36 = 1
end if
if (HIDMacros.IsButtonPressed("COM1", 31)/(-128))= 1 And (HIDMacros.IsButtonPressed("COM1", 32)/(-128))= 0 And (HIDMacros.IsButtonPressed("COM1", 30)/(-128))= 0 And (HIDMacros.IsButtonPressed("COM1", 27)/(-128))= 0 then
com1_decright_00 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 31)/(-128))+(HIDMacros.IsButtonPressed("COM1", 32)/(-128)))= 2 then
com1_decright_10 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 30)/(-128))+(HIDMacros.IsButtonPressed("COM1", 32)/(-128)))= 2 then
com1_decright_20 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 30)/(-128))+(HIDMacros.IsButtonPressed("COM1", 31)/(-128)))= 2 then
com1_decright_30 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 27)/(-128))+(HIDMacros.IsButtonPressed("COM1", 31)/(-128)))= 2 then
com1_decright_40 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 27)/(-128))+(HIDMacros.IsButtonPressed("COM1", 30)/(-128)))= 2 then
com1_decright_50 = 1
end if
if (HIDMacros.IsButtonPressed("COM1", 30)/(-128))= 1 And (HIDMacros.IsButtonPressed("COM1", 32)/(-128))= 0 And (HIDMacros.IsButtonPressed("COM1", 31)/(-128))= 0 And (HIDMacros.IsButtonPressed("COM1", 27)/(-128))= 0 then
com1_decright_60 = 1
end if
if (HIDMacros.IsButtonPressed("COM1", 27)/(-128))= 1 And (HIDMacros.IsButtonPressed("COM1", 31)/(-128))= 0 And (HIDMacros.IsButtonPressed("COM1", 30)/(-128))= 0 And (HIDMacros.IsButtonPressed("COM1", 32)/(-128))= 0 then
com1_decright_70 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 27)/(-128))+(HIDMacros.IsButtonPressed("COM1", 32)/(-128)))= 2 then
com1_decright_80 = 1
end if
if (HIDMacros.IsButtonPressed("COM1", 32)/(-128))= 1 And (HIDMacros.IsButtonPressed("COM1", 31)/(-128))= 0 And (HIDMacros.IsButtonPressed("COM1", 30)/(-128))= 0 And (HIDMacros.IsButtonPressed("COM1", 27)/(-128))= 0 then
com1_decright_90 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 8)/(-128))= 1 )then
com1_lastright_0 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 7)/(-128))= 1 )then
com1_lastright_2 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 6)/(-128))= 1 )then
com1_lastright_5 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 3)/(-128))= 1 )then
com1_lastright_7 = 1
end if
right_com1_frequency_whole = com1_wholeright_18 * 118 + com1_wholeright_19 * 119 + com1_wholeright_20 * 120 + com1_wholeright_21 * 121 + com1_wholeright_22 * 122 + com1_wholeright_23 * 123 + com1_wholeright_24 * 124 + com1_wholeright_25 * 125 + com1_wholeright_26 * 126 + com1_wholeright_27 * 127 + com1_wholeright_28 * 128 + com1_wholeright_29 * 129 + com1_wholeright_30 * 130 + com1_wholeright_31 * 131 + com1_wholeright_32 * 132 + com1_wholeright_33 * 133 + com1_wholeright_34 * 134 + com1_wholeright_35 * 135 + com1_wholeright_36 * 136 + 0
right_com1_frequency_decimal = com1_decright_00 * 0 + com1_decright_10 * 0.1 + com1_decright_20 * 0.2 + com1_decright_30 * 0.3 + com1_decright_40 * 0.4 + com1_decright_50 * 0.5 + com1_decright_60 * 0.6 + com1_decright_70 * 0.7 + com1_decright_80 * 0.8 + com1_decright_90 * 0.9
right_com1_frequency_last = com1_lastright_0 * 0 + com1_lastright_2 * 0.02 + com1_lastright_5 * 0.05 + com1_lastright_7 * 0.07
right_com1_freq = right_com1_frequency_whole + right_com1_frequency_decimal + right_com1_frequency_last
right_com1_active=HIDMacros.IsButtonPressed("COM1", 4)/(-128)
if ((HIDMacros.IsButtonPressed("COM1", 55)/(-128))+(HIDMacros.IsButtonPressed("COM1", 59)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 64)/(-128))= 3 then
com1_wholeleft_18 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 55)/(-128))+(HIDMacros.IsButtonPressed("COM1", 56)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 58)/(-128))+(HIDMacros.IsButtonPressed("COM1", 64)/(-128))= 4 then
com1_wholeleft_19 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 56)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 58)/(-128))+(HIDMacros.IsButtonPressed("COM1", 63)/(-128))= 4 then
com1_wholeleft_20 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 56)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 63)/(-128))+(HIDMacros.IsButtonPressed("COM1", 64)/(-128))= 4 then
com1_wholeleft_21 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 56)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 62)/(-128))+(HIDMacros.IsButtonPressed("COM1", 64)/(-128))= 4 then
com1_wholeleft_22 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 56)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 62)/(-128))+(HIDMacros.IsButtonPressed("COM1", 63)/(-128))= 4 then
com1_wholeleft_23 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 56)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 59)/(-128))+(HIDMacros.IsButtonPressed("COM1", 63)/(-128))= 4 then
com1_wholeleft_24 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 56)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 59)/(-128))+(HIDMacros.IsButtonPressed("COM1", 62)/(-128))= 4 then
com1_wholeleft_25 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 56)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 58)/(-128))+(HIDMacros.IsButtonPressed("COM1", 62)/(-128))= 4 then
com1_wholeleft_26 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 56)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 58)/(-128))+(HIDMacros.IsButtonPressed("COM1", 59)/(-128))= 4 then
com1_wholeleft_27 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 56)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 59)/(-128))+(HIDMacros.IsButtonPressed("COM1", 64)/(-128))= 4 then
com1_wholeleft_28 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 56)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 58)/(-128))+(HIDMacros.IsButtonPressed("COM1", 64)/(-128))= 4 then
com1_wholeleft_29 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 55)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 58)/(-128))+(HIDMacros.IsButtonPressed("COM1", 63)/(-128))= 4 then
com1_wholeleft_30 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 55)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 63)/(-128))+(HIDMacros.IsButtonPressed("COM1", 64)/(-128))= 4 then
com1_wholeleft_31 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 55)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 62)/(-128))+(HIDMacros.IsButtonPressed("COM1", 64)/(-128))= 4 then
com1_wholeleft_32 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 55)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 62)/(-128))+(HIDMacros.IsButtonPressed("COM1", 63)/(-128))= 4 then
com1_wholeleft_33 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 55)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 59)/(-128))+(HIDMacros.IsButtonPressed("COM1", 63)/(-128))= 4 then
com1_wholeleft_34 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 55)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 59)/(-128))+(HIDMacros.IsButtonPressed("COM1", 62)/(-128))= 4 then
com1_wholeleft_35 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 54)/(-128))+(HIDMacros.IsButtonPressed("COM1", 55)/(-128)))+(HIDMacros.IsButtonPressed("COM1", 58)/(-128))+(HIDMacros.IsButtonPressed("COM1", 62)/(-128))= 4 then
com1_wholeleft_36 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 42)/(-128))+(HIDMacros.IsButtonPressed("COM1", 47)/(-128))= 2) then
com1_decleft_00 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 47)/(-128))+(HIDMacros.IsButtonPressed("COM1", 48)/(-128))= 2) then
com1_decleft_10 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 46)/(-128))+(HIDMacros.IsButtonPressed("COM1", 48)/(-128))= 2) then
com1_decleft_20 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 46)/(-128))+(HIDMacros.IsButtonPressed("COM1", 47)/(-128))= 2) then
com1_decleft_30 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 43)/(-128))+(HIDMacros.IsButtonPressed("COM1", 47)/(-128))= 2) then
com1_decleft_40 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 43)/(-128))+(HIDMacros.IsButtonPressed("COM1", 46)/(-128))= 2) then
com1_decleft_50 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 42)/(-128))+(HIDMacros.IsButtonPressed("COM1", 46)/(-128))= 2) then
com1_decleft_60 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 42)/(-128))+(HIDMacros.IsButtonPressed("COM1", 43)/(-128))= 2) then
com1_decleft_70 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 43)/(-128))+(HIDMacros.IsButtonPressed("COM1", 48)/(-128))= 2) then
com1_decleft_80 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 42)/(-128))+(HIDMacros.IsButtonPressed("COM1", 48)/(-128))= 2) then
com1_decleft_90 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 40)/(-128))= 1 )then
com1_lastleft_0 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 39)/(-128))= 1 )then
com1_lastleft_2 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 38)/(-128))= 1 )then
com1_lastleft_5 = 1
end if
if ((HIDMacros.IsButtonPressed("COM1", 35)/(-128))= 1 )then
com1_lastleft_7 = 1
end if
left_com1_frequency_whole = com1_wholeleft_18 * 118 + com1_wholeleft_19 * 119 + com1_wholeleft_20 * 120 + com1_wholeleft_21 * 121 + com1_wholeleft_22 * 122 + com1_wholeleft_23 * 123 + com1_wholeleft_24 * 124 + com1_wholeleft_25 * 125 + com1_wholeleft_26 * 126 + com1_wholeleft_27 * 127 + com1_wholeleft_28 * 128 + com1_wholeleft_29 * 129 + com1_wholeleft_30 * 130 + com1_wholeleft_31 * 131 + com1_wholeleft_32 * 132 + com1_wholeleft_33 * 133 + com1_wholeleft_34 * 134 + com1_wholeleft_35 * 135 + com1_wholeleft_36 * 136 + 0
left_com1_frequency_decimal = com1_decleft_00 * 0 + com1_decleft_10 * 0.1 + com1_decleft_20 * 0.2 + com1_decleft_30 * 0.3 + com1_decleft_40 * 0.4 + com1_decleft_50 * 0.5 + com1_decleft_60 * 0.6 + com1_decleft_70 * 0.7 + com1_decleft_80 * 0.8 + com1_decleft_90 * 0.9
left_com1_frequency_last = com1_lastleft_0 * 0 + com1_lastleft_2 * 0.02 + com1_lastleft_5 * 0.05 + com1_lastleft_7 * 0.07
left_com1_freq = left_com1_frequency_whole + left_com1_frequency_decimal + left_com1_frequency_last
left_com1_active=HIDMacros.IsButtonPressed("COM1", 5)/(-128)
com1_result = (right_com1_freq * right_com1_active + left_com1_freq * left_com1_active)*100
'HIDMacros.Debug(com1_result)
end sub

Copied from Czech DC-9 project

No video yet, I am going to sleep now, tomorrow the second COM is waiting for wiring and scripting, video will be recorded when it is done :p

Pavel