PDA

View Full Version : Progamming help with FSBus dll



Pages : [1] 2 3

RobiD
05-30-2009, 07:39 PM
Hi everyone,

Can anyone give me an example of the coding for a servo (RPM gauge) in FSBus dll.

If I can find an example, I should be able to replecate for the rest of my gauges.

Need coding for: examplerpm.h, examplerpm.cpp, the entry in main cockpit.cpp and stdafx.h file.

Any help would be appreciated.

Thanks
David

sgaert
05-31-2009, 04:44 AM
Hi David,

i make a untested sample for you, how to make your own Software please look to the Documentation page 22-24.
I dont know what RPM you mean. In the sample i use APU_RPM (0B54)

examplerpm.h

#ifndef __EXAMPLERPM_H
#define __EXAMPLERPM_H

#define OID_EXAMPLERPM_GROUP (10 << OID_CONTROL_BITS)
// any OID_xxx_GROUP should have a unique number, left shifted by OID_CONTROL_BITS

// declaration of all (max 32) objects of this group
#define C_RPMSERVO OID_EXAMPLERPM_GROUP + 0
#define FS_APURPM OID_EXAMPLERPM_GROUP + 1


// declare the functions in the corresponding .cpp file
void BuildEXAMPLERPMObjects();
void cbEXAMPLERPM (int oid, int val, double dval);

#endif

examplerpm.cpp


#include "stdafx.h"

void BuildEXAMPLERPMObjects()
{
MkFsbusObject (BTP_A_OUT,C_RPMSERVO, 16, 80); //Servo ports are 80-87
MakeFsObject(FS_APURPM, 0x0B54, 4, TP_UI32, FS_NORMAL); //the TP_UI32 is maybe wrong it must be a FLT32
}

void cbEXAMPLERPM (int oid, int val, double dval)
{

switch (oid)
{
case FS_APURPM:
int x = val * 2,55; //Servo need 0-255 as value, fo an other RPM you need a new caluculation
FsbusWrite (C_RPMSERVO, x);
break;
}
}

additional to the given stdafx.h

examplerpm.h


additional to the given parts of the cockpit.cpp
in funktion _tmain

BuildEXAMPLERPMObjects();
in funktion EventCallback


case OID_EXAMPLERPM_GROUP:
cbEXAMPLERPM (oid, val, dval);
break;

I hope that helps a little bit.

Regards,
Stefan

RobiD
05-31-2009, 08:19 AM
Hi Stefan,

Fantastic, I really appreciate the time you have taken in this reply.

The RPM I am referring to is the tachometer in a General Aviation plane, say a cessna or the such.

I am using the servo board for this and it has a cid 25, RID 8

I tried a couple of times to code this and was getting an 'object out of range' error message with '(80 - 87)' as you have indicated in the code.

I will give your code a try and see if I can get it to work.

Once again, I really appreciate your help.

Regards
David

Jan737
05-31-2009, 10:21 AM
Hi David,

Have you tried CID 25 RID 80.
RID 80 is the first connector and 87 the last connector of the Servo board.

Best regards

Jan Geurtsen

RobiD
05-31-2009, 06:24 PM
Wow, I didn't get that in the servo board documentation.

Thank you.

David

sgaert
06-01-2009, 02:37 AM
hi,
that is right. You can find it in the dll Docu part MakeFsbusObjekt.

Regards,
Stefan

RobiD
06-01-2009, 04:18 AM
Of course you are right. I found it after having another good look. I don't know where I was looking before.

I will put all the code together and see how I go. Hopefully it will compile without complaint and work beautifully.

Thanks for the help everyone, I'll post how I go.

David

RobiD
06-02-2009, 08:47 AM
Ok, I have spent some time trialling and testing.

I have it down to one error on compiling and that error is:

davids flight sim\enginerpm.cpp(16) : error C2059: syntax error : 'constant'

When I hold Shift + F4 the specific line is :
<CODE>
int x = val * 2,55; //Servo need 0-255 as value, fo an other RPM you need a new caluculation</CODE>

I'll post the code so far.

You will notice that I don't have this:

in funktion EventCallback

Code:


case OID_EXAMPLERPM_GROUP: cbEXAMPLERPM (oid, val, dval); break;
</PRE>

In the EventCallback function area as putting in the EventCallback was producing many more errors as it wasn't declared.

So here are the files:

cockpit.cpp

<CODE>
#include"stdafx.h"
#include<WINDOWS.H>
#include<STDIO.H>

int _tmain(int argc, _TCHAR* argv[])
{
int v = GetFsbusDLLVersion ();
if (v < 100)
{
printf ("Program requires Fsbus DLL version 1.0.0 or higher\r\n");
return 1;
}
CheckIn();
FsConnect();
FsbusOpen("COM1");

// TODO: add functions to create the fsbus software objects
cbLLSwitchboardBuildObjects();
cbEngineBuildObjects();
cbMagnetoBuildObjects();
cbEnginerpmBuildObjects();

printf ("press any key to exit ...\r\n");

while (!_kbhit())
FsbusMux(500);

CheckOut();
return 0;
}
</CODE>

stdafx.h
<CODE>
#pragmaonce
#include"targetver.h"
#include<STDIO.H>
#include<TCHAR.H>


// TODO: reference additional headers your program requires here
#include<WINDOWS.H>
#include"fsbus.h"
#define OID_LLSWITCHBOARD_GROUP (1 << OID_CONTROL_BITS)
#include"switchboard.h"
#define OID_MAGNETO_GROUP (10 << OID_CONTROL_BITS)
#include"magneto.h"
#define OID_ENGINE_GROUP (2 << OID_CONTROL_BITS)
#include"engine.h"
#define OID_ENGINERPM_GROUP (11 << OID_CONTROL_BITS)
#include"enginerpm.h"
</CODE>

enginerpm.h
<CODE>
#ifndef __ENGINERPM_H
#define __ENGINERPM_H
// any OID_xxx_GROUP should have a unique number, left shifted by OID_CONTROL_BITS
// declaration of all (max 32) objects of this group
// declare the functions in the corresponding .cpp file
void cbEnginerpmBuildObjects();
void cbEnginerpm (int oid, int val, double dval);
enum e_Enginerpm
{
C_RPMSERVO = OID_ENGINERPM_GROUP,
};
void BuildFsuipcObjects(void);
enum _fsobjectid
{
FS_ENGINE1RPM,
};
#endif
</CODE>

enginerpm.cpp

<CODE>
#include"stdafx.h"
staticint x;
void cbEnginerpmBuildObjects()
{
MkFsbusObject (BTP_A_OUT,C_RPMSERVO,"RpmGauge",cbEnginerpm, 25, 87); //Servo ports are 80-87
MkFsObject(FS_ENGINE1RPM,"RpmGauge", cbEnginerpm, 0x08C8, 2, TP_UI16, FS_NORMAL); //the TP_UI32 is maybe wrong it must be a FLT32
}
void cbEnginerpm (int oid, int val, double dval)
{
switch (oid)
{
case FS_ENGINE1RPM:
int x = val * 2,55; //Servo need 0-255 as value, fo an other RPM you need a new caluculation
FsbusWrite (C_RPMSERVO, x);
break;
}
}
</CODE>

Any help would be appreciated as I am not getting anywhere very fast.

Thanks again,
David

xlonglife
06-02-2009, 09:10 AM
You have a comma in a numeric (ie 2,55)

Shouldnt that be 2.55 or even 255?

sgaert
06-02-2009, 09:17 AM
Right, 2.55 or *100/255.

The engine need an other calculation for the rigt values. Please look to the FSUIPC SDK there you see what you need.

regards,
Stefan

RobiD
06-02-2009, 09:19 AM
Great, so simple. It compiles with a full stop or without, but certainly not with a comma.

I will now have to test if it will now run my servo driven Tacho.

I'll let you know. Thanks again for all the help.
Any other suggestions about the code would be greatly appreciated.

David

RobiD
06-02-2009, 10:16 AM
So here is an update.

Ran FSX
Then compiled project and it gave me a message in the command prompt window saying: Object-ID 0(0,0) out of range.

It appears to be the
FS_ENGINE1RPM that has an ID of 0 but I can't work out where to change it, or where it is even getting the ID from.

Any thoughts?


Stefan, could you give me an idea of what the calculation should be - In the sdk, it says the following about the offset I've used.

<TABLE dir=ltr cellSpacing=0 cellPadding=7 width=455 border=1><TBODY><TR><TD vAlign=top width="33%" height=65>08C8

</TD><TD vAlign=top width="33%" height=65>2

</TD><TD vAlign=top width="33%" height=65>Engine 1 RPM Scaler: For Props, use this to calculate RPM – see offset 0898
(On turboprops this will give the shaft RPM, since there is currently no Gear Reduction Ratio available to fix values on such aircraft. I will fix this when I can)

</TD></TR></TBODY></TABLE>

This is the other option

<TABLE dir=ltr cellSpacing=0 cellPadding=7 width=454 border=1><TBODY><TR><TD vAlign=top width="33%" height=90>0898

</TD><TD vAlign=top width="33%" height=90>2

</TD><TD vAlign=top width="33%" height=90>Engine 1 Jet N1 as 0 – 16384 (100%), or Prop RPM (derive RPM by multiplying this value by the RPM Scaler (see 08C8 and dividing by 65536). Note that Prop RPM is signed and negative for counter-rotating propellers.
In FS2004 this also now gives the Robinson model‘s RPM, when scaled by the RPM scaler.

</TD></TR></TBODY></TABLE>

I know the calculation is probably easy to work out, but I've only just delved into C++ and this is my first attemp at doing anything in C++ so I would greatly appreciate help.

Thanks again,
David

sgaert
06-02-2009, 10:25 AM
Try it "old" styl on H file:

#define C_RPMSERVO OID_EXAMPLERPM_GROUP + 0
#define FS_ENGINE1RPM OID_EXAMPLERPM_GROUP + 1

Regards,
Stefan

RobiD
06-02-2009, 10:51 AM
Thanks. It's compiling again.
Now just need to get calculation right and then test the gauge.

sgaert
06-02-2009, 11:32 AM
make an Objekt for the Eng1 Scaler (08C8) on h file.

enginerpm.cpp


#include"stdafx.h"
static int eng1scaler;

void cbEnginerpmBuildObjects()
{
MkFsbusObject (BTP_A_OUT,C_RPMSERVO,"RpmGauge",cbEnginerpm, 25, 87); //Servo ports are 80-87
MkFsObject(FS_ENGINE1RPM,"RpmGauge", cbEnginerpm, 0x0898, 2, TP_I16, FS_NORMAL); //the TP_UI32 is maybe wrong it must be a FLT32
MkFsObject(FS_ENGINE1RPMScaler,"RpmGauge", cbEnginerpm, 0x08C8, 2, TP_UI16, FS_NORMAL);
}
void cbEnginerpm (int oid, int val, double dval)
{
switch (oid)
{
case FS_ENGINE1RPMScaler:
eng1scaler = val;
break;

case FS_ENGINE1RPM:
int x = val * eng1scaler / 65536;
maybe you need a additional or other calculation. The Servo need a value range between 0-255.
FsbusWrite (C_RPMSERVO, x);
break;
}
}

The Version 2 will have funktion for such cases. But she isnt released jet.

Regards,
Stefan

RobiD
06-02-2009, 11:24 PM
'The Version 2 will have funktion for such cases. But she isnt released jet.'

Stefan, is that the Calibrate function?

If so, how would I use it in this situation?

From my understanding, it converts values 10-250 into 0-16000 and I thing the reverse way as well.

I will integrate what you have given me and see how it goes.

Thanks again
David

sgaert
06-03-2009, 02:04 AM
Hi,
yes it is the calibrat funktion.
Do you have the V2 from the dll, or you read on a board about it?

Regads,
Stefan

RobiD
06-03-2009, 02:17 AM
Hi,
yes it is the calibrat funktion.
Do you have the V2 from the dll, or you read on a board about it?

Regads,
Stefan

Hi Stefan,

I was discussing the v2 with Rob (I'm sure you know who he is) who is helpful to Dirk with testing and writing the code.

So back to the rpm gauge. Good news, it's working. FSX is sending data to the FSBus which is moving the rpm gauge. It's not correct though but at least it is working.

It is not moving very smoothly (quite jerky) and for a small increase in throttle in FSX, it produces a large increase in rpm on the gauge so what do I need to change?

Thanks again, can't wait to get this in the sim once it's sorted.

sgaert
06-03-2009, 03:17 AM
You have to find the right calculation. You need one that synchronize the Gauge on the Software Panel to the Hardware gauge.
Which aircraft do you use and what is the Value of the scaler?
What is the Servo value of the lowest and higest needle position?

Regards,
Stefan

RobiD
06-03-2009, 04:30 AM
Generic Cessna GA aircraft.

I don't know what the minimum and maximum values are for the servo but my understanding is that it's 0-255.

Where do I find the value of the scaler?

Thanks
David

sgaert
06-03-2009, 04:47 AM
If you need the full servo way for the gauge than you hav 0-255, as sample my Flap gauge needs 10-235.
The scale value is the 08C8 offset, you can use FSInterrogate2std to find out the value.

Stefan

RobiD
06-03-2009, 06:17 AM
FsAdmin gives me the values for the full travel around the rpm gauge as 9-197.

Used FSInterogate (hopefully used it correctly);

With engine stopped 08C8 Engine Scaler read in the 16bit buffer: 5660
in the Factored Buffer: 5660

With engine at full rpm 08C8 Engine Scaler read in the 16bit buffer: 10829
in the Factored Buffer: 10829

Hope this is what you mean.

Thanks
David

sgaert
06-03-2009, 07:36 AM
hi,

i think you have to use calibrate funktion from the V2.
As a fast solution you can try to divide the RMP by 10.

int x = (val * eng1scaler / 65536)/10;

That isnīt synchron to the scale, but better then the fast movements on low rpm.

Stefan

RobiD
06-04-2009, 07:27 AM
Hi Stefan,

V2 dll is possibly going to be release mid June, so only a couple of weeks away.

Do you know what the correct syntax in context would be for the Calibrate function for when it is released.

I will try the /10 option and see how is works. Can I change this number higher or lower in order to make small adjustments?

Thanks
David

sgaert
06-04-2009, 07:41 AM
Hi,
yes you can adjust that with small changes.
Dirk didnīt arnswer at the moment so i donīt know about a release date, but mid june sounds good.

Part of the V2 Doku

Calibrate
Syntax int Calibrate (int val, CALTAB* t, int count)
Sometimes it is necessary to convert a value from fsuipc into a special output value.
Think about servo applications, where the scale of a gauge is nonlinear or the servo
itself requires some corrections.
This function interpolates a value out of a table which you can supply. You can add an
arbitrary number of points to the table.
The input value must be in ascending order!
Example Example 1:
the input values from 10-250 are interpolated to 0-16000
CALTAB t[] = { {10, 16000},{ 250, 0} };
int x = Calibrate (50, t, sizeof(t)/sizeof(LITAB));
Example 2:
An fsbus control (C_XY) sends a value from 10 to 220. You translate it
into an output value from 0 to 16000.
void EventCallback (int oid, int v)
{
static CALTAB t[] = { {10, 0}, {40, 3000}, {70, 5800},
{100, 8500}, {130, 11000}, {160, 14000},
{190, 15000}, { 220, 16000} };
switch (oid)
{
case C_XY:
Fsrite (FS_CTRL, Calibrate(v, t, 8);
break;
}
}

Regardes,
Stefan

RobiD
06-05-2009, 08:34 PM
Hi Stefan,

How would I write the Calibrate function into my code in the .h file, I think I need to use this example:

CALTAB t[] = { {10, 16000},{ 250, 0} };
int x = Calibrate (50, t, sizeof(t)/sizeof(LITAB));

Where is it placed in relation to my existing code:

<code>
void cbEnginerpm (int oid, int val, double dval)
{
switch (oid)
{
case FS_ENGINE1RPMScaler:
eng1scaler = val;
break;
case FS_ENGINE1RPM:
int x = (val * eng1scaler / 65536)/10;
FsbusWrite (C_RPMSERVO, x);
break;
</code>

If I work this out, (with your help of course) when V2 is release, I should be able to integrate this into whatever code I have already written.

Thanks again,
David

sgaert
06-06-2009, 02:25 AM
Hi,

it is a little bit more to do.
I give you an example from my working Flap Gauge.


case FS_FLAPSINDICATORLEFT:
{
static CALTAB FLAPIndicator[] = {
{100,20},{420,63},{830,95},{2050,115},{4100,134},{6150,148},{10250,162},{12290,180},{16390,200}
};
val = Calibrate (val, FLAPIndicator,9);
FsbusWrite (CAO_Flaps, val);
}
break;

The Array build you can also put outside the case funtion.
The importen Step is to find out the records ({100,20}), an a scale of RPM i would do 8 to 12 pears for a smooth needle.
How you do that??
Put a print funtion in the code with the RPM (value of x) than you let everything run. Than you the the RMP on DosBox and can write down some needle positions.
sample:
RPM=1500
Servo position of 1500RPM in your gauge=120
you have a record of {1500,120}

As last delete the Print funktion.

Regards,
Stefan

RobiD
06-06-2009, 08:26 AM
Thanks Stefan, that gives me a good idea of how it works.
The old method has worked well as the actual gauge is virtually the same as the screen when I devide by 17.

I have now progress to the IAS but of course nothing ever goes smooth. From what I can tell, I have followed everything from the example you gave me and also the examples with the dll and I'm getting:
gauges.cpp(6) : error C3861: 'MakeFsObject': identifier not found

Hope you don't mind me posting the code. I know it's is probably something simple that I am just overlooking repeatedly.

gauges.h

<code>
#ifndef __GAUGES_H__
#define __GAUGES_H__
void cbGaugesBuildObjects();
void cbGauges (int oid, int val, double dval);
void BuildFsuipcObjects(void);
#endif
</code>

gauges.cpp
<code>
#include "stdafx.h"
void cbGaugesBuildObjects()
{
MkFsbusObject (BTP_A_OUT,C_IASSERVO,"IASGauge",cbGauges,25,80);
MakeFsObject (FS_IAS,"IASGauge",cbGauges, 0x02BC, 4, TP_I32, FS_QUICK);
}
static int IAS;
void cbGauges (int oid, int val, double dval)
{
double dbl;
int x;
switch (oid)
{
case FS_IAS:
if (IAS != (val/128))
{
IAS = val / 128;
}
x = 250 - IAS;
x = x < 40 ? 40 : x;
FsbusWrite(C_IASSERVO, x);
break;
}
}
</code>

cockpit.cpp
<code>
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
int v = GetFsbusDLLVersion ();
if (v < 100)
{
printf ("Program requires Fsbus DLL version 1.0.0 or higher\r\n");
return 1;
}
CheckIn();
FsConnect();
FsbusOpen("COM1");

// TODO: add functions to create the fsbus software objects
cbLLSwitchboardBuildObjects();
cbEngineBuildObjects();
cbMagnetoBuildObjects();
cbEnginerpmBuildObjects();
cbGaugesBuildObjects();

printf ("press any key to exit ...\r\n");

while (!_kbhit())
FsbusMux(500);

CheckOut();
return 0;
}
</code>

stdafx.h

<code>
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>


// TODO: reference additional headers your program requires here
#include <windows.h>
#include "fsbus.h"
#define OID_LLSWITCHBOARD_GROUP (1 << OID_CONTROL_BITS)
#include "switchboard.h"
#define OID_MAGNETO_GROUP (10 << OID_CONTROL_BITS)
#include "magneto.h"
#define OID_ENGINE_GROUP (2 << OID_CONTROL_BITS)
#include "engine.h"
#define OID_ENGINERPM_GROUP (11 << OID_CONTROL_BITS)
#include "enginerpm.h"
#define C_RPMSERVO OID_ENGINERPM_GROUP + 0
#define FS_ENGINE1RPM OID_ENGINERPM_GROUP + 1
#include "gauges.h"
#define OID_GAUGES_GROUP (15 << OID_CONTROL_BITS)
#define FS_IAS OID_GAUGES_GROUP +3
#define C_IASSERVO OID_GAUGES_GROUP +0
</code>

Hope you have time to check it out.

Thanks again.
David

sgaert
06-06-2009, 10:19 AM
From what I can tell, I have followed everything from the example you gave me and also the examples with the dll and I'm getting:
[SIZE=1]gauges.cpp(6) : error C3861: 'MakeFsObject': identifier not found


No problem, it is:
MakeFsObject (FS_IAS,"IASGauge",cbGauges, 0x02BC, 4, TP_I32, FS_QUICK);
right is:
MakeFsObject (FS_IAS, 0x02BC, 4, TP_I32, FS_QUICK);

The part of ""IASGauge",cbGauges" you need in V2 not V1.

Regards,
Stefan

RobiD
06-06-2009, 10:26 AM
Tried that and got the same error.
Any other thoughts?

Thanks
David

sgaert
06-06-2009, 11:54 AM
I have read the complet thread again, what versin of the DLL you have?
Please give me the date and time of the fsbus.dll file.
At post 8 you write V2 Code.
Than it isnt the MakeFsObject Funktion, it is MkFsObject.

Regards,
Stefan

RobiD
06-07-2009, 01:01 AM
Hi Stefan,

Thanks for your help again, IAS is now working. 0 knots is 0 knots but my physical gauge is progressively behind the onscreen IAS.

I have changed the x = x < 40 ? 40 : x;
to
x = x < 10 ? 10 : x;
and this seems to have aligned the 0 knots point.
Where else would I adjust to increase the equation would I alter to change the rate or would I be better off figuring out how to use the Calibrate function.

This is what I have now:
if (IAS != (val/128))
{
IAS = val / 128;
}
x = 000 + IAS;
x = x < 10 ? 10 : x;
FsbusWrite(C_IASSERVO, x);

About the version dll that I have.
It's a long story but here goes.
I had been trying to download the dll version from Dirks site for sometime and I was having trouble downloading the FSAdmin tool - the site said 1.8mb but when it downloaded, it was only 150kb (when I tried to execute it, it would give and error).

I had left messages on Avsim, FSMagazine, even email Norbert Bosch (who I know uses FSBus) for help with this problem, with no answer.
I then contacted Rob and he said to leave it with him and he would contact Dirk.
About a week later Rob then offered me the beta version of V2 to test and get used to before the final release in mid June under strict conditions that it was only for my use and not to be shared (as I have done).

I hope this doesn't cause any problems for anyone as this is only for me.

Thanks again.
David

sgaert
06-07-2009, 03:17 AM
hi,
that ist ok. iīm also a betatester.
In that case you can try the calibrate funktion for your RPM Gauge.
Maybe it is interessting for you, Rob has made some code for an other group build. Now he has 16 groups with 256 objekts. If you what, i give you the code.
We donīt share the dll or lib file only the own code and that is ok.

Regards,
Stefan

RobiD
06-07-2009, 06:13 AM
Hi Stefan,

Is that Robs code: RVDB737NG. If it is, he has given it to me to help me get my head around C++ and FSBus dll.

If it is not, I would be grateful to view more of his code as what I have now has helped enormously.

I must also say, that without your assistance, I may have given this up as too hard, but it is great to see my gauges coming to life and hopefully soon, my whole cockpit.

I'm quite ok with how the RPM gauge is working. It is very acurate to the screen gauge.

Just probably need to use it for the IAS (so far).
I have gone through the code Rob has given me and I can't see a Calibrate Function in it to see how it is correctly put in the file.


Could you give me some pointers for putting the calibrate function into the gauges.cpp file.

Do I replace:

<code>case FS_IAS:
if (IAS != (val/128)
{
IAS = val / 128;
}
x = 250 - IAS;
x = x < 40 ? 40 : x;
FsbusWrite(C_IASSERVO, x);
break;
}
}
</code>

with

<code>case FS_FLAPSINDICATORLEFT:
{
static CALTAB FLAPIndicator[] = {
{100,20},{420,63},{830,95},{2050,115},{4100,134},{6150,148},{10250,162},{12290,180},{16390,200}
};
val = Calibrate (val, FLAPIndicator,9);
FsbusWrite (CAO_Flaps, val);
}
break;</code>

and what changes do I need to make:
I know FS_IAS: at the start
but what do I replace FLAPIndicator with - IASIndicator and if I do, do I need to declare IASIndicator.
What do I replace CAO_Flaps with?

Thanks for the help.
David

sgaert
06-07-2009, 06:43 AM
hi,
the FLAPIndicator is only the lable from the array.
You can chouse what you want.
Tha Calibrate funktion work like that:
x = Calibrate (a,b,c);

x are the back value of the funktion
a is the input value
b is the Label of used Array
c is how many records in used Array


What do I replace CAO_Flaps with?
With your C_IASSERVO.

Yes i mean Robs code. For me personal is the C++ more easy than the CDK. Why? The CDK isnīt a logic programming envioment and it is so slow.

Regards,
Stefan

RobiD
06-07-2009, 08:42 AM
Wow, that was really easy to do.
I now have an acurate IAS.
Humm, which gauge to do next!!!

Thank you again.

David

Jan737
06-07-2009, 10:36 AM
Hi David and Stefan,

I have a question about the smoothness of the needle.
With the version 1 of the dll I've tried to make a 737 flap gauge, but the needle moves very quick between the Flap positions.
Is this better with the second version and can you adjust the needle speed?


Best regards

Jan Geurtsen

sgaert
06-07-2009, 10:45 AM
Hi Jan,
at my post #27 you can see my V2 Code from the flaps.
Her are a movie of the movment.
Flapgauge (http://picasaweb.google.de/sgaert/MIP#5342424313298052114)
The first Part is also quick but this is the fast moveing between 0 and 5 degrees.

regards,
Stefan

Jan737
06-07-2009, 01:20 PM
Hi Stefan,

Yes,that's look better! Is it your choice, to move the needle quick to the flap 5 position?


Best regards

Jan Geurtsen.

sgaert
06-07-2009, 03:45 PM
HI,
no that is FSX. But that are only 5 degrees, that will go fast.

Regard,
Stefan

RobiD
06-07-2009, 09:09 PM
Jan,
Stefan is the expert, I'm just learning my way through it.

I have another question Stefan.

I have coded my turn coordinator ball and it compiled without any trouble.
I am using the calibrate function.

I am getting all weird movements on the ball. I wrote a print function and viewed the 0x036E offset and have used FSInterogate.

Previous documentation state (V1) that the numbers go from -127 to 128
In the print function I did get similar numbers but without the minus part.
FSInterogate only gave me minus numbers in the Factored column.

I got it working really easy but can't get it to behave.

Here's the code I've got so far:

<code>
case FS_TURNCOORD:
{
static CALTAB TURNCORDINATORIndicator [] = {
{-127,7},{-100,15},{-60,30},{-30,40},{0,45},{30,55},{60,65},{100,75},{128,85}
};
val = Calibrate (val, TURNCORDINATORIndicator,9);
FsbusWrite (C_TURNCOSERVO, val);
}
break;
</code>

Hope you can help.

David

RobiD
06-07-2009, 10:13 PM
Hmm, that's weird. With the print function, I am getting numbers ascending and descending from 130ish thought to zero and on to 130ish.
There isn't any minus as there should be. should be between -128 and 128

So my turn ball moves and stays only on the right side.

sgaert
06-08-2009, 01:42 AM
Hi,
is your FS_TURNCOORD objekt TP_I8???

Regards,
Stefan

RobiD
06-08-2009, 05:12 AM
Yes it is.

The numbers coming out of FSX don't seem right.

I put a print function on the Turn rate to see if it gave negative numbers and it gave from -512 to +512.

The turn coordinator only gives positive numbers but it should be -128 to +128.

sgaert
06-08-2009, 05:35 AM
If you look on 0x036E with FSInterogate, do you see negativ Values?

RobiD
06-08-2009, 05:37 AM
FSInterogate only gave me minus numbers in the Factored column.

sgaert
06-08-2009, 05:48 AM
Ok i will check that after work.
What shows FSInterogate on the 8bit column?

RobiD
06-08-2009, 06:00 AM
I did it about 9 hours ago so I don't remember off the top of my head but
I'll do it again and give you the numbers. Should take about 10 mins.

RobiD
06-08-2009, 06:14 AM
Standing still on the runway, I get 254 in the 8 bit box and -2 in the factored box.

Hard right rudder (ball hard left) produces 131 in the 8 bit box and -125 in the factored box.

Hard left rudder (ball hard right) produces 126 in the 8 bit box and 126 in the Factored box. (the numbers droped down through 0 then up again as the ball crossed the center)

Ok, that strange.

0 centered first numbers on turning left (ball to the right) is 255 and then reduces the harder the ball moves to the right.

The same the other way so it looks like this:

0-<--100<----255-centered-255--->100--->--0

sgaert
06-08-2009, 07:18 AM
Ok that ist realy strange.
I donīt see a way to readout the factored field.
Did you try an other aircraft?
Last way is to ask Pete about the Offset.

Regards,
Stefan

RobiD
06-08-2009, 08:34 AM
Thanks Stefan.

My brain is fried for the night. I now have VSI, RPM, IAS, Turn rate and sort of turn cooordinator done and working.

I will try it again tomorrow and if I have no better luck, I will email Pete and see what he says.

The last time I emailed him, it must have been a stupid question, as he was quite short with me.

I also want to get my Glideslope indicator done tomorrow. Just to check that I have the right off sets:

MkFsObject(FS_NAV1LOCALISER, 0x0C48, 1, TP_I8, FS_NONE);
MkFsObject(FS_NAV1GLIDESLOPE, 0x0C49, 1, TP_I8, FS_NONE);

or

MkFsObject(FS_NAV2GLIDESLOPENEEDLE, 0x0C6E, 1, TP_I8, FS_NONE);
MkFsObject(FS_NAV2LOCALISERNEEDLE, 0x0C59, 1, TP_I8, FS_NONE);

This is for the gauges with the 2 crossed needles for ILS landing. Not sure which ones I should be using.

David

sgaert
06-08-2009, 08:49 AM
Hi.
normaly a GA aircraft has only ILS on NAV1. In that case you use the first one.

Stefan

sgaert
06-08-2009, 01:52 PM
Hi,
i had some test flights with the default GA Aircrafts from the FSX and find other output values on the 8 bit column.

I write them in you "style".
129-<--200<----255-centered-0--->100--->--128

please check them. With this values you can work with calibrate funktion.

Regards,
Stefan

sgaert
06-08-2009, 04:47 PM
Hi,
Dirk has released the Version 2 of the DLL.

Regards,
Stefan

RobiD
06-08-2009, 07:20 PM
Hi Stefan,

Downloading V2 as I type.

This is an unusual way for the numbers to come out, but I can see that using what you have given me, I should be able to build a table that works.

I will let you know.

Quick question. I have a dual boot machine. I keep the second harddrive with minimum software on it purely for FlightSim. I have been doing all the coding on the other system/drive.

What do I need to copy over to the FlightSim harddrive for FSBus dll to work.

I tried last night: put dll file in system32 folder, put my .exe cockpit file on the second drive. Installed FSBus dll on the drive, Started Flight sim, executed the exe cockpit file and got configuration error.
Do I need to also have Visual Studio installed as well.

This thread will be a great tool for those who are programming FSBus dll V2.

David

RobiD
06-09-2009, 12:51 AM
Appear to have got the table right thanks to Stefan.
For anyone else having trouble sorting this one out, here is what I finished up with:

static CALTAB TURNCORDINATORIndicator [] = {
{0,96},{30,101},{60,110},{100,117},{128,126},{129,57},{149,62},{160,69},{230,76},{255,86}
};
val = Calibrate (val, TURNCORDINATORIndicator,9);
FsbusWrite (C_TURNCOSERVO, val);

The table has to run in ascending order so I had to move the end half to the front. My servo numbers run from 57 far left to 126 far right.

RobiD
06-09-2009, 12:58 AM
Stefan,

Here's another question that I can't seem to find the answer to.

I am using a keyed electrical switch (which is 4 seperate switches enclosed in the housing) for my ignition switch.
off-left-right-both-start.

I have used the Magneto example in Dirks documents and it works well except for when one switch breaks contact, the onscreen switch moves backwards until the next physical switch makes contact then the screen switch moves forward two positions.

So FSBus is registering the on and the off (1/0).
How do I code it so the on screen switch doesn't move backwards when it breaks contact in the physical switch.

Hope you understand what I mean.

Thanks
David

sgaert
06-09-2009, 01:43 AM
What do I need to copy over to the FlightSim harddrive for FSBus dll to work.
You only overwrite the old .h, .dll and .lib file.


I tried last night: put dll file in system32 folder, put my .exe cockpit file on the second drive. Installed FSBus dll on the drive, Started Flight sim, executed the exe cockpit file and got configuration error.
Do I need to also have Visual Studio installed as well.

Please look to the last page of the fsbusdll.pdf.

At Dirkīs sample you have the order of off-right-left-both-start. The right makes a toggle between values and the rest set a value. Please check your order.

Regards,
Stefan

RobiD
06-09-2009, 05:28 AM
Hi Stefan,

Yes the order is right. I just wrote it wrong.

Any other thoughts on what I can do to stop it jumping?

Thanks
David

RobiD
06-09-2009, 07:11 AM
A bit more investigation and it may be the DIO board. Pins 0 to 3 are used for the magneto.
Now with everything unplugged FSbus and FSX running, engine running, randomly the green led lights then the red led displays its CID number, the green lights up again and the motor stops. But there is nothing plugged into the board except the bus cable.

On several occasions I've had to reflash the CID number to the DIO as somehow it changed itself to 31 so the switches etc stopped working.

I removed the magnto code, recompiled now the engine isn't stopping but the CID is still randomly displayed on the DIO.

Any thoughts on this one too.

sgaert
06-09-2009, 07:49 AM
Yes i know that problem.
Erase the complet Controller with PonyProg and write them new.

Regards,
Stefan

RobiD
06-10-2009, 07:35 AM
Great. Fixed problem.

Now to start on the Glideslope indicator, then the Attitude indicator which is servo for pitch and stepper for bank.

David

sgaert
06-10-2009, 07:44 AM
Hi,
sounds good. Why do you use a stepper for bank?
I use also a Servo.

regards,
Stefan

RobiD
06-10-2009, 08:34 AM
It seemed like a good idea at the time because I thought it could move continuously around but I forgot about the wires for the pitch servo.

I could still change it I guess. It would mean making modification only to the very rear deck (I've used Mike's Flightdeck design).

dvincent
06-10-2009, 06:52 PM
Hi all,

in case of problems with FsBus, you can take a look on the website of Rob van Dijk. Together with Dirk Anderseck, he developped the software + PCB's.

http://www.rvdijk.nl/

Greetz,

Dirk

RobiD
06-11-2009, 06:46 AM
Stefan,

Just when I thought I was on a roll of just adding gauges and them working, I've hit another snag. Hope you can help.

The problem is with the Glideslope and Localiser needles.

The servos are fine, all set up in FSAdmin.

The code compiles without error.

I am getting no response from them when I'm in FSX.

Here is the code. ***I have left out unneccessary code that we know works, this is just what I have added for this gauge.

Thanks
David

gauges.h (this is the same as before as I'm declaring the objects in stdafx.h)

<code>
#ifndef __GAUGES_H__
#define __GAUGES_H__
void cbGaugesBuildObjects();
void cbGauges (int oid, int val, double dval);
void BuildFsuipcObjects(void);
#endif
</code>

gauges.cpp

<code>
MkFsbusObject (BTP_A_OUT,C_NAV1LOCSERVO,"Localiser Needle",cbGauges,25,83);
MkFsbusObject (BTP_A_OUT,C_GLIDESLOPESERVO,"Glideslope Needle",cbGauges,25,84);

MkFsObject(FS_NAV1LOCALISER,"Localiser needle",cbGauges, 0x0C48, 1, TP_I8, FS_NONE);
MkFsObject(FS_NAV1GLIDESLOPE,"Glideslope Needle",cbGauges, 0x0C49, 1, TP_I8, FS_NONE);




case FS_NAV1LOCALISER:
{
static CALTAB NAV1LOCALISERIndicator [] = {
{-127,166},{0,89},{127,25}
};
val = Calibrate (val,NAV1LOCALISERIndicator,9);
FsbusWrite (C_NAV1LOCSERVO, val);
}
break;
case FS_NAV1GLIDESLOPE:
{
static CALTAB NAV1GLIDESLOPEIndicator [] = {
{0,141},{118,50},{138,240}
};
val = Calibrate (val,NAV1GLIDESLOPEIndicator,9);
FsbusWrite (C_GLIDESLOPESERVO, val);
}
break;
</code>


stdafx.h

<code>
#define FS_NAV1LOCALISER OID_GAUGES_GROUP +9
#define C_NAV1LOCSERVO OID_GAUGES_GROUP +10
#define FS_NAV1GLIDESLOPE OID_GAUGES_GROUP +11
#define C_GLIDESLOPESERVO OID_GAUGES_GROUP +12
</code>

sgaert
06-11-2009, 07:02 AM
Hi,
as first 2 big errors, you dont have 9 records on array.
Please typ
val = Calibrate (val,XXXXX,3);
XXXXX= your lable.

As next, you must enable the FSUIPC polling.
Dont type FS_NONE, you have to use NORMAL or QICK.

Regards,
Stefan

RobiD
06-11-2009, 07:13 AM
So for future reference, the number at the end is the number of arrays you have in the table (val = Calibrate (val,XXXXX,3);)

I've made the changes you suggested but still no response from the servos.

Any other thoughts.

Do you want me to post the entire gauges.cpp, gauges.h and stdafx.h files?

Thanks
David

sgaert
06-11-2009, 07:19 AM
gauges.cpp


MkFsbusObject (BTP_A_OUT,C_NAV1LOCSERVO,"Localiser Needle",cbGauges,25,83);
MkFsbusObject (BTP_A_OUT,C_GLIDESLOPESERVO,"Glideslope Needle",cbGauges,25,84);

MkFsObject(FS_NAV1LOCALISER,"Localiser needle",cbGauges, 0x0C48, 1, TP_I8, FS_NORMAL);
MkFsObject(FS_NAV1GLIDESLOPE,"Glideslope Needle",cbGauges, 0x0C49, 1, TP_I8, FS_NORMAL);




case FS_NAV1LOCALISER:
{
static CALTAB NAV1LOCALISERIndicator [] = {
{-127,166},{0,89},{127,25}
};
val = Calibrate (val,NAV1LOCALISERIndicator,3);
FsbusWrite (C_NAV1LOCSERVO, val);
}
break;
case FS_NAV1GLIDESLOPE:
{
static CALTAB NAV1GLIDESLOPEIndicator [] = {
{0,141},{118,50},{138,240}
};
val = Calibrate (val,NAV1GLIDESLOPEIndicator,3);
FsbusWrite (C_GLIDESLOPESERVO, val);
}
break;

RobiD
06-11-2009, 08:29 AM
Hummm, not sure what happened, I made the changes you suggested and nothing happened, then I fiddled a bit with the code but didn't really change anything, and now it works.

Thanks as always for your help Stefan.

Regards
David

sgaert
06-11-2009, 06:58 PM
hehe, that sounds crazy but it is good.
I like to help.

Regards,
Stefan

RobiD
06-15-2009, 01:49 AM
Hi Stefan,

Back in the land of the internet. Been away for the weekend.

I am now programming in the GS Indicator (LED) and the To/From (2 leds) indicators.

This is what I am declaring in stdafx.h

#define FL_NAV1GSFLAG OID_GAUGES_GROUP +13
#define C_LEDGLIDESLOPEFLAG OID_GAUGES_GROUP +14

Then in Gauges.cpp

MkFsbusObject (BTP_D_OUT, C_LEDGLIDESLOPEFLAG,"Glideslope Flag LED",cbGauges,22,51);
MkFsObject(FS_NAV1GSFLAG,"Glideslope Flag LED",cbGauges, 0x0C4C, 1, TP_I8, FS_NORMAL);

What do I need to enter ie: **I know this isn't correct, it's just a copy and paste of an example as I'm not sure what it should say.

staticvoid GlideslopeflagLed()
{
for (int i=0; i<8; i++)
{
switch (i)
{
case 0:
FsbusWrite (C_LEDGLIDESLOPEFLAG, (ra & (1<<I)) 1:0 ? font );<>
break;


Next question:

The To/From flags.

I can only find this offset:
MkFsObject(FS_NAV1TOFROM, "", cb__, 0x0C4B, 1, TP_I8, FS_NONE);

So how do I make this offset trigger one led for "to" and a different led for "from"

As always, thanks for your help.

David

sgaert
06-15-2009, 02:00 AM
Hi,

The Led output i do diferent.

case FS_NAV1GSFLAG:
FsbusWrite (C_LEDGLIDESLOPEFLAG, val);
break;

case FS_NAV1TOFROM:
if (val==0)
{
FsbusWrite (C_LEDFROM, val);
FsbusWrite (C_LEDTO, val);
}
else if (val==1)
{
FsbusWrite (C_LEDFROM, 0);
FsbusWrite (C_LEDTO, 1);
}
else if (val==2)
{
FsbusWrite (C_LEDFROM, 1);
FsbusWrite (C_LEDTO, 0);
}
break;

Try that.

Regards,
Stefan

RobiD
06-15-2009, 02:28 AM
Hi Stefan,

Looks pretty good.

I'm getting 1 error on compiling:
gauges.cpp(91) : error C2196: case value '493' already used

Which is this line:

case FS_NAV1GSFLAG:
FsbusWrite (C_LEDGLIDESLOPEFLAG,val);
break;

I have to also have a good look at my DIO board as the voltage coming out of J5 and J4 is only 0.2 volts. I am using 180 ohm resistors, so there is not enough voltage to light the leds (any thoughts on this one?)

sgaert
06-15-2009, 02:35 AM
gauges.cpp(91) : error C2196: case value '493' already used

Do you have an other "case FS_NAV1GSFLAG:" line??


J5 and J4 is only 0.2 volts.
You are sure that the right jumper is closed?

Regards,
Stefan

RobiD
06-15-2009, 03:38 AM
No, there is only 1 case FS_NAV1GSFLAG: line.



<quote>J5 and J4 is only 0.2 volts.

You are sure that the right jumper is closed?</quote>

What do you mean by "right Jumper" should I have a shunt on a jumper somewhere to boost the voltage?

David

sgaert
06-15-2009, 04:02 AM
Hi,
in you Project is the case value already used. You have to find where.

Please look to the Schematic Drawing of the DIO Board (Doku page 5).
There you can see, J14 and J15 with this Jumpery you can give 5V to J4 and J5.

Regrads,
Stefan

RobiD
06-15-2009, 04:16 AM
By case value do you mean:
case FS_NAV1GSFLAG:

This entire line? If so, it doesn't appear anywhere else in my project.


On the DIO board, do I need to jumper J14 and J15 (if so which pins?) or do I need to supply external power?

sgaert
06-15-2009, 04:23 AM
This entire line? If so, it doesn't appear anywhere else in my project.

Is it possible that you have "OID_GAUGES_GROUP +13" at 2 diferent objekts?


On the DIO board, do I need to jumper J14 and J15 (if so which pins?) or do I need to supply external power?
Look at the picture from Robs website, there are the right jumper position.
Picture (http://www.rvdijk.nl/images/PCB_RVD_IO_2.JPG)

Regards,
Stefan

RobiD
06-15-2009, 04:55 AM
Is it possible that you have "OID_GAUGES_GROUP +13" at 2 diferent objekts?

Yes I do. Thanks and now it compiles.



Look at the picture from Robs website, there are the right jumper position.
Picture (http://www.rvdijk.nl/images/PCB_RVD_IO_2.JPG)


Rob's pins are horizontal and mine are vertical but I'll work it out.


Thanks again,
David

RobiD
06-15-2009, 06:21 AM
Stefan,

Where do I find the RID numbers for J5 on the DIO. I can find the 0-63 for keys and 72-79 for J3 in the DIO manual but I can't find J4 and J5.

David

sgaert
06-15-2009, 06:25 AM
It is to easy, 0-15.
http://www.rvdijk.nl/images/RVD_PCB_FSBUS_IO_Connectors.JPG

RobiD
06-15-2009, 06:42 AM
It is to easy, 0-15.
http://www.rvdijk.nl/images/RVD_PCB_FSBUS_IO_Connectors.JPG


0-63 on the DIO board is the key inputs (switches and such). I have 0-5 already assigned to switches.

RobiD
06-15-2009, 06:48 AM
Oh, just got it. 0-63 for the keys are "in" 0-15 are "out"

Thanks

RobiD
06-15-2009, 07:44 AM
Tested it out with FSX.
GS indicator comes on when your on or approaching the GS.

The "to" light is on. (not sure how to get the "from" indicator to light up to test it).

Very happy about how things are going so far.

sgaert
06-15-2009, 07:49 AM
not sure how to get the "from" indicator to light up to test it
Use a VOR fly to or away from them.

RobiD
06-15-2009, 11:18 PM
Great, it works perfectly.

For my next great acheivement (of course with your help), I want to do the Master Battery, Alternator, Avionics switches and the fuel pump switch.

I have tried to find a simple example in Robs project and also the cockpit project example, and I can't find a good single switch example.

Here's were I'm at:

switches.h

<code>
#ifndef __SWITCHES_H__
#define __SWITCHES_H__
void cbSwitchesBuildObjects();
void cbSwitches (int oid, int val, double dval);
#endif
</code>

switches.cpp

<code>
#include "stdafx.h"
void cbSwitchesBuildObjects()
{
MkFsbusObject (BTP_D_IN,C_SWITCH_ALTERNATOR,"MasterAltSwitch",cbSwitches,27,57);
MkFsbusObject (BTP_D_IN,C_SWITCH_MASTERBATT,"MasterBattSwitch",cbSwitches,27,56);
MkFsbusObject (BTP_D_IN,C_SWITCH_MASTERAVIONICS,"MasterAvionicsSwitch",cbSwitches,27,55);
MkFsbusObject (BTP_D_IN,C_SWITCH_FUELPUMP,"FuelboostPumpSwitch",cbSwitches,27,58);

MkFsObject(FS_ALTERNATOR,"MasterAlternatorSwitch",cbSwitches, 0x3101,1,TP_I8,FS_NORMAL);
MkFsObject(FS_MASTERBATTERYSWITCH,"MasterBattSwitch",cbSwitches, 0x281C, 4, TP_I32, FS_NORMAL);
MkFsObject(FS_MASTERAVIONICSSWITCH,"MasterAvionicsSwitch",cbSwitches, 0x2E80, 4, TP_I32, FS_NORMAL);
MkFsObject(FS_FUELPUMP,"FuelBoostPumpSwitch",cbSwitches, 0x3104, 1, TP_I8, FS_NORMAL);
}
</code>


stdafx.h

<code>
#include "switches.h"
#define OID_SWITCHES_GROUP (17 << OID_CONTROL_BITS)
#define C_SWITCH_ALTERNATOR OID_SWITCHES_GROUP +1
#define FS_ALTERNATOR OID_SWITCHES_GROUP +2
#define C_SWITCH_MASTERBATT OID_SWITCHES_GROUP +3
#define FS_MASTERBATTERYSWITCH OID_SWITCHES_GROUP +4
#define C_SWITCH_MASTERAVIONICS OID_SWITCHES_GROUP +5
#define FS_MASTERAVIONICSSWITCH OID_SWITCHES_GROUP +6
#define C_SWITCH_FUELPUMP OID_SWITCHES_GROUP +7
#define FS_FUELPUMP OID_SWITCHES_GROUP +8
</code>


What arguments (if that's the correct terminology) do I need to put in the switches.cpp file to complete it?

As it is, when I compile, I get these two errors:


switches.obj : error LNK2001: unresolved external symbol "void __cdecl cbSwitches(int,int,double)" (?cbSwitches@@YAXHHN@Z)
1>C:\Documents and Settings\David\My Documents\Visual Studio 2008\Projects\Davids Flight sim\Debug\Davids Flight sim.exe : fatal error LNK1120: 1 unresolved externals

Thanks again,
David

sgaert
06-16-2009, 01:51 AM
hi,
as first i found.
Master Battery switch = 0x3102
Avionics switch = 0x3103

switches.cpp


#include"stdafx.h"
void cbSwitchesBuildObjects()
{
MkFsbusObject (BTP_D_IN,C_SWITCH_ALTERNATOR,"MasterAltSwitch",cbSwitches,27,57);
MkFsbusObject (BTP_D_IN,C_SWITCH_MASTERBATT,"MasterBattSwitch",cbSwitches,27,56);
MkFsbusObject (BTP_D_IN,C_SWITCH_MASTERAVIONICS,"MasterAvionicsSwitch",cbSwitches,27,55);
MkFsbusObject (BTP_D_IN,C_SWITCH_FUELPUMP,"FuelboostPumpSwitch",cbSwitches,27,5;

MkFsObject(FS_ALTERNATOR,"MasterAlternatorSwitch",cbSwitches, 0x3101,1,TP_I8,FS_NORMAL);
MkFsObject(FS_MASTERBATTERYSWITCH,"MasterBattSwitch",cbSwitches, 0x281C, 4, TP_I32, FS_NORMAL);
MkFsObject(FS_MASTERAVIONICSSWITCH,"MasterAvionicsSwitch",cbSwitches, 0x2E80, 4, TP_I32, FS_NORMAL);
MkFsObject(FS_FUELPUMP,"FuelBoostPumpSwitch",cbSwitches, 0x3104, 1, TP_I8, FS_NORMAL);
}

void cbSwitches (int oid, int val, double dval);
{
switch (oid)
{
case C_SWITCH_ALTERNATOR:
FsWrite (FS_ALTERNATOR, !val); // i donīt know whether that work
break;
}
}

If that not work you have to do the long form, like at the LED part from yesterday.

Regards,
Stefan

RobiD
06-16-2009, 02:13 AM
Hi Stefan,

I'm getting this error message on compiling:

switches.cpp(17) : error C2447: '{' : missing function header (old-style formal list?)

sgaert
06-16-2009, 02:21 AM
my fault.

void cbSwitches (int oid, int val, double dval)

RobiD
06-16-2009, 02:25 AM
It's always something simple. Compiled fine.

I'll test that it works in FSX then add the other switches.

Thanks
David

RobiD
06-16-2009, 02:53 AM
Stefan,

In the DOS box, I am getting error message:

FSBUS DLL:
ObjectID-551(17,7) still in use
press any key to exit....


Any ideas what that means?

I have only just started FSX and only just powered up my boards and only just run the .exe (through compiling)

sgaert
06-16-2009, 02:59 AM
That mean you have twice the same object ID.
The message also say what object.
Group: 17
Object: 7

RobiD
06-16-2009, 03:05 AM
Is this where I should be looking?

The message is referring to the C_SWITCH_FUELPUMP OID_SWITCHES_GROUP +7

#include "switches.h"
#define OID_SWITCHES_GROUP (17 << OID_CONTROL_BITS)
#define C_SWITCH_ALTERNATOR OID_SWITCHES_GROUP +1
#define FS_ALTERNATOR OID_SWITCHES_GROUP +2
#define C_SWITCH_MASTERBATT OID_SWITCHES_GROUP +3
#define FS_BATTERY OID_SWITCHES_GROUP +4
#define C_SWITCH_MASTERAVIONICS OID_SWITCHES_GROUP +5
#define FS_AVIONICS OID_SWITCHES_GROUP +6
#define C_SWITCH_FUELPUMP OID_SWITCHES_GROUP +7
#define FS_FUELPUMP OID_SWITCHES_GROUP +8

RobiD
06-16-2009, 11:28 PM
Hi Stefan,

I've done a bit of detective work and this is what I've found. Yes, I did have a duplicate Fuel offset (I was experimenting weeks ago and forgot to delete it.

So now the project compiles.

All of the switches work ie: Master Battery, avionics and alternator and fuel pump.
Interestingly, if I turn the fuel pump switch on, if I use any of the above switches,(except the Alternator switch) not only does it turn the switch that it's meant to turn on, but it also switches off the fuel pump.

It does the same even if I // out all lines relating to the fuel pump.

sgaert
06-17-2009, 01:43 AM
ok, in that case i would make an if - else like at the LEDīs.

RobiD
06-17-2009, 04:41 AM
Stefan,

Can you give me an example.

In the LEDs, I only have :

case FS_NAV1GSFLAG:
FsbusWrite (C_LEDGLIDESLOPEFLAG, val);
break;


Which I've used,

For the To/From LEDs, I have the if - else

case FS_NAV1TOFROM:
if (val==0)
{
FsbusWrite (C_LEDFROM, val);
FsbusWrite (C_LEDTO, val);
}
else if (val==1)
{
FsbusWrite (C_LEDFROM, 0);
FsbusWrite (C_LEDTO, 1);
}
else if (val==2)
{
FsbusWrite (C_LEDFROM, 1);
FsbusWrite (C_LEDTO, 0);
}
break;

But it's to light 2 leds from the one offset.

Thanks
David

sgaert
06-17-2009, 04:59 AM
case C_SWITCH_ALTERNATOR:
if (val==0)
FsWrite (FS_ALTERNATOR, 1);
else
FsWrite (FS_ALTERNATOR, 0);
break;

RobiD
06-17-2009, 05:22 AM
Thanks Stefan,

That works for all the switches but the same problem persists.

The Batt and Avionics switch turns off the fuel pump (that is whether you turn the switch on or off, if you turn the fuel pump switch on, whichever way your turn the Batt or Avionics switch, it turns the fuel pump off). It won't turn it on, it just turns it off.

Tha Master Alt switch does not turn the fuel pump off. I can't see what I've done differently for the Alt switch.

Any other thoughts?

Thanks
David

RobiD
06-17-2009, 06:17 AM
Ok, I'm totally confused.

I deleted all of my switches and started from scratch.
I moved the fuel pump switch to a different group completely, and re-wrote the Master switches from scratch.

The group that I moved the fuel pump to does not affect the fuel pump switch but the same ones as before still change the fuel pump ie: MasterBatt, MasterAvionics.

Very confusing.

RobiD
06-18-2009, 08:01 AM
I moved the fuel pump switch to a different group and made sure they all worked right. Then I re-wrote the other switches file one switch at a time and tested it to make sure it wasn't affecting the fuel pump switch again and slowly but surely I rebuilt the file and it now works.

Not sure what the problem was, but it doesn't matter now.

Thanks again for your help.

David

RobiD
06-19-2009, 09:46 PM
Hey Stefan,

Need your help again if your willing. (or anyone else who knows Fsbus dll well.

I am now programming my fuel, oil press, temp, amps and fuel pressure gauges (6 in all).

They are aircore (voltmeters) and there is no example in the documentation to use.

I am starting with Left fuel gauge. Offset is


<TABLE dir=ltr style="WIDTH: 504px; HEIGHT: 66px" cellSpacing=0 cellPadding=7 width=504 border=1><TBODY><TR><TD vAlign=top width="33%" height=12>0B7C
</TD><TD vAlign=top width="33%" height=12>4
</TD><TD vAlign=top width="33%" height=12>Fuel: left main tank level, % * 128 * 65536
</TD></TR></TBODY></TABLE>

I need an example calculation for this and then I should be able to work the other gauges out from there.

Stefan, I know you have helped me out lots with this and I can't begin to tell you how much it is appreciated. This thread will be very helpful to anyone like me who is learning FSBusdll. So I hope you can continue to help.

Thanks
David

sgaert
06-20-2009, 03:13 AM
Hi,
do you have a picture of this Gauge?
I donīt know what Values you need as output.

Stefan

RobiD
06-20-2009, 03:30 AM
Hi Stefan,

These are not the exact same but I bought them from this company and this is the closest they have now.

http://www.futurlec.com.au/Panel_Meters.jsp It's the ones down the bottom.

I have tested the meter in FSAdmin, and I'm getting no response using J3 Analogue out, but if I leave it plugged into J3 and press Auto in the Digital out, the LEDS I have connected to J5 light and the meter is randomly moved (hard, due to voltage) in there. I don't know if I'm missing something. I've followed the instructions in the DIO manual.

Thanks for helping.
David

sgaert
06-20-2009, 03:41 AM
Did you connect a resistor and capacity to the circuit like on the schematic?

RobiD
06-20-2009, 03:55 AM
Yes, I've tried with the 10uf cap and the 5k6 resistor and without.

sgaert
06-20-2009, 04:05 AM
Ok than try other resistors to get a smooth movement wit the Analog Out fader.

RobiD
06-20-2009, 04:18 AM
On the board in R4-R11 I have 1k resistors and caps in C8-C15.

Should these be there? I have no measurable voltage on the pins of J3.

sgaert
06-20-2009, 04:33 AM
that is a PWM no Voltage you can measure. you need after J3 a low pass for you gauge.

RobiD
06-20-2009, 04:54 AM
that is a PWM no Voltage you can measure. you need after J3 a low pass for you gauge.


I figured that is why I couldn't measure a voltage. So it is ok to have the 1k resistors and the caps on the board as well as the cap and resistor after J3.

If so, I have everything covered but no movement on the needle. You suggested changing the resistor after J3. What do you suggest I try at present, it's a 5k6. (Bear in mind that I didn't get any movement with or without the cap and resistor.

sgaert
06-20-2009, 05:01 AM
Sorry i donīt know. I never try to work with the analog output.
Maybee look to the datasheet of the gauge there you have the values you need for the gauge.

RobiD
06-20-2009, 06:35 AM
I bought these so long ago, I can't remember what they were ie: amp or volt meters. They may be amp meters as putting a 1.5volt battery (even a flat one) across it makes the needle hit the other side with force.

I may have to souce some new meter and redo the artwork inside them.

Also, on compiling what I've coded, I assigned the fuel gauges BTP_A_OUT with CID 27 and RID 0, it compiles but then says in the DOS box that it is out of range and it should be 80 to 87. Is that right, as the assignments on the image of Rob's board says 00-07.

RobiD
06-20-2009, 07:22 AM
I had to peel the artwork off of one to see what it was and it's a VU meter which from what I understand is of no use. (unless it is possible to rewind the coil to make it a voltmeter)

Can you give me a general idea of the calculation anyway. You know, what it should look like after the :

switch cbPwmgauges (int oid, int val, double dval) line.

Thanks. I'll have to see what I can work out with these panel meters.

RobiD
06-30-2009, 11:26 PM
Stefan,

Wondering if you can point me in the right direction.

I am coding in the oil pressure gauge offset 0x3B60 which is a FLOAT64

In FSInterrogate, readings go from 0 at engine off up to 6000 at full rpm so I would estimate that it would go to 10000 if there was an overpressure.

Have used the calibrate function:

void cbVoltmeters (int oid, int val, double dval)
{
switch (oid)
{
case FS_GENERALENGINE1OILPRESSURE:
{
static CALTAB OILPRESSUREGauge[] = {
(0,0),(6000,255)
};
val = Calibrate (val, OILPRESSUREGauge,2);
FsbusWrite (C_OILPRESSURE, val);
}
break;

When I start the engine the needle has full deflection and when I stop the engine, as soon as the oil pressure hits 0 in interrogate, the needle drops to zero.

I have tried all combinations of numbers to get it to show some kind of parity with the gauge in the software, but it seem either off or full on.
I have also tried more numbers in the table, not just 2.

Any help you can offer.

Thanks
David

sgaert
07-01-2009, 01:57 AM
Hi.
to check the FSUIPC Output, put a print funktion over the calibration.

case FS_GENERALENGINE1OILPRESSURE:
{
printf("GENERALENGINE1OILPRESSURE %d%%\n", val);
static CALTAB OILPRESSUREGauge[] = {
(0,0),(6000,255)
};
val = Calibrate (val, OILPRESSUREGauge,2);
FsbusWrite (C_OILPRESSURE, val);
}
break;

Stefan

RobiD
07-01-2009, 04:17 AM
The values are the same as what I got from FSInterrogate.

0 for no pressure
3000 plus when engine starts.

But as I said before, When I start the engine the needle moves to full deflection and when I stop the engine, as soon as the oil pressure winds down and hits 0 in interrogate, the needle drops to zero.

It stays fully deflected the moment the pressure moves above 0.

Am I missing something in the calculation. Is this how you would have done it?

I have full deflection from 0 to 100% deflection using the Analog out in FSAdmin, so I shouldn't have to use a different resistor? I am still using the 5k6 resisitor as in the manual.

I had a go at doing the left fuel gauge, and at 0% in the tank, the needle dropped to 0, anything above 0 and it's fully deflected at 100%

Hope that makes sense.

Thanks
David

sgaert
07-01-2009, 04:31 AM
That dosenīt look at an analog out.
I would make a small programm with a Poti and a Analog Out and put the value of the poti to the analog out. There you can see output signal of the analog output on a definied input.

Stefan

RobiD
07-01-2009, 05:06 AM
wow, that may be beyond my ability. I am only just beginning to understand a little of C++.

RobiD
07-01-2009, 05:10 AM
If anyone else wants to help and contribute to this thread, I am more than willing to share to code for my Cessna cockpit.

I only have mine built due to other peoples input.

So this will be a complete Cessna package when it's complete.

sgaert
07-01-2009, 05:53 AM
wow, that may be beyond my ability. I am only just beginning to understand a little of C++.

He, that is more than easy. It is only C.

case C_Testpoti:
FsbusWrite(C_Tastanalogout, val);
break;

:D

Stefan

RobiD
07-01-2009, 06:34 AM
Sorry Stefan, excuse my ignorance, but where do I put this, and what do I do with it.

I understand it is to test the analog out.

Do I need to declare C_Tastanalogout
Do I need to declare C_Testpoti
Do I need to MkFsbusObject
Do I need to MkFSObject


When you say Poti, are you talking about a potentiometer, if so is it possible to have Analog in on port 80 and Analog out on port 87 because I understood that you couldn't have analog out if you have any analog in.

Appreciate if you could take me through step by step.

As you've probably gathered, I know about as much about C++ or C as you could learn in 2 weeks without reading any books.

David

sgaert
07-01-2009, 07:21 AM
That was only an sample.
You can use your own objekts.
I dont see any Problems in the Docu with a mix of Analog In and Analog Out.

Step by Step:
Find a definied data source. (Potentiometer, encoder, value entry in the Application)
Make all necessary hardware changes.
Declare and build all Objekts.
Write the code like my sample, in case of an encoder you need additional a variable and the add calculation. (x +=val; )

Stefan

RobiD
07-01-2009, 07:39 AM
Ok, I'm up for the challange.

I might try a value entry in the application.

How do I MkFSObject without an offset, or do I not need to MkFsObject.

MkFsbusObject (BTP_A_OUT,C_TESTANALOGOUT,"This is a test",cbVoltmeters,27,85);

case C_Testpoti:
int val;
val = enter set value here?;
FsbusWrite(C_TESTANALOGOUT, val);
break;


Then define C_Testpoti and define C_TESTANALOGOUT IN stdaft.h

Will this do it if I enter different values in the val = ? part?

sgaert
07-01-2009, 08:07 AM
NO.

first: you put them into a case that means only on an event of the right OID that would do. but without nothing work.

second: val is the vaiable lable of the OID value. you donīt need to gerate them.

last time you ask about encoders. use them.

Stefan

RobiD
07-01-2009, 08:18 AM
Ok,
maybe you can guide me a bit further.

I have a rotary encoder setup and configured on Digital IN CID27,RID32

I have a voltmeter setup and configured on Analog OUT 27,87

Can you write for me what I need to get the encoder to move the needle.
How will I then see what the numbers are for the encoder - print function?

Hope you can do this for me, my head is starting to hurt.

RobiD
07-03-2009, 08:33 PM
Just an update for anyone using this thread as an information source.

The rotary encoders are now working great, and the voltmeters are also working great.

Here were my problems (mistakes):

When you configure the DIO board for rotary encoders or analog out, the jumper J16 must be set in the same way as for giving the board the CID number.

The problem with getting the voltmeters to work using the calibrate function is totally my fault. In the array table, I used ( ) brackets instead of { } brackets. Now they all work fine.

So I now have working: Voltmeter (amps), Left and Right Fuel Gauges, Fuel Pressure, Oil Pressure and Oil Temp. It's great to see them working perfectly.

For my next adventure, I will start programming the radios: Nav1, Nav2, Com1, Com2

David

RobiD
07-04-2009, 11:50 PM
Stefan,

Another question for you.

I am programming my ADF, simple 5 digit display, and a rotary encoder.

In the example that came with FSBus dll V1, there is an example under nav.cpp

I have copied this over to my files, made the change for MkFsObject from MakeFsObject, put in my DIO board for the rotary encoder ie: 27,32
put in the display card, 14,0

I am getting no change in the ADF using the rotary encoder, and I am getting nothing on the display.

I tested the display, it is working fine, and we tested the rotary encoder with your program and it's working fine.

Is there something else that needs to be changed in order for it to work in FSbus V2?

Appreciate your thoughts.

David

sgaert
07-05-2009, 03:39 AM
Hi,
as far as I can remember me the ADF never work in the sample files.

Stefan

RobiD
07-05-2009, 06:07 AM
That's a shame, I thought I could just copy it over and it would work straight out of the box. But then again, I have found out that nothing works straight out of the box with programming.

Any thoughts on what needs to be changed to get it to work?
Did Rob have any luck?
Dirk is building a Cessna, perhaps he has had some luck.

Thanks
David

sgaert
07-05-2009, 06:21 AM
to think you copy a part from the sample and you have a finished solution is the compleatly wrong way.
That are only early samples, they have big bugs.
At Robs code you have a finished working ADF.
Btw. a ADF with only 1 Encode will drive you crazy.

Stefan

RobiD
07-05-2009, 08:14 AM
Ok, that explains why it doesn't work.

I will have another look at Rob's code. He seems to use a different format for his coding and I've found it a little difficult to work out.

Also, my rotary encoders have a momentary switch when you push the knob. I have read somewhere that it is possible to convert it to a dual encoder by using this switch ie: tune the main three digits, push the knob and then tune the decimal places.

Is this possible?

Thanks
David

sgaert
07-05-2009, 09:18 AM
Hi,
what you mean with "He seems to use a different format for his coding "?

with the pushbutton is a possible way.

Stefan

RobiD
07-05-2009, 07:21 PM
Rob uses "Eventhandler" a lot and I don't understand it. It's just my lack of knowledge.

His method of defining is different to how I've been laying out my code. His seems quite advanced compared to my 'learning' code.


How can it be done with the rotary encoder with the push switch?
I will go though Rob's code later today to see if I can pull out the right info.

David

sgaert
07-06-2009, 01:39 AM
The "EventHandler" is the highest Funktion in Robs code.
The Type of defining is more effektive, btw. we dont use Groups with 32 Objects. Our groups have 256 objekts.

Your Encoder is only an normal Encoder and a normal push button, nothing special. You have too make Code for the Mode Switching and rotation.

Stefan

RobiD
07-06-2009, 07:54 AM
I've done lots of trial and error using the EventHandler with no success so I've rebuilt Rob's code in the format I've got used to.

I have had reasonable success as such. Rob uses 3 encoders ie: 1, 10,100.

If I assign my rotary encoder (1 at a time to test) to each, it moves my display as it should, but doesn't move the display on the screen. If I change the numbers on the screen with my cursor, the numbers in my display also change.

It appears the encoder is writing correctly to Fsbus, but not to FS and FS is writing to Fsbus correctly.

I'll attache the code and if you get a chance, could you take a look and see what I've missed.

Also, I have no idea how to put together the code for the mode switching and rotation so I'd love some help there too if possible.

I'll just post the case part:



void cbNav (int oid, int val, double dval)
{
int x;
switch (oid)
{
/*----------------------- ADF Events ----------------------*/
case FS_ADF1FREQUENCY:
ADF1 = (ADF1 / 10000) * 10000 + BCD2Int(val) * 10 + ADF1 % 10;
FsbusWrite(C_DADF1, ADF1);
if (bSynchronised == false)
{
FsbusWrite(C_DADF1, ADF1);
}
break;
case FS_EXTENDEDADF1:
ADF1 = BCD2Int(val >> 8) * 10000 + ((ADF1/10)%1000)*10 + BCD2Int(val & 0x00FF);
FsbusWrite(C_DADF1, ADF1);
if (bSynchronised == false)
{
FsbusWrite(C_DADF1, ADF1);
}
break;
case C_RADF_100:
x = ADF1 / 1000; // hundreds
x = x + val; // update 100s
if (x > 17)
x = 1; // wrap
else if (x < 1)
x = 17; // wrap
ADF1 = x * 1000 + ADF1 % 1000; // new 100s
FsbusWrite(C_DADF1, ADF1);
FsWrite(C_DADF1, ADF1);//***ADDED THIS MYSELF TO SEE IF I COULD GET IT TO WRITE TO FSX
break;
case C_RADF_10:
x = (ADF1 % 1000) / 10; // tens + units
x = x + val; // update 10s
if (x > 99)
x = 0; // wrap
else if (x < 0)
x = 99; // wrap
ADF1 = (ADF1 / 1000) * 1000 + x * 10 + ADF1 % 10; // new 10s
FsbusWrite(C_DADF1, ADF1);
break;
case C_RADF_1:
x = ADF1 % 10; // .1 units
x = x + val; // update 10s
if (x > 9)
x = 0; // wrap
else if (x < 0)
x = 9; // wrap
ADF1 = (ADF1 / 10) * 10 + x;
FsbusWrite(C_DADF1, ADF1);
break;
}
}


Thanks again,
David

Update: I have changed FsWrite(C_DADF1, ADF1); to FsWrite(FS_ADF1FREQUENCY, ADF1) as of course C_DADF1 is not an FS Object and now it is writing to FSX but random numbers. In FSInterrogate, it is making random hexidecimal numbers. If I leave the FSWrite out, my display moves perfectly when I move the encoder, but when I add the FSWrite in, it become random. Any ideas?

sgaert
07-06-2009, 08:34 AM
Hi,
that is my ADF Code.
Btw. ADF need 2 FSUIPC Offset.



/*
adf1_dec and adf1_fra are
static int variables (read/write from the corresponding fsuipc offsets)
*/
static int adf1_dec;
static int adf1_fra;

MkFsObject(FS_EXTENDEDADF1,"",EventHandler,0x0356, 2,TP_UI16,FS_NORMAL);
MkFsObject(FS_ADF1FREQUENCY,"",EventHandler,0x034C, 2,TP_UI16,FS_NORMAL);

case FS_ADF1FREQUENCY:
ADF1 = (ADF1 / 10000) * 10000 + BCD2Int(val) * 10 + ADF1 % 10;
FsbusWrite(CD_ADF_1, ADF1);
if (bSynchronised == false)
{
ADF1Stb = ADF1;
FsbusWrite(CD_ADF_1, ADF1Stb);
}
break;
case FS_EXTENDEDADF1:
ADF1 = BCD2Int(val >> 8) * 10000 + ((ADF1/10)%1000)*10 + BCD2Int(val & 0x00FF);
FsbusWrite(CD_ADF_1, ADF1);
if (bSynchronised == false)
{
ADF1Stb = ADF1;
FsbusWrite(CD_ADF_1, ADF1Stb);
}
break;
case CR_ADF_100:
x = ADF1Stb / 1000; // hundreds
x = x + val; // update 100s
if (x > 17)
x = 1; // wrap
else if (x < 1)
x = 17; // wrap
ADF1Stb = x * 1000 + ADF1Stb % 1000; // new 100s
FsbusWrite(CD_ADF_1, ADF1Stb);
x = Int2BCD(ADF1Stb);
FsWrite(FS_EXTENDEDADF1, ((x & 0x0F0000) >> 8) | (x & 0x00000F));
FsWrite(FS_ADF1FREQUENCY, (x & 0x00FFF0) >> 4);
break;
case CR_ADF_10:
x = (ADF1Stb % 1000) / 10; // tens + units
x = x + val; // update 10s
if (x > 99)
x = 0; // wrap
else if (x < 0)
x = 99; // wrap
ADF1Stb = (ADF1Stb / 1000) * 1000 + x * 10 + ADF1Stb % 10; // new 10s
FsbusWrite(CD_ADF_1, ADF1Stb);
x = Int2BCD(ADF1Stb);
FsWrite(FS_EXTENDEDADF1, ((x & 0x0F0000) >> 8) | (x & 0x00000F));
FsWrite(FS_ADF1FREQUENCY, (x & 0x00FFF0) >> 4);
break;
case CR_ADF_1:
x = ADF1Stb % 10; // .1 units
x = x + val; // update 10s
if (x > 9)
x = 0; // wrap
else if (x < 0)
x = 9; // wrap
ADF1Stb = (ADF1Stb / 10) * 10 + x;
FsbusWrite(CD_ADF_1, ADF1Stb);
x = Int2BCD(ADF1Stb);
FsWrite(FS_EXTENDEDADF1, ((x & 0x0F0000) >> 8) | (x & 0x00000F));
FsWrite(FS_ADF1FREQUENCY, (x & 0x00FFF0) >> 4);
break;


so now with Push Buttons.
Fast freestyle not tested.


/*
adf1_dec and adf1_fra are
static int variables (read/write from the corresponding fsuipc offsets)
*/
static int adf1_dec;
static int adf1_fra;
static int adfmode=0;

MkFsbusObject (BTP_ROTARY, CR_ADF,"",EventHandler, 27,32);
MkFsbusObject (BTP_D_IN, C_ADFPush,"",EventHandler, 4, 55);
MkFsObject(FS_EXTENDEDADF1,"",EventHandler,0x0356, 2,TP_UI16,FS_NORMAL);
MkFsObject(FS_ADF1FREQUENCY,"",EventHandler,0x034C, 2,TP_UI16,FS_NORMAL);

case FS_ADF1FREQUENCY:
ADF1 = (ADF1 / 10000) * 10000 + BCD2Int(val) * 10 + ADF1 % 10;
FsbusWrite(CD_ADF_1, ADF1);
if (bSynchronised == false)
{
ADF1Stb = ADF1;
FsbusWrite(CD_ADF_1, ADF1Stb);
}
break;
case FS_EXTENDEDADF1:
ADF1 = BCD2Int(val >> 8) * 10000 + ((ADF1/10)%1000)*10 + BCD2Int(val & 0x00FF);
FsbusWrite(CD_ADF_1, ADF1);
if (bSynchronised == false)
{
ADF1Stb = ADF1;
FsbusWrite(CD_ADF_1, ADF1Stb);
}
break;

case C_ADFPush:
if(val==0)
{
adfmode+=1;
if (adfmode>2)
adfmode=0;
}
break;

case CR_ADF:
if (adfmode==0)
{
x = ADF1Stb / 1000; // hundreds
x = x + val; // update 100s
if (x > 17)
x = 1; // wrap
else if (x < 1)
x = 17; // wrap
ADF1Stb = x * 1000 + ADF1Stb % 1000; // new 100s
FsbusWrite(CD_ADF_1, ADF1Stb);
x = Int2BCD(ADF1Stb);
FsWrite(FS_EXTENDEDADF1, ((x & 0x0F0000) >> 8) | (x & 0x00000F));
FsWrite(FS_ADF1FREQUENCY, (x & 0x00FFF0) >> 4);
}
if (adfmode==1)
{
x = (ADF1Stb % 1000) / 10; // tens + units
x = x + val; // update 10s
if (x > 99)
x = 0; // wrap
else if (x < 0)
x = 99; // wrap
ADF1Stb = (ADF1Stb / 1000) * 1000 + x * 10 + ADF1Stb % 10; // new 10s
FsbusWrite(CD_ADF_1, ADF1Stb);
x = Int2BCD(ADF1Stb);
FsWrite(FS_EXTENDEDADF1, ((x & 0x0F0000) >> 8) | (x & 0x00000F));
FsWrite(FS_ADF1FREQUENCY, (x & 0x00FFF0) >> 4);
}
if (adfmode==1)
{
x = ADF1Stb % 10; // .1 units
x = x + val; // update 10s
if (x > 9)
x = 0; // wrap
else if (x < 0)
x = 9; // wrap
ADF1Stb = (ADF1Stb / 10) * 10 + x;
FsbusWrite(CD_ADF_1, ADF1Stb);
x = Int2BCD(ADF1Stb);
FsWrite(FS_EXTENDEDADF1, ((x & 0x0F0000) >> 8) | (x & 0x00000F));
FsWrite(FS_ADF1FREQUENCY, (x & 0x00FFF0) >> 4);
}
break;


EDIT: you have to make some variabels that i have used.
static int ADF1 = 0; // binary, units 0.1 KHz
static int ADF1Stb = 0; // binary, units 0.1



good luck
Stefan

RobiD
07-06-2009, 09:05 PM
Stefan,

Great. This works almost perfect.

I think it is mode 1. the 10s, 1s and .1s ie: 1448.8 (48.8) Hope this explains what I mean.

The 48 increments correctly but the .8 increments with the 8 ie: 48.8, 49.9, 50.0, 51.1.

I'm sure it's probably a little change, but other than that it works. Writes to Fsbus and FSX and FSX writes correctly to Fsbus.

Just a thought, it is possible to have mode 0, mode 1 and mode 2 (so there are three clicks ie: mode 0 for thousands and hundreds, mode 1 for tens and ones, and mode 2 for the .1 to .9)

So this is what I have now with the minor mods to keep in line with my methodology:



static int ADF1 = 0; // binary, units 0.1 KHz
static int ADF1Stb = 0; // binary, units 0.1
/*
adf1_dec and adf1_fra are
static int variables (read/write from the corresponding fsuipc offsets)
*/
static int adf1_dec;
static int adf1_fra;
static int adfmode=0;
void cbNavBuildObjects()
{
MkFsbusObject (BTP_ROTARY, C_RADF,"",cbNav, 27,32);
MkFsbusObject (BTP_D_IN, C_ADFPush,"",cbNav, 27, 16);
MkFsbusObject(BTP_DISPLAY, C_DADF_1, "",cbNav, 14, 0);
DisplayOptions(C_DADF_1,5,0,TRUE,2);
MkFsObject(FS_EXTENDEDADF1,"",cbNav,0x0356, 2,TP_UI16,FS_NORMAL);
MkFsObject(FS_ADF1FREQUENCY,"",cbNav,0x034C, 2,TP_UI16,FS_NORMAL);
}
void cbNav (int oid, int val, double dval)
{
int x;
switch (oid)
{
case FS_ADF1FREQUENCY:
ADF1 = (ADF1 / 10000) * 10000 + BCD2Int(val) * 10 + ADF1 % 10;
FsbusWrite(C_DADF_1, ADF1);
if (bSynchronised == false)
{
ADF1Stb = ADF1;
FsbusWrite(C_DADF_1, ADF1Stb);
}
break;
case FS_EXTENDEDADF1:
ADF1 = BCD2Int(val >> 8) * 10000 + ((ADF1/10)%1000)*10 + BCD2Int(val & 0x00FF);
FsbusWrite(C_DADF_1, ADF1);
if (bSynchronised == false)
{
ADF1Stb = ADF1;
FsbusWrite(C_DADF_1, ADF1Stb);
}
break;

case C_ADFPush:
if(val==0)
{
adfmode+=1;
if (adfmode>2)
adfmode=0;
}
break;

case C_RADF:
if (adfmode==0)
{
x = ADF1Stb / 1000; // hundreds
x = x + val; // update 100s
if (x > 17)
x = 1; // wrap
else if (x < 1)
x = 17; // wrap
ADF1Stb = x * 1000 + ADF1Stb % 1000; // new 100s
FsbusWrite(C_DADF_1, ADF1Stb);
x = Int2BCD(ADF1Stb);
FsWrite(FS_EXTENDEDADF1, ((x & 0x0F0000) >> 8) | (x & 0x00000F));
FsWrite(FS_ADF1FREQUENCY, (x & 0x00FFF0) >> 4);
}
if (adfmode==1)
{
x = (ADF1Stb % 1000) / 10; // tens + units
x = x + val; // update 10s
if (x > 99)
x = 0; // wrap
else if (x < 0)
x = 99; // wrap
ADF1Stb = (ADF1Stb / 1000) * 1000 + x * 10 + ADF1Stb % 10; // new 10s
FsbusWrite(C_DADF_1, ADF1Stb);
x = Int2BCD(ADF1Stb);
FsWrite(FS_EXTENDEDADF1, ((x & 0x0F0000) >> 8) | (x & 0x00000F));
FsWrite(FS_ADF1FREQUENCY, (x & 0x00FFF0) >> 4);
}
if (adfmode==1)
{
x = ADF1Stb % 10; // .1 units
x = x + val; // update 10s
if (x > 9)
x = 0; // wrap
else if (x < 0)
x = 9; // wrap
ADF1Stb = (ADF1Stb / 10) * 10 + x;
FsbusWrite(C_DADF_1, ADF1Stb);
x = Int2BCD(ADF1Stb);
FsWrite(FS_EXTENDEDADF1, ((x & 0x0F0000) >> 8) | (x & 0x00000F));
FsWrite(FS_ADF1FREQUENCY, (x & 0x00FFF0) >> 4);
}
break;
}
}

RobiD
07-07-2009, 12:25 AM
Ok, worked out what was wrong, there were two instances of mode 1, I changed the second to mode 2 and now it works like it should.

Yee haa.

Thanks as always Stefan.

I'm now going to try to do this with the Nav1

David

RobiD
07-07-2009, 02:13 AM
Just completed the NAV1 radio. Use the mode method you gave me and it works great, swap works so all is good.

Just can't find an offset for the test button (not that is important).

sgaert
07-07-2009, 02:24 AM
That is right, this funktion dosenīt work on FS.

RobiD
07-10-2009, 07:05 PM
Hi Stefan,

Back again. Everything is going great.

I have started on the xponder.

My set us uses 4 on-off-on self centering switches for the four digits, one for each digit (push up for up one number and press down for down one number), (hope that makes sense).

I have a 12 position rotary switch which I use for: Off, SBY, ON, ALT, TEST.

What do I need to change in Rob's (it's probably your code) code to achieve this.

Oh, another thing, I have a single LED as an on indicator.

Appreciate your help once again.

David

Here's Rob's code



case FS_TRANSPONDERSETTING:
Expdr = BCD2Int(val);
FsbusWrite (C_DXPNDR, Expdr);
break;
case C_RXPNDRL:
if (val > 0)
{
Expdr += 1000;
if ((Expdr % 10000) > 7777)
Expdr -= 8000;
}
else
{
Expdr += 100;
if ((Expdr % 1000) > 777)
Expdr -= 800;
}
FsbusWrite(C_DXPNDR, Expdr);
x = Int2BCD(Expdr);
FsWrite(FS_TRANSPONDERSETTING, x);
break;
case C_RXPNDRR:
if (val > 0)
{
Expdr += 10;
if ((Expdr % 100) > 77)
Expdr -= 80;
}
else
{
Expdr += 1;
if ((Expdr % 10) > 7)
Expdr -= 8;
}
FsbusWrite(C_DXPNDR, Expdr);
x = Int2BCD(Expdr);
FsWrite(FS_TRANSPONDERSETTING, x);
break;
case C_SXPNDRIDENT://this would be off?
break;
case C_SXPNDRCTRL1://this would be sby?
break;
case C_SXPNDRCTRL2://this would be on?
break;
case C_SXPNDRCTRL3://this would be alt?
break;
case C_SXPNDRCTRL4://this would be test?
break;
case C_SXPNDRCTRL5:
break;

sgaert
07-11-2009, 01:25 AM
hi,
to change Robs code make no sence, you idea is completly different to Robs solution. Robs code have only the up way, not the down direction.
You have to make your own solution.

Stefan

RobiD
07-11-2009, 01:45 AM
Hi Stefan,

Thanks for your comments.

I think I will have to redesign my transponder. I built this a long time ago from someone elses idea.

I will have to get the old cnc machine out again.

Am I correct:

Rob's code is based on 1 rotary encoder
A 5 position rotary switch (for OFF, STBY, ON, ALT, TEST)
It is a 5 7-segment display (not 4 like mine is)

Regards
David

sgaert
07-11-2009, 01:56 AM
no:
4 Digits
a 5 position switch (you can use what you want)
and 2 Encoder each for two digits, turn left the left digit goes up, turn right the right goes up.

Stefan

RobiD
07-11-2009, 08:32 PM
Thanks Stefan.

I should be able to use the same encoders that I've used for the Nav1 and use the mode technique you have shown me so that I only have to use one rotary encoder.

Does that sound right?

Regards
David

sgaert
07-12-2009, 01:39 AM
Yes that is possible, but dont think that is a useable solution.

Stefan

RobiD
07-12-2009, 09:15 AM
Just come to the realisation that there are no offsets for the OFF, STBY, ON, ALT or test, so it was a pointless exercise.

I've gone back to basics, I've pulled two of the switches out and converted the holes to fit the rotary encoders, so now I have the same layout as Rob uses ie: 2 rotary encoders, 4 digits and a dummy 5 position switch.

The code compiles so that's a good sign. I just need to wire it all up to test.

When I'm done with the coding, I will be giving the uncompiled project to anyone who wants to build a cessna cockpit using FSBus dll. Hope no one minds (I'm sure no one does).

David

RobiD
07-14-2009, 02:44 AM
Stefan,

Can you check my parts list for the Stepper Board. It is very hard to read off of the documentation:

1 SMD AtMega168
1 L293D DIN
R1 47k
R2 3k3
R3 100
R4 220

C1 100n
C2 100p
C3 can't see this one. Looks like 100n
C4 22p
C5 22p
D1 1N418
Q1 8MHz
SMD LED

Thanks
David

sgaert
07-14-2009, 02:56 AM
C2 = 100uF
C3 = 100nF

2 thinks for information.
If you need the "motor breaks when idel" the l293D become realy hot, you need a big passiv cooler.
My Stepper work only in the AdminTool in my C code i nevver had a movement.

Stefan

RobiD
07-14-2009, 03:17 AM
How are you going to get around this.

Does that mean you can't get it to work with the C++ coding?

I need to make 4 of these boards to drive my altitude indicator, 2 for the ADF/RMI and Gyro compass. I don't really have an alternative to drive these.

Has Rob has success in programming the boards in C++.

sgaert
07-14-2009, 03:21 AM
Does that mean you can't get it to work with the C++ coding?
Right!


Has Rob has success in programming the boards in C++.I dont know, nobody give me an arnswer.

Stefan

RobiD
07-16-2009, 04:26 AM
Hi Stefan,

This will probably sound like a silly question, but here goes.

I have programmed in the Inner, middle and outer marker lights (IMO lights).

I want to test them, but I can't get the IMO lights to work in fsx (not the programmed ones, but the actual ones on the screen). I have tried many different airports, approached from at least 4nm out to get the outer marker, but they just don't work.

I have also tried with the VOR frequency dialled in for that specific airport but no go.

I am missing something that makes these lights work.

I have flown so many times and these lights have worked so many times before but when I want them to light up so I can test my coding, nothing.

Appreciate your input on this.

David

sgaert
07-16-2009, 04:31 AM
I want to test them, but I can't get the IMO lights to work in fsx (not the programmed ones, but the actual ones on the screen). I
Do i understand that right, FSX IMO Lights do not work?
Stefan

RobiD
07-16-2009, 04:38 AM
I can't say that they don't work, but I am probably doing something wrong on approach or I have a setting wrong or have not set something.

I thought they worked all the time on approach whether it's an ILS, vor, vfr etc.

RobiD
07-17-2009, 07:18 AM
I can get the lights to light up in the USA. Dallas International.

The IMO lights illuminate but now that I can test the lights, I'm not getting my led's lighting up.

I've tried a variety of coding to see if it works but I'm not having any luck.

Here's what I have. I thought it should be as simple as the Inner and Middle are coded so then I tried adding the variable to the Outer but that didn't work either.

Tested the leds in FSAdmin and they work.

I know I'm missing something simple, hope you can point it out to me.

(with the outer marker, I have the static int outermarker = 0; at the top of the page)



void cbIndicatorlights (int oid, int val, double dval)
{
switch (oid)
{
case FS_INNERMARKER:
FsbusWrite (C_LEDINNERMARKER, val);
break;
case FS_MIDDLEMARKER:
FsbusWrite (C_LEDMIDDLEMARKER, val);
break;
case FS_OUTERMARKER:
if (outermarker == 0)
{
FsbusWrite (FS_OUTERMARKER, 0);
}
else (outermarker == 1);
{
FsbusWrite (FS_OUTERMARKER, 1);
}
break;

sgaert
07-17-2009, 07:49 AM
Hi,
this type is the right solution.

case FS_INNERMARKER:
FsbusWrite (C_LEDINNERMARKER, val);
break;

Your outermarker code canīt work.
The variable "outermarker" has only the value 0 from greation.
you can write val into outermarker than is everything ok, but that is all code for nothing.

What a polling time you use for this objekts?
I would use FS_QUICK.

Stefan

RobiD
07-17-2009, 07:54 AM
I'm using normal polling time. I will change it to quick, get rid of the pointless code and try again.

I only tried the extra code as the led's were not working.

Do I need to define val?

Thanks

sgaert
07-17-2009, 07:57 AM
no, val is define wit "void cbIndicatorlights (int oid, int val, double dval)".

RobiD
07-17-2009, 08:18 AM
Found my error, I didn't declare cbIndicatorlightsBuildObject in cockpit.cpp

Did that, now I have an error on compiling in the dos window:

FSBUS DLL:
102 is not an fsbus object

any ideas what that means?

sgaert
07-17-2009, 08:21 AM
an error with your OID define on object 102.

RobiD
07-17-2009, 08:26 AM
Not sure what you mean.

Here is my OID details for these lights:

#include "indicatorlights.h"
#define OID_INDICATORLIGHTS_GROUP (3 << OID_CONTROL_BITS)
#define C_LEDOUTERMARKER OID_INDICATORLIGHTS_GROUP +1
#define C_LEDMIDDLEMARKER OID_INDICATORLIGHTS_GROUP +2
#define C_LEDINNERMARKER OID_INDICATORLIGHTS_GROUP +3
#define FS_INNERMARKER OID_INDICATORLIGHTS_GROUP +4
#define FS_MIDDLEMARKER OID_INDICATORLIGHTS_GROUP +5
#define FS_OUTERMARKER OID_INDICATORLIGHTS_GROUP +6

If I comment out the outermarker code, it compiles ok (the outermarker light is on at present and paused)


If I change FS_OUTERMARKER to +7 the error is 103, if I change it to +8, the error is 04, so it has something to do with FS_OUTERMARKER

RobiD
07-17-2009, 08:34 AM
My error again. I was writing to FS_OUTERMARKER instead of C_LEDOUTERMARKER.

Now it compiles and I'll test it.

And of course, now it works.

Thanks for your patience with my learning.

Regards
David

PS I will soon start on the MCP. I will try to use Rob's code without change other than changing the Eventhandler format.

RobiD
07-20-2009, 01:59 AM
Started on the MCP now.

Set up Rob's code and made some minor formating changes as usual.

Everything seems to work ok except for the AP_Altitude. Seems lots of people have trouble with this one.

This is what Rob has and I've added the FsWrite as it wasn't writing to FSX.

If I use the software knob with the mouse, my Display increments in 100's but does this:

00000
00100
00200
3300
3400
00500
00600
3070

I'll stop there but you get the idea.

If I use the physical rotary, it trys to move on the display will go to 100, 200 and then 00000 again. In the software, it won't move up, but will go down from 00000 to 99900 99800 and then 00000

Here's Robs code:


case C_RALTITUDE:
//EventHandler(S_RHEADING, 0, 0); // sound rotary
Altitude += val * 10000 / 100; // val can be >1 or <-1
// printf("Altitude %d\n", Altitude);
FsbusWrite(C_DALTITUDE, Altitude);
FsWrite(FS_AP_ALTITUDE, Altitude); // to cockpit display
break;


Do you have any thoughts on this.

sgaert
07-20-2009, 02:35 AM
Hi,
please donīt use Robs code so much it isnīt finished.
Look to the FSUIPC SDK then you see the error.

My code:

case CR_APALT:
apalt += val*100;
if (apalt < 0)
apalt = 0;
if (apalt > 39000)
apalt = 39000;
FsbusWrite (CD_APALT, apalt);
FsWrite(FS_AP_ALTITUDE, apalt*19975);
break;

define apalt als static int on top.

Stefan

RobiD
07-20-2009, 02:48 AM
Hi Stefan,

Thanks again, you're a life saver.

I don't really have a lot of choice for using Rob's code, as I have no other reference to use, and as I don't really know how to code (or rather, I am learning as I'm going), I have no other starting point.

So I hope you can understand how helpful it has been that you have been so willing to help me.

I will change to code and see how it goes.

Gratitude,
David

RobiD
07-20-2009, 03:09 AM
Wow, there are a lot of errors in Rob's code. I've commented out pretty well everything after this piece of code and it what you have given me increments well. A few minor problems, but usable. Only problem is FSX is not writing to Fsbus.
If I change the altitude in the software, my display doesn't update.

There appears to be other sections of code later on that is also writing to FS_AP_ALTITUDE. When I don't comment this out, the display doesn't increment properly.


This is probably a big ask, but if you have a working sample of a complete MCP code, would you share it with me?

It would save lots of questions.

RobiD
07-21-2009, 05:11 AM
Hey Stefan,

Do you know if there is going to be a simple key type card like the old FSbus.

I need more space for switches and it seem a waste to build an entire DIO board just for switches. I still have my old Key card, I guess it's is of no use with FSbus dll v2.

Also, I was looking at the pcb layouts with the V2, and in the display pcb, there are about 6 different tabs down the bottom with some very interesting layouts for ... I'm not sure. Can you tell me what they are for (other than the obvious 6 pack and display cards).

Thanks
David

sgaert
07-21-2009, 06:00 AM
hi,


This is probably a big ask, but if you have a working sample of a complete MCP code, would you share it with me?
Yes i have code for you but i only share the Rotarys and ther backway. The switches and LED you can make by your self. The reason for that isnīt i donīt what give you the code, I donīt have the code. All my code samples are from my VasFmc projekt and the Switches talk direkt to VasFmc and not to FSX.



case CR_APHEADING:
aphdg -= val;
if (aphdg > 360)
aphdg = 1;
if (aphdg < 1)
aphdg = 360;
x = (aphdg * 65536 - 180) / 360;
FsbusWrite (CD_APHEADING, aphdg);
FsWrite(FS_AP_HEADING, x);
break;

case FS_AP_HEADING:
aphdg=(val+1)*360/65536;
if (aphdg == 0)
aphdg = 360;
FsbusWrite (CD_APHEADING, aphdg);
break;

case CR_APALT:
apalt += val*100;
if (apalt < 0)
apalt = 0;
if (apalt > 39000)
apalt = 39000;
FsbusWrite (CD_APALT, apalt);
FsWrite(FS_AP_ALTITUDE, apalt*19975);
break;

case FS_AP_ALTITUDE:
apalt = (val / 19975);
FsbusWrite (CD_APALT, apalt);
break;

case CR_APVSpeed:
apvspeed += val*100;
if (apvspeed < -7600)
apvspeed = -7600;
if (apvspeed > 6000)
apvspeed = 6000;
FsbusWrite (CD_APVSpeed, apvspeed);
FsWrite(FS_AP_VS, apvspeed);
break;

case FS_AP_VS:
apvspeed = val ;
FsbusWrite (CD_APVSpeed, apvspeed);
break;

case CR_APCours:
apvcours -= val;
while (apvcours > 360)
apvcours -= 360;
while (apvcours <= 0)
apvcours += 360;
FsbusWrite (CD_APCours, apvcours);
FsWrite(FS_NAV1OBS, apvcours);
break;

case FS_NAV1OBS:
apvcours = val;
if (apvcours == 0)
apvcours = 360;
FsbusWrite (CD_APCours, apvcours);
break;

case CR_APSpeed:
apias -= val;
if (apias < 100)
apias = 100;
if (apias > 340)
apias = 340;
FsWrite(FS_AP_AIRSPEED, apias);
FsbusWrite (CD_APSpeed, apias);
break;

case FS_AP_AIRSPEED:
apias = val;
FsbusWrite (CD_APSpeed, apias);
break;


For Switches and LED you have enough experiance, to find the right solution.
Also you can use Robs code, that looks ok.



I need more space for switches and it seem a waste to build an entire DIO board just for switches.
I donīt think so, DIO is to 80% input. If you calculate there are only 2€ (3US$) for the Outs and analog part. That is to low to make a new PCB with ONLY inputs.

Your second question i donīt understand, can you make a drawing of the part? (use the pictures from the docu, or Robs page)

Stefan

RobiD
07-21-2009, 06:20 AM
First of all, Thank you for the code.

I understand what you are saying about the cost of building a DIO as compared to just the input part. I guess it's more about the space or size of the board, but that's ok, I have all the parts to make another one.

Lastly, the pcb layouts:

If you open the pcb folder under the main FSbus dll folder, then open dsp_7.lay in sprint-Layout, at the bottom of the window you will see tabs named: Platine 1, Platine 2, Platine 3, Platine 4, Platine 1 (yes, another 1), Platine 6, AD, Platine 1 (yes, yet another 1).

The first 1 through 4 are specifically for the 6 pack and the singles, and the 7 digit led cards.

The remainder I have never seen before but they have me curious. The second Platine 1 looks like it is an ATC switch panel with microswitches (numbers 1 to 0 type of keypad)

The third Platine 1 looks like a mounting card for 6 slide potentiometers. Any idea what they all are?

David

sgaert
07-21-2009, 06:28 AM
No idea, btw. i look for the first time in that file.

Stefan

RobiD
07-21-2009, 06:49 AM
Other than the obvious ones, none of them resemble any of the boards Rob has on his site.

RobiD
07-24-2009, 07:00 AM
Stefan,

Another question regarding the code for MCP.

For the flight director switch, using Rob's code for the switch, he has coded it for a momentary switch ie: push, turns on, push again, turns off etc.

How do I change this to be a toggle as it should be ie: switch in up position, ON, switch in down position, OFF (I'm sure you understand what I mean).

Here is the code he has:



case C_SFLIGHTDIRL:
if (val == 0) {
printf("C_SFLIGHTDIRL event, ValFlightDir=%d\n", ValFlightDir);
if (ValFlightDir == 0)
{
// printf("DIRL0, val=%d\n", val);
FsbusWrite(C_LFLIGHTDIRL, 1);
FsbusWrite(C_LMASTFLIGHTL, 1);
FsbusWrite(C_LFLIGHTDIRR, 0);
FsbusWrite(C_LMASTFLIGHTR, 0);
FsWrite(FS_FLIGHTDIRECTOR,1);
ValFlightDir = 1;
}
else if (ValFlightDir == 1)
{
// printf("DIRL1, val=%d\n", val);
FsbusWrite(C_LFLIGHTDIRL, 0);
FsbusWrite(C_LMASTFLIGHTL, 0);
FsWrite(FS_FLIGHTDIRECTOR, 0);
FsbusWrite(C_LMASTFLIGHTR, 0);
ValFlightDir = 0;
}
else if (ValFlightDir == 2)
{
// printf("DIRL2, val=%d\n", val);
FsbusWrite(C_LFLIGHTDIRL, 1);
FsbusWrite(C_LMASTFLIGHTL, 0);
FsWrite(FS_FLIGHTDIRECTOR, 1);
ValFlightDir = 4;
}
else if (ValFlightDir == 3)
{
// printf("DIRL3, val=%d\n", val);
FsbusWrite(C_LFLIGHTDIRL, 0);
FsbusWrite(C_LMASTFLIGHTL, 0);
FsbusWrite(C_LMASTFLIGHTR, 1);
FsWrite(FS_FLIGHTDIRECTOR, 1);
ValFlightDir = 2;
}
else if (ValFlightDir == 4)
{
// printf("DIRL4, val=%d\n", val);
FsbusWrite(C_LFLIGHTDIRL, 0);
FsbusWrite(C_LMASTFLIGHTL, 0);
ValFlightDir = 2;
}
}
break;


Thanks again,
David

sgaert
07-24-2009, 07:34 AM
Hi,
do you need the Logic from the 737 with Left and Right FD, Master and FD Light???

Please discribe what you have build as hardware and what funktion do you need?

Stefan

RobiD
07-24-2009, 08:14 AM
I have custom designed my mcp as it is only a single seater cockpit. So there is only one FD switch, I'll describe from left to right (it's loosely based on a 777).

Course Rotary - Course Display
F/D toggle switch
Auto-throttle arm toggle - A/T led indicator
Speed hold momentary
IAS/MACH Display - IAS rotary - IAS/MACH selector momentary
Heading Select momentary / Heading Select Rotary /Heading selectDisplay
Nav momentary / VOR loc momentary / App momentary
Altitude Rotary - Altitude Display - Altitude hold momentary
V/S Display - V/S Hold - V/S Rotary
A/P CMD momentary
A/P Disengage (self centering toggle switch)


I've also attached a 737 mcp image that I've made changes to to give you an idea of what I've done.

Thanks
David

sgaert
07-24-2009, 08:19 AM
ok, i only mean the FD Funktion but ok.



case C_SFLIGHTDIRL:
if (val == 0) //here you write if 1 active or 0
{
// printf("DIRL0, val=%d\n", val);
FsbusWrite(C_LFLIGHTDIRL, 1);
FsbusWrite(C_LMASTFLIGHTL, 1);
FsWrite(FS_FLIGHTDIRECTOR,1);
}
else
{
// printf("DIRL1, val=%d\n", val);
FsbusWrite(C_LFLIGHTDIRL, 0);
FsbusWrite(C_LMASTFLIGHTL, 0);
FsWrite(FS_FLIGHTDIRECTOR, 0);
}
break;


Stefan

RobiD
07-24-2009, 08:29 AM
ok, i only mean the FD Funktion but ok.

Sorry, I misunderstood your question.
Thank you, thank you, thank you for your help again!!

Very much appreciated.

David

RobiD
08-28-2009, 10:26 PM
Stefan,

I have another question or rather asking your advice.

I have almost finished wiring up the MCP in which I have made another DIO and display 6pack.

So, my question.

I have designed and made my own Korry replicas and I have an amber light in the bottom half to indicate the switch is active, and I have a green led in the top half to light up the legend ie: APP, HDG SEL etc.

I want the green legend leds to light up when the Master Avionics switch is on.

Do I use the 0x3103 offset (which is the one I've used for the Switch)?

There are 8 green leds that I want to light using the digital out on the DIO board, so how do I write that same value to 8 different addresses.

void cbIndicatorlightsBuildObjects()
{
MkFsbusObject(BTP_D_OUT, C_LEDMCPLEGEND1,"MCP Legend LED",cbIndicatorlights,27,11);
MkFsbusObject(BTP_D_OUT, C_LEDMCPLEGEND2,"MCP Legend LED",cbIndicatorlights,27,12);
MkFsbusObject(BTP_D_OUT, C_LEDMCPLEGEND3,"MCP Legend LED",cbIndicatorlights,27,13);
MkFsbusObject(BTP_D_OUT, C_LEDMCPLEGEND4,"MCP Legend LED",cbIndicatorlights,27,14);
etc>>> to 8




MkFsObject(FS_AVIONICS,"",cbSwitches,0x3103,1,TP_I8,FS_NORMAL);
}
void cbIndicatorlights (int oid, int val, double dval)
{
switch (oid)
{
case FS_AVIONICS:
FsbusWrite (C_LEDMCPLEGEND1, val);
FsbusWrite (C_LEDMCPLEGEND2, val);
FsbusWrite (C_LEDMCPLEGEND3, val);
FsbusWrite (C_LEDMCPLEGEND4, val);
FsbusWrite (C_LEDMCPLEGEND5, val);
UP TO 8
break;


Will this do the job.

Thanks
David

sgaert
08-30-2009, 04:11 AM
Hi,

the way is right.
Do that work or do you have problems?

I see that FS_AVIONICS you refary to cbSwitches but you use it in cbIndicatorlights. That can be a problem. Maybe you try a global Eventhandler, than you dont have such problems.

Stefan

RobiD
08-30-2009, 05:07 AM
Hi,

the way is right.
Do that work or do you have problems?

I see that FS_AVIONICS you refary to cbSwitches but you use it in cbIndicatorlights. That can be a problem. Maybe you try a global Eventhandler, than you dont have such problems.

HI Stefan,

Go to hear from you.

Yes it does work this way.

Yes I did have a problem with declaring FS_AVIONICS twice so I moved the code into the Indicatorlights Group and all is good.

Thanks

I'm still not sure how to do the global Eventhandler though, this would have been a simpler solution to keep all the relevant code in the relevant files.

Regards
David

RobiD
10-09-2009, 06:13 AM
Hi Stefan,

I have a little problem I'm hoping you can help me with.

It's been a little while since I've been able to do any work on the sim.

The other day, I finally connected the ADF and Exponder displays up permanently and fired up the sim.

Strange things are happening. As you know, I have built the code up bit by bit and it has worked all the way through.

Here is what is happening:

Some switches are not working (even though they work in FSAdmin)

The servos are doing strange things (although the do follow the software gauges most of the time)

The voltmeters are doing their own thing

The displays will not display correctly (they test fine in FSADmin), they will not display what is on the screen, although the rotaries are changing the setting on the screen and on the display (not the same though), and the decimal point is missing (works in FSAdmin) then the servos in the gauges move rapidly and the displays go out. If I turn the rotaries, the displays light up again (incorrectly) and then the servos move rapidly and the displays go out.

The push button on the rotaries are not working either (they do in FSAdmin).

So, as you can see, there is a lot of things not working how they used to or should. Nothing has changed apart from time.

What can you suggest. Have you had this happen before.

Appreciate you help.
Thanks
David

sgaert
10-10-2009, 03:50 AM
Hi,

oh yes, that sounds realy crazy.
The first i would try is to check the code and rebuild the exe.

Stefan

RobiD
10-10-2009, 04:06 AM
Hi Stefan,

Thanks for responding.

I have tried rebuilding the code. Nothing really has been changed since you helped me with the FS_AVIONICS solution. That worked without any problems.

Not sure where to go from here to problem solve. Oh, one oddity. I use the same 10 pin bus cable from the Com board to the DIO and then onto the Servo board.

The servo board keeps taking on the CID of the DIO board (CID27) so I have to reflash the CID on the servo board.

This is an example of when this happens: I want to declare a rotary switch on my DIO board so I disconnect everything connected to the Com board other than the DIO board and I disconnect the Servo Board from the end of the cable.

After I've declared the Rotary (or anything else I need to do with the DIO board) I take the jumper off, connect everything back up and when I reconnect the servo board, I get 27 being displayed on the LED of the servo board which means even though the jumper is not on the Servo board or the DIO board, it's CID is being changed.

I hope I can resolve this without having to restart the coding process from the beginning.

Thanks
David

sgaert
10-10-2009, 04:16 AM
Ah interessting.
A year ago i had the same problem, always changing CID and non stored parameters in the controllers. My solution was to erase the Controller Chip and reflasch them new incl. the EEPROM part. Sometimes the EEPROM part was not erase or flash able. Than i renew that Controllers. Since that time i have some Controller for backup in my toolbox.

Stefan

RobiD
10-10-2009, 04:50 AM
I thought this might have been my next step.

So reflash each controller chip with the hex (which is the EEPROM part, is that the fusebits?).

This may sound like an obvious questions but, will I need to reset the zero points on the servos, redeclare rotaries etc. etc.

David

sgaert
10-10-2009, 05:07 AM
Hi,
the EEPROM part is the blue characters part in Ponyprog.
In the EEPROM part the all parameters are saved.
You have to set the parameters new.

In ponyprog you find a butten called erase.

Stefan

RobiD
10-10-2009, 05:35 AM
Thanks Stefan, I'll let you know how it goes.

Regards
David

RobiD
10-10-2009, 07:16 PM
I have reflashed the DIO to check it first. I just left the DIO board connected and tested it out.

Everything seems to work ok, although now there seems to be a time lag from changing something in the cockpit to it happening in the software (it's only fractions of a second as compared to instantly before).

I then plugged in the 6pack Display board and everything seems to work other than the decimal point (I will reflash these incase they became corrupt).

I then plugged in servo card and this is where things went funny. There may be a power problem (I have the seperate 5vdc connected to the servo card for power) for a few moments, the servos were ok, then it was like a power surge to the servos, they moved rapidly and then the displays went out. The displays can be lit up again by moving the associated rotary.

As the servos are poling to maintain a set position, there is a (I'll describe it like this) electrical wave that travels through the displays, lcd monitor, and then there is the surge in the servos and it all happens again.

The 'electrical wave' is like an electrical interferrence.

Does this information give you any ideas?

Thanks again
David

sgaert
10-11-2009, 03:40 AM
I then plugged in the 6pack Display board and everything seems to work other than the decimal point (I will reflash these incase they became corrupt).
I know the problem with the decimal point. If you set them at Build of the Objekts than he not work. But if you make them later in your code every thing is ok.

Your Servo problem sounds strange. Do you checked you 5V Power supply?
Maybe put only 1 Servo to the board and try 5V from the Databus as Power.

Stefan

RobiD
10-11-2009, 04:30 AM
I know the problem with the decimal point. If you set them at Build of the Objekts than he not work. But if you make them later in your code every thing is ok.

Your Servo problem sounds strange. Do you checked you 5V Power supply?
Maybe put only 1 Servo to the board and try 5V from the Databus as Power.

Stefan


Hi Stefan,

The decimal point displayed correctly before this all happened.
I will reflash the display controllers and see.

It also may seem like there is too much load on the system ie: when the displays go out, if I leave them out, the servos stay stable. When I reactivate the displays, that is when it happens again.

I have tried a seperate power supply to the servos with no difference (I am running com board and some lighting and the servos off the same ATX power supply - this worked fine before)

I'll let you know how the reflashing goes.

Thanks
David

RobiD
10-23-2009, 11:09 PM
Hi Stefan,

Here's an update on my little problem.

I have reflashed and redelegated my DIO board, reflashed the Servo board (then it took on the CID of the DIO board again ie: Set the DIO to 27, removed the jumper, removed the 10 pin bus cable, set the CID on the servo, removed the jumper, verified that the leds on the boards indicated the correct CID).

I am going to use a seperate 10 pin bus cable to the servo board although this should not make a difference.

I may have found the problem with everything going funny. One of the servos has stopped working but it is getting hot. When I unplug this servo, everything seems to be ok.

I may have cooked this servo. Any thoughts?

I am yet to reflash the displays as I have all back up and running but 1 is missing the decimal point.

David

RobiD
11-14-2009, 12:01 AM
Hi Stefan,

Here is a further update to my problem.

I have now reflashed every chip in my collection.

Everything is now working well.

If for some reason I remove the 10 pin cable from the servo board and plug it back in, even if nothing else in plugged in, it takes on the CID of 27.

I tried to set the CID on the servo board without the jumper set (incase there was a short) and it would only reset with the jumper (as it should be).

Do you have any idea how this board can be changing it's CID on it's own like this?

It is very strange, and why 27, why not the default 31?

I look forward to your feedback (or anyone elses if someone has come across this before)

Regards
David

sgaert
11-14-2009, 05:30 AM
Hi David,

yes have an idea what is happend.
But at the moment the way is not verified.
We talk by PM.

Stefan

RobiD
11-14-2009, 05:32 PM
If the controller is resetting this often, I must have a fault somewhere.

What type of events will cause the controller to reset?

Could this be a power supply problem? I am using a Computer power supply to provide power to the servo board and it is also supplying the power to the Com board, a couple of 12vdc computer ventilation fans and a couple of other things.

I also sent you a PM in response to your PM.

Thanks again Stefan, you are always a source of good knowledge and help.

David

sgaert
11-14-2009, 05:53 PM
Hi David,
now we go on the way of the solution.
What i write to you, has enable a low Voltage protection. Your 5V Power goes lower than 2,4V that is one reason why the CID will be reset. Now that donīt happend anymore but the complete Controller makes the reset. :mrgreen:
You drive the Servos with the same Power??

Please check your powersupply system maybe it have to less power.

Stefan

RobiD
11-14-2009, 09:46 PM
Hi Stefan,

Yes, I do use the same PSU for the Com and the extra power line for the servos.

When you say "if the 5vdc power goes less than 2.4vdc" are you referring to the power coming from the com board through the 10 pin connector to the servo board or do you mean from the additional power line coming onto the servo board.

I have not yet tried your suggestion in the PM you sent.

Could I reprogram the code so that all servo commands are to contoller 27 and make the servo CID27 and change the DIO to CID25.

Is this a basic work around that should work long term?

Thanks
David

sgaert
11-15-2009, 05:44 AM
HI,

ok. i thought that you set the options. The Resets of the ICīs would be the result.
Yes i mean that you use the Power for the Servos over the Com Card.
You can plug the power direct to the Servo Card.

Stefan

RobiD
11-15-2009, 06:02 AM
Hi Stefan,

I haven't set the options you have given me in the fuse bits yet.

I wanted to check if changing the CID's I use in the programming so that the Servo card is 27 (so when it resets, it doesn't change everything) would be a simple solution before I tried the fuse bits option and possibly cooked my chips.

I have a seperate power line which supplies 5vdc to the servo from the same power supply I use for the Com board (also 5vdc)

I am willing to give the fuse bits option a go if you feel this is the best solution. No, I won't hold you responsible if I cook the chip (I will just set the servo board chip and see how it goes).

Thanks
David

sgaert
11-15-2009, 06:15 AM
I would try to set the Fuses, it is a protection against problems like losing CID. if you need i can make a screenshot of the Fuse Bit window in Ponyprog.

Stefan

RobiD
11-15-2009, 07:07 AM
Thanks, I would appreciate the screen shot just to be safe.

Regards
David

sgaert
11-15-2009, 07:20 AM
Hi,

i send the Screeshot by Mail.

Stefan

RobiD
11-15-2009, 07:41 AM
Thanks Stefan.

Are those setting for the 2313's?

David

sgaert
11-15-2009, 09:18 AM
that is right.

388TH_A
12-03-2009, 12:31 AM
OK WOW i feel dumb now i should have came here first but no... in stead i have been spending a week on this and going to the library and reading books and just plain messing with C++ just to get something to work right. But if i came here i could have coped and pasted some of your guys code to get me off on a faster foot in the right direction instead of a slow one. Anyways i am only trying to get my COM1 Display to work and so far i got it to show for example in FSX the Freq is 118.00 but on the display it shows 080.00 instead. I have coped some of the code in here from the manual and also typing in things just to see if it would work. But here is my code any ideas on how i can get this to work so i can move on to getting others to work also. Thanks in advance!!!


FSBUScockpit.cpp

// FSBUScockpit.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
int v = GetFsbusDLLVersion ();
if (v < 100)
{
printf ("Program requires Fsbus DLL version 1.0.0 or higher\r\n");
return 1;
}

CheckIn();
FsbusOpen ("COM1");

BuildRadiostackObjects(); // TODO: add more of your individual Build.. functions HERE

printf ("FSBUS hardware connected ...\r\n");

FsConnect();
printf ("Flightsim connected ...\r\n");

//TODO: add functions to create the fsbus software objects
printf ("press any key to exit ...\r\n");

while (!_kbhit())
FsbusMux(500);
}

//---------------------------------------------------------------------------
void EventCallback (int oid, int val, double dval)
{
switch (oid & OID_GROUP_MASK)
{
case OID_RADIOSTACK_GROUP:
cbRadiostack (oid, val, dval);
// TODO: add the group handlers of your individual cockpit groups
}
}


stdafx.h

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>

// TODO: reference additional headers your program requires here
#include "fsbus.h"

#include "radiostack.h"


stdafx.cpp

#include "stdafx.h"


radiostack.cpp

#include "stdafx.h"

void BuildRadiostackObjects ()
{

MkFsbusObject (BTP_DISPLAY, C_COM1DISPLAY, "COM1DISPLAY", cbRadiostack, 1, 0);
DisplayOptions (C_COM1DISPLAY, 5, 0, true, 3);
MkFsObject(FS_RADIOSTACKCOM1, "COM1DISPLAY", cbRadiostack, 0x034E, 2, TP_UI16, FS_NORMAL);
}

void cbRadiostack (int oid, int val, double dval)
{
int x;
static int COM1 = 0;

switch (oid)
{
case C_COM1DISPLAY:
x = BCD2Int(COM1);
x += val*5;
if (x > 13697)
x = 13697;
if (x < 11800)
x = 11800;
COM1 = Int2BCD(x);
FsWrite (FS_RADIOSTACKCOM1, (COM1&0x0fff0) >> 4);
FsbusWrite (C_COM1DISPLAY, x);
break;

case FS_RADIOSTACKCOM1:
// main 3 digits, in Binary Coded Decimal.
// A frequency of 1234.5 will have 0x0234 here
// and 0x0105 in offset 0356.
x = val;
COM1 = (COM1 & 0xf000f) | (x << 4);
FsbusWrite (C_COM1DISPLAY, BCD2Int(COM1));
break;

}
}

radiostack.h

#ifndef __RADIOSTACK_H
#define __RADIOSTACK_H

#define OID_RADIOSTACK_GROUP (1 << OID_CONTROL_BITS)
// any OID_xxx_GROUP should have a unique number, left shifted by OID_CONTROL_BITS

// declaration of all (max 32) objects of this group
#define C_COM1DISPLAY OID_RADIOSTACK_GROUP + 0
#define FS_RADIOSTACKCOM1 OID_RADIOSTACK_GROUP + 1

// declare the functions in the corresponding .cpp file
void BuildRadiostackObjects();
void cbRadiostack (int oid, int val, double dval);

#endif

RobiD
12-03-2009, 05:52 AM
Hey Stefan,

Hope you can find the problem here, I've spent some time going through it and comparing it to my code and I think my brain has fried.

I know I had a similar issue at one point and resolved it. It was something simple but I can't remember what it was.

I used the same format as my ADF and changed around the object names etc and it all worked.

Remembering, I am using a single rotary with a push switch in it.

Here's the base code I used for the ADF. Hope it helps a little.
This is the .cpp code


staticint ADF1 = 0; // binary, units 0.1 KHz
staticint ADF1Stb = 0; // binary, units 0.1
/*
adf1_dec and adf1_fra are
static int variables (read/write from the corresponding fsuipc offsets)
*/
staticint adf1_dec;
staticint adf1_fra;
staticint adfmode=0;
void cbNavBuildObjects()
{
MkFsbusObject (BTP_ROTARY, C_RADF,"",cbNav, 27,32);
MkFsbusObject (BTP_D_IN, C_ADFPush,"",cbNav, 27, 16);
MkFsbusObject(BTP_DISPLAY, C_DADF_1, "",cbNav, 14, 0);
DisplayOptions(C_DADF_1,5,0,TRUE,2);
MkFsObject(FS_EXTENDEDADF1,"",cbNav,0x0356, 2,TP_UI16,FS_NORMAL);
MkFsObject(FS_ADF1FREQUENCY,"",cbNav,0x034C, 2,TP_UI16,FS_NORMAL);
}
void cbNav (int oid, int val, double dval)
{
int x;
switch (oid)
{
case FS_ADF1FREQUENCY:
ADF1 = (ADF1 / 10000) * 10000 + BCD2Int(val) * 10 + ADF1 % 10;
FsbusWrite(C_DADF_1, ADF1);
if (bSynchronised == false)
{
ADF1Stb = ADF1;
FsbusWrite(C_DADF_1, ADF1Stb);
}
break;
case FS_EXTENDEDADF1:ADF1 = BCD2Int(val >> 8) * 10000 + ((ADF1/10)%1000)*10 + BCD2Int(val & 0x00FF);FsbusWrite(C_DADF_1, ADF1);if (bSynchronised == false)
{
ADF1Stb = ADF1;
FsbusWrite(C_DADF_1, ADF1Stb);
}
break;

case C_ADFPush:
if(val==0)
{
adfmode+=1;
if (adfmode>2)
adfmode=0;
}
break;

case C_RADF:
if (adfmode==0)
{
x = ADF1Stb / 1000; // hundreds
x = x + val; // update 100s
if (x > 17)
x = 1; // wrap
elseif (x < 1)
x = 17; // wrap
ADF1Stb = x * 1000 + ADF1Stb % 1000; // new 100s
FsbusWrite(C_DADF_1, ADF1Stb);
x = Int2BCD(ADF1Stb);
FsWrite(FS_EXTENDEDADF1, ((x & 0x0F0000) >> 8) | (x & 0x00000F));
FsWrite(FS_ADF1FREQUENCY, (x & 0x00FFF0) >> 4);
}
if (adfmode==1)
{
x = (ADF1Stb % 1000) / 10; // tens + units
x = x + val; // update 10s
if (x > 99)
x = 0; // wrap
elseif (x < 0)
x = 99; // wrap
ADF1Stb = (ADF1Stb / 1000) * 1000 + x * 10 + ADF1Stb % 10; // new 10s
FsbusWrite(C_DADF_1, ADF1Stb);
x = Int2BCD(ADF1Stb);
FsWrite(FS_EXTENDEDADF1, ((x & 0x0F0000) >> 8) | (x & 0x00000F));
FsWrite(FS_ADF1FREQUENCY, (x & 0x00FFF0) >> 4);
}
if (adfmode==2)
{
x = ADF1Stb % 10; // .1 units
x = x + val; // update 10s
if (x > 9)
x = 0; // wrap
elseif (x < 0)
x = 9; // wrap
ADF1Stb = (ADF1Stb / 10) * 10 + x;
FsbusWrite(C_DADF_1, ADF1Stb);
x = Int2BCD(ADF1Stb);
FsWrite(FS_EXTENDEDADF1, ((x & 0x0F0000) >> 8) | (x & 0x00000F));
FsWrite(FS_ADF1FREQUENCY, (x & 0x00FFF0) >> 4);
}
break;
}
}

sgaert
12-03-2009, 01:37 PM
radiostack.cpp

#include "stdafx.h"

void BuildRadiostackObjects ()
{

MkFsbusObject (BTP_DISPLAY, C_COM1DISPLAY, "COM1DISPLAY", cbRadiostack, 1, 0);
DisplayOptions (C_COM1DISPLAY, 5, 0, true, 3);
MkFsObject(FS_RADIOSTACKCOM1, "COM1DISPLAY", cbRadiostack, 0x034E, 2, TP_UI16, FS_NORMAL);
}

void cbRadiostack (int oid, int val, double dval)
{
int x;
static int COM1 = 0;

switch (oid)
{
case C_COM1DISPLAY:
x = BCD2Int(COM1);
x += val*5;
if (x > 13697)
x = 13697;
if (x < 11800)
x = 11800;
COM1 = Int2BCD(x);
FsWrite (FS_RADIOSTACKCOM1, (COM1&0x0fff0) >> 4);
FsbusWrite (C_COM1DISPLAY, x);
break;

case FS_RADIOSTACKCOM1:
// main 3 digits, in Binary Coded Decimal.
// A frequency of 1234.5 will have 0x0234 here
// and 0x0105 in offset 0356.
x = val;
COM1 = (COM1 & 0xf000f) | (x << 4);
FsbusWrite (C_COM1DISPLAY, BCD2Int(COM1));
break;

}
}


HI,

you have used code from ADF that is not like COM or NAV.
Her some Code that will work.

case C_COM1DISPLAY:
x = BCD2Int(COM1);
x += val*5;
if (x > 13697)
x = 13697;
if (x < 11800)
x = 11800;
COM1 = Int2BCD(x);
FsWrite (FS_RADIOSTACKCOM1, COM1);
FsbusWrite (C_COM1DISPLAY, x);
break;
But with that Code you will have problems with the 25, 50, 75, 00 order.
Her my Code, but i use 2 encoder.

case C_COM1ROTARYnk:
comstby = BCD2Int(COM1S);
//x1=2, if last digit =2;
/***********************/
x2=comstby/10;
x2=x2*10;
x1=comstby-x2;
comstby = comstby *10;
if((x1==2) | (x1==7))
comstby+= 5;
comstby += val * 25;
x3=comstby;
x3/=10;
comstby=x3;
/***********************/
if (comstby > 3697)
comstby = 3697;
if (comstby < 1800)
comstby = 1800;
COM1S = Int2BCD(comstby);
FsbusWrite (C_COM1DisplayS, comstby+10000);
FsWrite (FS_COM1STANDBY, COM1S);
break;

case C_COM1ROTARYvk:
comstby = BCD2Int(COM1S);
comstby += val * 100;
if (comstby > 3697)
comstby = 3600 + comstby%100;
if (comstby < 1800){
comstby = 1800 + comstby%100;
}
COM1S = Int2BCD(comstby);
FsbusWrite (C_COM1DisplayS, comstby+10000);
FsWrite (FS_COM1STANDBY, COM1S);
break;
Her my code for the back way FS to Hardware.

case FS_COM1FREQUENCY:
// main 3 digits, in Binary Coded Decimal.
// A frequency of 1234.5 will have 0x0234 here
// and 0x0105 in offset 0356.
COM1= val;
FsbusWrite(C_COM1DisplayA, BCD2Int(COM1)+10000);
break;

Stefan

sgaert
12-03-2009, 01:57 PM
Hey Stefan,

Hope you can find the problem here, I've spent some time going through it and comparing it to my code and I think my brain has fried.

I know I had a similar issue at one point and resolved it. It was something simple but I can't remember what it was.

I used the same format as my ADF and changed around the object names etc and it all worked.

Remembering, I am using a single rotary with a push switch in it.

Here's the base code I used for the ADF. Hope it helps a little.


Hi,
what errors do you have, i cant see a bug.
I only find to things but i think that are only format errors in the board.
staticint = wrong
static int = right
elseif = wrong
else if = right

If it is more, describe what error you have.

Stefan

RobiD
12-03-2009, 05:50 PM
Hi Stefan,

No, mine is working (thanks to your previous help). I put my code up to try to help 388TH_A with his COM1.

I thought you might be able to find his problem.

David

388TH_A
12-04-2009, 12:09 AM
Thanks you SO much it help and works but when i load up the exe it resets the display shows all 00000 then shows the right freq for whats in FS. But.... i change it to one freq to another it works fine but after the 3 or 4th freq change it starts to show the wrong freq like one time i got it to so 147.35 ummm thats not right lol any ideas? and how do you guys show your code in blue like that? AND THANKS AGAIN FOR THE HELP. Im so close to moving on to Com1 Stby and then Com2 and so on








void cbRadiostack (int oid, int val, double dval)
{
int x;
static int COM1 = 0;

switch (oid)
{
case C_COM1DISPLAY:
x = BCD2Int(COM1);
x += val*5;
if (x > 13697)
x = 13697;
if (x < 11800)
x = 11800;
COM1 = Int2BCD(x);
FsWrite (FS_RADIOSTACKCOM1, (COM1));
FsbusWrite (C_COM1DISPLAY, x);
break;

case FS_RADIOSTACKCOM1:
// main 3 digits, in Binary Coded Decimal.
// A frequency of 1234.5 will have 0x0234 here
// and 0x0105 in offset 0356.
x = val;
COM1 = (COM1) | (x);
FsbusWrite (C_COM1DISPLAY, BCD2Int(COM1)+10000);
break;

}
}

388TH_A
12-04-2009, 12:14 AM
i just went from 126.22 and it shows that on the Display then changed it to 118.00 and it showed 144.62 ummm....

Thanks, Trevor

388TH_A
12-10-2009, 12:09 AM
#include "stdafx.h"

void BuildRadiostackObjects ()
{

MkFsbusObject (BTP_DISPLAY, C_COM1DISPLAY, "COM1DISPLAY", cbRadiostack, 1, 0);
DisplayOptions (C_COM1DISPLAY, 5, 0, true, 3);
MkFsObject(FS_RADIOSTACKCOM1, "COM1DISPLAY", cbRadiostack, 0x034E, 2, TP_UI16, FS_NORMAL);
}

void cbRadiostack (int oid, int val, double dval)
{
int x;
static int COM1 = 0;

switch (oid)
{
case C_COM1DISPLAY:
x = BCD2Int(COM1);
x += val*5;
if (x > 13697)
x = 13697;
if (x < 11800)
x = 11800;
COM1 = Int2BCD(x);
FsWrite (FS_RADIOSTACKCOM1, (COM1));
FsbusWrite (C_COM1DISPLAY, x);
break;

case FS_RADIOSTACKCOM1:
x = val;
COM1 = (COM1) | (x);
FsbusWrite (C_COM1DISPLAY, BCD2Int(COM1)+10000);
break;

}
}



Why does in FS and on the display when i first start the program show the same thing 126.22 but then when i change it to 118.00 and it showed 118.00 in FS but on the display it showed 144.62? am i missing somthing?

sgaert
12-10-2009, 03:06 AM
Hi,
that code was a sample, but that donīt work correct.
The first thin is you cant work with the full frequenz, the FS dont understand that.
118.000 = wrong
18.000 = right

Use my working Code from my post.

Stefan

388TH_A
12-10-2009, 08:56 AM
your code didnt work for me it helped but didnt work. So then i tried instead and now i only get 14*.** so yeah



case C_COM1DISPLAY:
x = BCD2Int(COM1);
x += val*5;
if (x > 3697)
x = 3697;
if (x < 1800)
x = 1800;
COM1 = Int2BCD(x);
FsWrite (FS_RADIOSTACKCOM1, (COM1));
FsbusWrite (C_COM1DISPLAY, x);
break;

case FS_RADIOSTACKCOM1:
// main 3 digits, in Binary Coded Decimal.
// A frequency of 1234.5 will have 0x0234 here
// and 0x0105 in offset 0356.
x = val;
COM1 = (COM1) | (x);
FsbusWrite (C_COM1DISPLAY, BCD2Int(COM1)+10000);
break;

388TH_A
12-10-2009, 09:22 AM
ok so playing with it more looks like if i start out with

FS Freq FSBUS Dis Freq
118.00 118.00
118.02 118.02
118.00 118.02
118.05 118.05
118.00 118.05
118.10 118.15
118.17 118.17
122.20 140.97

Seems like the highest digit that it shows it will only display that but wont ever go lower. But then when i went to the 122 freqs it jumped to the 140 freq range so yeah im not sure on where to go from here.

sgaert
12-10-2009, 04:52 PM
Hi,
that part of the code has one error.

x += val*5;

The COM Radion has no 5 as stepsize. It is 25. Your code if for NAV.

Code like that will fix that.

x2=comstby/10;
x2=x2*10;
x1=comstby-x2;
comstby = comstby *10;
if((x1==2) | (x1==7))
comstby+= 5;
comstby += val * 25;
x3=comstby;
x3/=10;
comstby=x3

Stefan

cscotthendry
12-12-2009, 10:14 PM
your code didnt work for me it helped but didnt work. So then i tried instead and now i only get 14*.** so yeah



case C_COM1DISPLAY:
x = BCD2Int(COM1);
x += val*5;
if (x > 3697)
x = 3697;
if (x < 1800)
x = 1800;
COM1 = Int2BCD(x);
FsWrite (FS_RADIOSTACKCOM1, (COM1));
FsbusWrite (C_COM1DISPLAY, x);
break;

case FS_RADIOSTACKCOM1:
// main 3 digits, in Binary Coded Decimal.
// A frequency of 1234.5 will have 0x0234 here
// and 0x0105 in offset 0356.
x = val;
COM1 = (COM1) | (x);
FsbusWrite (C_COM1DISPLAY, BCD2Int(COM1)+10000);
break;

Hi:

I don't know much about FSBus, but I do know a little about C++, so I'll have a little stab at this for you. There is a line that makes me a little suspicious about the fault that you report. The fault that I think you're reporting is that when you increase from 118.00 to 118.02 and then go back to 118.00 the display stays at 118.02. The line I am suspicious of is
COM1 = (COM1) | (x);
In this statement, you are logically ORing the new value with the old value. Without going into a lesson on boolean logic, I think this line is preserving the higher values. What happens if you just use
COM1 = x;
???

388TH_A
12-13-2009, 05:33 AM
Hi:

I don't know much about FSBus, but I do know a little about C++, so I'll have a little stab at this for you. There is a line that makes me a little suspicious about the fault that you report. The fault that I think you're reporting is that when you increase from 118.00 to 118.02 and then go back to 118.00 the display stays at 118.02. The line I am suspicious of is
COM1 = (COM1) | (x);
In this statement, you are logically ORing the new value with the old value. Without going into a lesson on boolean logic, I think this line is preserving the higher values. What happens if you just use
COM1 = x;
???

WOW that was the problem and now it works just fine with no ERRORS THANK YOU SO MUCH!!!

cscotthendry
12-13-2009, 03:39 PM
Glad I could help.

388TH_A
12-16-2009, 12:21 PM
For the Avionics Bus Volt. 0x2850 FLT64 8 Bit Do you know if i can use this in my project? In FS Interrogate I can get it to show the value that its getting from the FS but it also says in it that NOT FSUIPC SUPPORTED but yet it does get a value from the FS so again do you know if i can use this or not?

sgaert
12-16-2009, 02:21 PM
You can use that.
What are your intentions with that Offset?
I use them to switch off my cockpit.

Stefan

388TH_A
12-16-2009, 11:01 PM
The same was wanting to add it into the C++ to turn off my radio stack only

388TH_A
12-17-2009, 02:00 AM
Yep your right it does work i got it to work with my COM1 display

sgaert
12-17-2009, 02:13 PM
Now broadcast the comand (CID 0) and all Displays will react.

Stefan

388TH_A
12-17-2009, 10:47 PM
thats what im doing and it works great. Now every thing will turn off when the power to them turns off.

RobiD
12-18-2009, 02:45 AM
Can you show me how you did this.

When I turn my master avionics switch off, in the software, all the radio stack go out, by my actual radio stack stays lit.

I'd like to also do this with my battery switch, when I turn the battery switch off in the cockpit, all the gauges ie: fuel, oil pump, fuel pump etc all turn off on the screen, but in my cockpit, the air core gauges do not turn off as they should.

Appreciate the help from all as always.

David

sgaert
12-18-2009, 12:48 PM
Here you have my function.


MkFsObject(FS_BUSVOLT,"", EventHandler, 0x2834, 8, TP_DBL, FS_NORMAL)

case FS_BUSVOLT:
// send the voltage information as a percent value
// to all controllers with command 131.
int spannung = (val * 100 / 24);
if (spannung != SpannungSave)
{
FsbusWriteFmt3 (0, 131,spannung);
SpannungSave=spannung;
}
break;

The Servos you have to drive by your self.

Stefan

388TH_A
12-18-2009, 01:35 PM
in my .CPP i put this but this is the Offset for the Avionics but you can change it to the main Battery one if you want


#include "stdafx.h"

void BuildRadiostackObjects ()
{

MkFsObject(FS_BUSVOLT, "BUSVOLTS", cbBusvolt, 0x2850, 8, TP_I64, FS_QUICK);
}

void cbBusvolt (int oid, int val, double dval)
{
switch (oid)
{
case FS_BUSVOLT:
FsbusWriteFmt3 (0, 131, val * 100 / 24 );

}
}

RobiD
12-18-2009, 05:45 PM
Thanks guys, I'll put it in the code and see how it goes.

I'll let you know.

David

RobiD
12-21-2009, 07:55 AM
Finally got the time to test out the code.

Here what is happening.

When I start FSX, the displays (in my cockpit) are lit even though the cockpit is cold and dark in the software (there must be a syncronize command somewhere to add in).

As I go through the start up sequence, I turn the avionics on and the displays start flashing on and off.

When I start the engine, the displays go out.

When I stop the engine, displays start flashing again.

When I turn the avionics switch off, displays go off (this part is working well)

Any ideas on what I need to tweak?

Do you want me to post the code from the .cpp file this code is in?

Ah, I'd do it anyway:


#include "stdafx.h"

void cbVoltmetersBuildObjects()
{
MkFsbusObject (BTP_A_OUT,C_FUELLEFT,"Left Fuel Gauge",cbVoltmeters,27,86);
MkFsbusObject (BTP_A_OUT,C_FUELRIGHT,"Right Fuel Gauge",cbVoltmeters,27,84);
MkFsbusObject (BTP_A_OUT,C_OILPRESSURE,"Oil Pressure Gauges",cbVoltmeters,27,87);
MkFsbusObject (BTP_A_OUT,C_OILTEMP,"Oil Temp Gauges",cbVoltmeters,27,85);
MkFsbusObject (BTP_A_OUT,C_MAINBUSAMPS,"Main Bus Amp Gauge",cbVoltmeters,27,83);
MkFsbusObject (BTP_A_OUT,C_FUELPRESSURE,"Fuel Pressure Gauge",cbVoltmeters,27,82);

MkFsObject(FS_FUELLEFTMAINLEVEL,"Left Fuel Gauge",cbVoltmeters, 0x0B7C,4,TP_I32, FS_NORMAL);
MkFsObject(FS_FUELRIGHTMAINLEVEL,"Right Fuel Gauge",cbVoltmeters, 0x0B94,4,TP_I32, FS_NORMAL);
MkFsObject(FS_GENERALENGINE1OILPRESSURE,"Oil Pressure Gauge",cbVoltmeters,0x3B60,8,TP_DBL,FS_NORMAL);
MkFsObject(FS_ENGINE1OILTEMP,"Engine Oil Temp Gauge",cbVoltmeters,0x08B8,2,TP_I16,FS_NORMAL);
MkFsObject(FS_MAINBUSAMPS,"Main Bus amp Gauge",cbVoltmeters,0x282C,8,TP_DBL,FS_NORMAL);
MkFsObject(FS_FUELPRESSURE,"Fuel Pressure Gauge",cbVoltmeters,0x3868,8,TP_DBL,FS_NORMAL);
MkFsObject(FS_BUSVOLT, "BUSVOLTS", cbVoltmeters, 0x2850, 8, TP_I64, FS_QUICK);
}

void cbVoltmeters (int oid, int val, double dval)
{
switch (oid)
{
case FS_GENERALENGINE1OILPRESSURE:
{
val=(val / 41);

static CALTAB OILPRESSUREGauge[] = {
{0,255},{127,200},{255,0}
};
val = Calibrate (val, OILPRESSUREGauge,3);
FsbusWrite (C_OILPRESSURE, val);
}
break;

case FS_FUELLEFTMAINLEVEL:
{
static CALTAB FUELLEFTMAINGauge[] = {
{0,255},{4194304,155},{8388608,0}
};
val = Calibrate (val, FUELLEFTMAINGauge,3);
FsbusWrite (C_FUELLEFT, val);

}
break;

case FS_FUELRIGHTMAINLEVEL:
{
static CALTAB FUELRIGHTMAINGauge[] = {
{0,255},{4194304,155},{8388608,0}
};
val = Calibrate (val, FUELRIGHTMAINGauge,3);
FsbusWrite (C_FUELRIGHT, val);

}
break;

case FS_ENGINE1OILTEMP:
{
static CALTAB OILTEMPGauge[] = {
{0,255},{25000,0}
};
val = Calibrate (val, OILTEMPGauge,2);
FsbusWrite (C_OILTEMP, val);
}
break;

case FS_MAINBUSAMPS:
{

static CALTAB MAINBUSAMPSGauge[] = {
{-60,255},{0,177},{60,0}
};
val = Calibrate (val, MAINBUSAMPSGauge,3);
FsbusWrite (C_MAINBUSAMPS, val);
}
break;

case FS_FUELPRESSURE:
{
static CALTAB FUELPRESSUREGauge[] = {
{0,255},{10,230},{16,200},{40,0}
};
val = Calibrate (val, FUELPRESSUREGauge,4);
FsbusWrite (C_FUELPRESSURE, val);
}
break;

case FS_BUSVOLT:
{
FsbusWriteFmt3 (0, 131, val * 100 / 24 );
}
}

}

Thanks
David

388TH_A
12-21-2009, 03:02 PM
I dont see any Displays in your code what Displays are you talking about?

Trevor

RobiD
12-21-2009, 05:38 PM
Hi Trevor,

I've only copied the code for the voltmeters.cpp
The code for the displays are in various other relevant .cpp files

The displays I have programmed are:

Nav1 & Nav1 stby
ADF
XPNDR
MCP

all 7 seg led displays.
The code for most of it is in this thread as Stefan has helped me with just about all of it.

Another thing, if I turn the master battery switch off, the 7seg displays also go out as they should.

So I just can't get them to stay lit (stop flashing) when everything is turned on and engine not running and to stay lit (not turn off) when engine is started.

Hope I'm explaining myself clearly.

Thanks
David

PS. I'm going to try Stefan's code for this later today and see how that goes.


MkFsObject(FS_BUSVOLT,"", cbVoltmeters, 0x2834, 8, TP_DBL, FS_NORMAL)

case FS_BUSVOLT:
// send the voltage information as a percent value
// to all controllers with command 131.
int voltage = (val * 100 / 24);
if (voltage != VoltageSave)
{
FsbusWriteFmt3 (0, 131,voltage);
VoltageSave=voltage;
}
break;

sgaert
12-22-2009, 02:58 AM
I'm going to try Stefan's code for this later today and see how that goes.


MkFsObject(FS_BUSVOLT,"", cbVoltmeters, 0x2834, 8, TP_DBL, FS_NORMAL)

case FS_BUSVOLT:
// send the voltage information as a percent value
// to all controllers with command 131.
int voltage = (val * 100 / 24);
if (voltage != VoltageSave)
{
FsbusWriteFmt3 (0, 131,voltage);
VoltageSave=voltage;
}
break;

It is enought if you try my MkFsObject line.

Stefan

RobiD
12-22-2009, 05:56 AM
Hi Stefan and Trevor,

Tried your code line Stefan, but I think the offset was wrong.

This is what I've finished up using and it now works fine.

MkFsObject(FS_BUSVOLT, "BUSVOLTS", cbVoltmeters, 0x2850, 8, TP_DBL, FS_NORMAL);

Probably my only complaint is that FSBus isn't syncing with the software.
When I start FSX - FSBus dll, initially the 7 seg displays are lit, but if I flick the avionics switch on and off, the displays go off as they should be.

What is the best and easiest way to have FSBus sync with FSX so everything is right from the very start. (hope you understand what I mean).

Thanks
David

sgaert
12-22-2009, 06:11 AM
The Offset was the Battery Voltage that is the Value i need.
For other Offset maybe it is nessesary to change the calculation.

in my Cockpit 90% of the syncronisation work. If i reset an IO Controller he write the status of each Input to the bus.

Stefan

RobiD
12-22-2009, 06:59 AM
Hi Stefan,

Thanks for that bit of information.

I am reseting each display controller, and the displays are starting as 'Off' now which is what is displayed in the software.

I've used this command for each controller:

FsbusWriteFmt2(9,128,0); // Fsbus reset CID 9
FsbusMux(350);

Thanks again for the info.

David

sgaert
12-22-2009, 08:06 AM
I do that restart on every start with a broadcast to all controllers.

Stefan

388TH_A
12-23-2009, 03:07 PM
Sorry i have been working alot this week but glad to see you got it to your liking. I my self would rather see the displays on that way i know there working just a way for me to do a test on them to make sure they work before i get to far and then notice that a circuit board went bad on me for some reason.

RobiD
12-23-2009, 05:07 PM
Thanks Trevor.

RobiD
01-22-2010, 08:05 AM
Just an update on my progress for those that are interested.

Finally I have just completed my second DIO board and display six pack. I built these specifically for the MCP.

As usual, there were some teething problems when testing, fix, test again. So far, the MCP seems to be working well (thanks to Stefan for help with the code).

I'll try to post some images of it in action in the next few days.

Boy it's exciting when something you've build actually works.

Cheers
David

RobiD
01-24-2010, 02:08 AM
Stefan,

You may be able to answer this and save me lots and lots of time fault finding.

I have wired my MCP with the second DIO board and 6pac display board.
In all the messing with wiring, and moving 10 pin bus cables on and off, my first DIO board has stopped working.
If I put the jumper on J16, the green led lights up, but when I plug the 10pin cable in, it is not giving the CID flashes and of course, not working.

Have you done this before, or do you know what it could be before I start pulling everything apart.

Thanks
David

sgaert
01-24-2010, 04:15 AM
Hi,

do you use a new/different 10Pin Cable for the new setup?
Did you check the new Cable for shortcuts or any other faults?
Can you connect the New Board one by one with a 10 Pin Cable to the Com board and check the functions?

Stefan

RobiD
01-24-2010, 04:28 AM
The new board is working perfectly, but it's the old board suddenly doesn't work.

sgaert
01-24-2010, 04:31 AM
ah, ok.
How do you connect the old board to the setup, is it on the same cable like the new one.
or has it his own connector on the COM Board?

Stefan

RobiD
01-24-2010, 04:34 AM
The new board has it's own cable to the com board. The old DIO has a shared cable to the Servo board (you probably remember the problems with having the change the fuse bits on the servo board)

I was moving the cables (10pin) around to test a couple of things that weren't working on the new board and then the old one stopped.

Oh, I didn't change the fuse bits on the DIO, only the servo board

sgaert
01-24-2010, 04:43 AM
That all sound realy strange.
Do all parts of the board donīt work or only some parts?
Can you measure the 5V power on the Controller of the old board?

Stefan

RobiD
01-24-2010, 06:02 AM
Nothing works on the DIO board.

If I put the jumper on J16, the green led lights up so there is power going to the board.

Where is the easiest place to measure the 5vdc on the board?


David

sgaert
01-24-2010, 06:29 AM
pin 10 and 11 at the controller.
I would readout and verify the firmware in the Controller via PonyProg.

Stefan

RobiD
01-24-2010, 06:31 AM
Will do and I'll let you know.

David

RobiD
01-24-2010, 07:11 AM
Must be an intermittant fault, it's working now, but not sure for how long.

sgaert
01-24-2010, 07:14 AM
Ok, i had some problems with "erased" Controllers some times ago, that happend when i made a shortcut to the powersupply.

RobiD
01-24-2010, 07:19 AM
When it happens again, I'll check the voltage and whether or not I can read the firmware.

I may have shorted it out, but it doesn't seem to have erased the firmware as it's working perfectly at present.

Thanks again Stefan.

David