General
Banner
Home | Articles | Dutch

 

Basics for cockpit builders.

Writing your own cockpit managements program in Visual Basic 6.

Part 2: Connecting switches to FS

Introduction | Hardware | Program | Conclusion

Introduction

In this article, I will try to explain in a simple way how a switch can be connected to FS. We will be using the newest USB interface from Velleman the K8061. You can compare it with the older K8000 but it has less I/O in- outputs. But it has the advantage of a modern USB connection in stead of the old parallel port. This isn't available any more on the newer generation PC's. We will be using a dll file witch comes with the package. We will show you how to integrate this dll file in to your visual basic program.

Hardware.

What do we need for this experiment. The K8061 card of Velleman of course. You can bay it as a ready to use card or as a kit you can put together yourself if you feel confident with soldering electronic components. What else do we need. Two pushbuttons, a on/off/on switch. A 12v adapter to connect to the K8061.

K8061

Top

Program build up.

We start with a new VB program and will name it K8061_FS. It exists out of a form and three modules. The form will have three frames, four command buttons, two checkboxes, four labels and a timer. The modules are a FSUIPC.bas module witch you can find in the FSUIPC for developers downloads. You need this basic module to be able to read and write data to FS. FSUIPC is a pay ware software from Pete Dowson. On the web page Links you can find the URL to purchase this. A second module MdlK8061 and the third module MdlWrite are written by myself. You can find the program example in the downloads web page. You can open it in VB6 and have a look on how it works. In the program itself, between the program lines, you can also find a lot of extra information about how things work.

How are we going to connect the switches, so it can communicate with FS. The first step to take is to make a connection to FS via the well known FSUIPC module. With the command button CmdFSUIPC we will make a connection between FS and the VB program.
Next step is to make a connection between the program and the K8061 interface card. With the command button CmdK8061 we will be able to make a connection to the card and view if all functions are working correct. If there would be any problem with the usb connection or power we will be notified by the different labels or checkboxes. Or by a separate message box.

If all the connections work without any problems we will start the program with the command button CmdStart.
The first thing it will do is to read out some data and check if all connection are running correctly and secondly start a timer. The timer will continuously check all changes of the K8061, and will take the necessary steps in the event off any change. If certain conditions are fulfilled, action will be undertaken. The timer will only stop when we close the form by clicking on the command button Cmdend or exit the program. With this action we also close the connection to the K8061 and we stop the connection to FSUIPC. Thanks to this timer the program stays on running in the background without anyone noticing this. From the moment you trigger a switch the program will immediately go over to action and will changes data in FS by fsuipc offsets or will send key commands. These changes are immediately seen in FS.

What are the different steps the timer makes.

Public Sub TmrWrt_Timer()

IOInput
Write_aLL

End Sub

First we look in the module MdlK8061 what the position is of the switches by executing the sub IOInput. In this sub all IO channels will get there proper data from the position of the switches. In the K8061 all inputs are high ("1") when the switches are in the off position. They become low ("0") when they are switched on. A bit different then we are used to but it isn't a problem. It is a question of agreement.

Next step we go to sub Write_aLL

Private Sub Write_aLL()
Dim booresult As Boolean
Dim dwResult As Long

'collect all data to write from write module
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Call Lbreak 'set left brakes
Call Rbreak 'set right brakes

'write direct keyboard keys
'~~~~~~~~~~~~~~~~~~~~~~~~~~

Call Flap_Up
Call Flap_Down

'FSUIPC Function write
'*********************

booresult = FSUIPC_Process(dwResult) 'pass all values to FS from switches.
DoEvents
End Sub

Here we are going to the module MdlWrite to collect all data we will send to FS by changing direct offsets or sending key inputs. These data are different depending on the IO channels data or switch position. It is here that we determine what changes we need to process. We will only send these data to FS at the end of the sub Write_aLL when we collected all data. By doing this we gain time. Only the key inputs will be send immediately. But this happens so fast that we won't notice it execpt in FS where we see the action.

In this way we continuously monitor the switches and react immediately to any changes.
This way we can connect any switch to FS.

Top

Conclusion.

Like I mentioned before, I prefer to make inputs to FS by means of joystick buttons. But there are circumstances where you need something extra. For instance when you want to make a complex decision like starting up a motor. You can combine different inputs and make complex combination before a motor can be started. This startup procedure can be written in VB. It would be very difficult or even impossible otherwise.

 

Top

 

<< Previous | Home | Articles | Next >


 
© Verley Jan 2007-2017