PDA

View Full Version : Trying to get USBkeys to work with SIOC



tiburon
05-15-2011, 09:18 AM
A total newbie at SIOC, I'm trying to get my USBkeyscard to send a simple 0/1 command to FSUIPC offset x0BC8 to release and apply the parking brakes in the PMDG 737. I know I can use IOCkeys to define a keystroke but I already have the ATC module rotary working through SIOC thanks to a script by a member of this forum and I would like to get my head around it fot future interfacing.
So I connected the card, opened sioc and read the device id : 44. I then opened SIOC.ini and changed it to read USBkeys=0,44
here's my sioc.ini :

[************** SIOC ***************]
[ IOCP port ]
IOCP_port=8090

[ IOCP Timeout ]
IOCP_timeout=4000

[ Start minimized in tray ]
Minimized=No

[ Deley needed for var. toggles (Project Magenta) ]
toggle_delay=20

[ Configuration File ]
CONFIG_FILE=.\SCRIPTS\SIOC ATC PMDG.txt


[************** IOCARDS MODULE ***************]
[ Disable IOCards module ]
IOCard_disable=No

[ Use LPT port in IOCards ]
IOCard_LPT=No


[------------- CARDS CONFIG -------------]

[ IOCard Master ]
[...............]


[ English : ]

[ MASTER=(Device index),(Type),(Number of cards),(Device number) ]

[ Device index : Index used in SIOC variable like device, this is the card used for SIOC sentence ]
[ Use 0 for only one card, for this value you not need specify Device number. If you not use DEVICE parameter in a definition in SIOC script, the default index used is 0]

[ type = 0 : Master Card Emulator ]
[ type = 1 : Master Card connected directly to parallel port ]
[ type = 2 : Master Card connected throught compatibility cable to parallel port ]
[ type = 3 : Expansion Card connected throught parallel port ]
[ type = 4 : USBExpansion Card used ]
[ type = 5 : Opencockpits MCP module ]
[ type = 6 : USBOutputs Card used ]
[ type = 7 : Opencockpits EFIS module ]
[ type = 8 : Opencockpits Radio COM module ]
[ type = 9 : Opencockpits Radio NAV module ]
[ type = 10 : Opencockpits Radio ADF module ]
[ type = 11 : Opencockpits Radio ATC module ]

[ Number of Cards = Master cards connecteds, 1 to 4 for expansion cards, 1 for a Master card directly connected or Emulator ]

[ Number of device = 0 for Emulator or first USB card detected, parallel port address, device number for specifies USBexpansion card ]

[ For example, a Master Card connected directly to parallel port : ]
[ MASTER=0,1,1,$0378 ]

[ For example, two USBExpansion cards connected with 3 and 2 Master cards used ]
[ MASTER=0,4,3,22 ]
[ MASTER=1,4,2,24 ]

[ For example, use of Master card emulator ]
[ MASTER=0,0,1,0 ]

[ Use the first USBExpansion card connected with only one Master Card attached ]
[ Esta definición es para usar la primera tarjeta USBExpansion que se encuentre instalada que además llevará conectada una placa Master ]

[MASTER=3,6,1,252]
[MASTER=0,4,1,0]
[MASTER=0,4,1,0]
MASTER=0,4,2,0
MASTER=0,11,2,0



[ Name_of_card=(Device index),(Device number) ]

[ Device index : Index used in SIOC variable like device, this is the card used for SIOC sentence ]
[ Use 0 for only one card, for this value you not need specify Device number. If you not use DEVICE parameter in a definition in SIOC script, the default index used is 0]

[ Number of device = 0 for first USB card of this type detected, or device number for a specifies device ]

[ Example of two USBServos for index 0 and 1, and device number 17 and 23 ]

[ USBServos=0,17 ]
[ USBServos=1,23 ]


USBStepper=0,0
USBKeys=0,44
USBServos=0,0
USBRelays=0,0
USBDCmotor=0,0

[ Para los ejes analógicos se usan los números de devices de las tarjetas donde están alojados ]
[ For analogic axles, you use the device number of cards what allow the axles ]

USBAnalogic=0,0


[************** FSUIPC MODULE ***************]

[ Desabilitar lectura de las FSUIPC ]
[ FSUIPC disable mode yes/no ]
FSUipcdisable=No

[ Refresco recepción FSUIPC ]
[ FSUIPC refresh ]
FSUipcRefresh=50


[************** IOCP CLIENTS MODULES ***************]

[ Retraso para inicializacion una vez conectado el cliente en milisegundos ]
[ Delay for initialization when client has been connected in mseconds ]
IOCPini_delay=3000

[************** IOCP CLIENT MODULE #0 ***************]

[ Desactivar el módulo cliente IOCP ]
[ Disable IOCP client module ]
IOCPclient0_disable=Yes

[ IP del servidor donde debe de conectar el cliente ]
[ IOCP client host name ]
IOCPclient0_host=localhost

[ Puerto de envio del protocolo IOCP cliente ]
[ IOCP client port ]
IOCPclient0_port=8090


[************** IOCP CLIENT MODULE #1 ***************]

[ Desactivar el módulo cliente IOCP ]
[ Disable IOCP client module ]
IOCPclient1_disable=Yes

[ IP del servidor donde debe de conectar el cliente ]
[ IOCP client host name ]
IOCPclient1_host=localhost

[ Puerto de envio del protocolo IOCP cliente ]
[ IOCP client port ]
IOCPclient1_port=8099


[************** SOUND MODULE ***************]

[ Ficheros de sonido ]
[ Sound Files ]

[ Desactivar el módulo de sonido ]
[ Disable Sound module ]
Sound_disable=yes

[ Volumen general de los sonidos 0-100 ]
[ Master Volume 0-100 ]
Volume=100


[ put '*' first filename for loop Sound ]
[ anteponer '*' en el fichero para bucle continuo de sonido]

[ Sound=wav_file,frequency,volume,pan ]
[ frequency=100 to 100000 0=original -1=current ]
[ volume=0 to 100, -1=current ]
[ pan=-100 (left) to +100 (right) 0=center -1=current ]

[ Sound=Fichero_wav,frecuencia,volumen,balance ]
[ frecuencia=100 hasta 100000 0=original -1=Por defecto ]
[ volumen=0 hasta 100 -1=Volumen por defecto ]
[ balance=-100 (Izquierda) hasta +100 (Derecha) 0=centro -1=Por defecto ]

[ #1 ]
Sound=APDis.wav,-1,-1,-1

[ #2 ]
Sound=*outermk.wav,-1,-1,-1

[ #3 ]
Sound=*hello.wav

[************** KEYBOARD EMULATOR MODULE ***************]

[ Nombre exacto de la ventana donde se enviarán las teclas ]
[ Name of window for key send ]
[window = "Project Magenta Glass Cockpit - Build 396" ]

window =a.txt - Bloc de notas


[ Asignación de teclas ]
[ assign youe keys ]

#1=\3I\4
#2=\3\1I\2\4
#3=C
#4=D
#5=E
#6=F
#7=G
#8=H
#9=I
#10=J
#11=K
#12=L
#13=M
#14=N
#15=O
#16=P
#17=Q
#18=R
#19=S
#20=T
#21=U
#22=V
#23=W
#24=X
#25=Y
#26=Z
#27=1
#28=2
#29=3
#30=4
#31=5
#32=6
#33=7
#34=8
#35=9
#36=0
#37=<
#38=,
#39=.
#40=-
#41=*
#42=+
#43=//
#44=/0
#45=/1
#46=/A
#47=
#48=
#49=
#50=
#51=
#52=
#53=
#54=
#55=
#56=
#57=
#58=
#59=
#60=
#61=
#62=
#63=
#64=
#65=
#66=
#67=
#68=
#69=
#70=
#71=
#72=
#73=
#74=
#75=
#76=
#77=
#78=
#79=
#80=
#81=
#82=
#83=
#84=
#85=
#86=
#87=
#88=<a
#200=<b

[ End of File ]

If this works (how can I test it?) the next step would be to write a script.
I've looked at a lot of examples at Niko's site, Ive tried a few things but it's unclear to me how to tell a script that when I toggle a switch it should be sent to my flight sim
Could someone please walk me through this ? I would be very grateful.

Martin

mpl330
05-15-2011, 10:59 AM
Hi Martin,

I'm not sure but I think the USB Keys Card only sends key strokes to an active window rather than FSUIPC offsets but you could send 'G' as a key stroke to the FS window which would do the gear... Someone else may be able to confirm this...?

Cheers
Mike

tiburon
05-15-2011, 11:14 AM
Hi Mike,

The way I have done it with IOCkeys was assign a keystroke to the offset in FSUIPC and assign the keystroke to the USBkeys card.
I was under the impression I could do this directly in SIOC but maybe I'm wrong ?

fordgt40
05-15-2011, 11:21 AM
Martin

You can write a script in sioc to read the key presses from the USBKeys card and then dependent on what you want send a value to any FSUIPC offset. You need to do a bit of studying on SIOC syntax, though you are well on the way reading Nico`s site. Have a try, by first writing out the logic flow of what you want eg

Has key G been pressed
If so then send the value to the correct FSUIPC offset

Then code this in SIOC syntax with the variable definitions. If you get stuck then post again

David

tiburon
05-15-2011, 11:54 AM
I have been studying Nico's site quite a while but I don't seem to be able to make it work. Is it for example different to connect a switch to a mastercard or to a USBkeyscard ? How do you tell SIOC there is a USBcard connected ? Do you use the key defintions at the end of SIOC.ini ?

kiek
05-15-2011, 12:34 PM
Hi,
There are two ways of working possible with the USBKeys card:

1) To let it generate keys. There are plenty of examples of this in the Opencockpits Forum

2) To let it generate integer codes (you can use IOCKeys to check the code generated for a key). In a SIOC script you can receive these codes and do whatever you want.

In sioc.ini define:


[USBKEYS]
USBKeys=5,44


In a SIOC script write:


Var 6000 Static name Key Link USB_KEYS Device 5
{
L0 = &Key
IF L0 = "your on key code code here"
{
&ParkBrake = 32767 // park brake ON
}
ELSE
{
IF L0 = "your off key code here"
{
&ParkBrake = 0 // park brake OFF
}
}
}

Var 1 name ParkBrake Link FSUIPC_OUT Length 2 Offset $0BC8


Regards,
Nico Kaan

fordgt40
05-15-2011, 12:58 PM
Martin

The USBKeys card is like a keyboard matrix and will return a value dependent on the row and column selected (joined) by your keypress. You have approx 88 "keys" ie that is the number of rows multiplied by the number of columns.

SIOC knows that there is an USBkeys card because you have given it a device number in the sioc.ini file

You now need to write a .txt file in notepad containing your SIOC instructions and also put the reference in the sioc.ini file for example CONFIG_FILE=.\SCRIPTS\SIOC yournewsiocfile.txt
If I recall correctly, the .ini key definitions are there for when you want to send a character to the "live" window. However, if you want to send something to an offset then you only need to look for the "key" value you want. For example if you have a switch joing row 5 and column 7 then simplistically you want to know when key 35 has been pressed. If you are unsure of the numbering of the "keys" within the matrix then use the IOCPCONSOLE feature within the main SIOC window - this will tell you the "key" press when you look for the variable value you have assigned to the incoming key presses. Here is a very simple coding example



Var 0000, Value 0

Var 0001, Link FSUIPC_INOUT, name Gear_status, Offset $????, Length 1 // Insert the correct FSUIPC offset in place of ????

Var 0002, name key_in, Link USB_KEYS // this is your incoming "key press" value
{
if &key_in = 71 // 71 or whatever "keypress" value you are looking for
{
&Gear_status = 1 // sends a value of 1 to the gearstatus FSUIPC offset
}
}

mpl330
05-15-2011, 01:05 PM
Ah so you can make it send FSUIPC values by coding round it, makes sense really!

Cheers
Mike

tiburon
05-15-2011, 01:10 PM
Thank you, Nico.
Couple of questions, if you don't mind :
So if I understand correctly : For the second option you don't have to assign keystrokes at all ? You just see which codes are generated ?
<USBKeys=5,44> : is there a reason for the "5" in this statement ?
What does "static" do in the first line of the script ?
I actually think I understand the rest of it. Wow.
Thanks a lot, Nico, je bent een kanjer.

tiburon
05-15-2011, 01:23 PM
Martin

The USBKeys card is like a keyboard matrix and will return a value dependent on the row and column selected (joined) by your keypress. You have approx 88 "keys" ie that is the number of rows multiplied by the number of columns.

SIOC knows that there is an USBkeys card because you have given it a device number in the sioc.ini file

You now need to write a .txt file in notepad containing your SIOC instructions and also put the reference in the sioc.ini file for example CONFIG_FILE=.\SCRIPTS\SIOC yournewsiocfile.txt
If I recall correctly, the .ini key definitions are there for when you want to send a character to the "live" window. However, if you want to send something to an offset then you only need to look for the "key" value you want. For example if you have a switch joing row 5 and column 7 then simplistically you want to know when key 35 has been pressed. If you are unsure of the numbering of the "keys" within the matrix then use the IOCPCONSOLE feature within the main SIOC window - this will tell you the "key" press when you look for the variable value you have assigned to the incoming key presses. Here is a very simple coding example



Var 0000, Value 0

Var 0001, Link FSUIPC_INOUT, name Gear_status, Offset $????, Length 1 // Insert the correct FSUIPC offset in place of ????

Var 0002, name key_in, Link USB_KEYS // this is your incoming "key press" value
{
if &key_in = 71 // 71 or whatever "keypress" value you are looking for
{
&Gear_status = 1 // sends a value of 1 to the gearstatus FSUIPC offset
}
}

David, thanks, it's getting clearer by the minute. Why does your script start with Var0000, value 0 ?
I'm going to study your and Nico's examples exhaustively, looking forward to it all coming together.

fordgt40
05-15-2011, 01:32 PM
Why does your script start with Var0000, value 0 ?

Martin

You can delete that line - the snippet of code I gave you was a fraction of my FMC code and I had left that in
That line actually is used to give some variables an initial value at start up. If you have a var 0000, then SIOC will run the code attached to that Var once at startup. So you can use it to initialise other variables eg
Var 0000 Value 0
{
&Altitude = 10000
&Heading = 180
}
Etc
Etc

David

kiek
05-15-2011, 02:26 PM
So if I understand correctly : For the second option you don't have to assign keystrokes at all ? You just see which codes are generated ?

Yes, indeed.



<USBKeys=5,44> : is there a reason for the "5" in this statement ?

Yes, because in sioc.ini i had defined DEVICE 5 to be your USBKeys card (44)


[USBKEYS]
USBKeys=5,44




What does "static" do in the first line of the script ?

It means that the var number 6000 will never change when you compile this script together with another script, is not very important here actually.

Gefeliciteerd met het 30ste kampioenschap van Ajax (!), zit je niet in de kroeg ? ;-)

Groeten,
Nico

tiburon
05-15-2011, 02:41 PM
Nah, ben niet zo'n voetbal fan:)