Sign in to follow this  
Guest PoRrEkE

VB.Net vs FSUIPC

Recommended Posts

Ok I have an issue here.I am using VB.Net for my "CockpitLink" program.The result I get is as follows:With my fsuipc code I can read the values; all goos well.I can write the virtual joystick buttons presses: all goos well.But when I do both in the same session .. the read values go mad.So each time I have to enable in my code the "read timer" OR the "write timer". Actually they are on the same timer but I have to put either of both commands as comment to prevent 1 of the 2 peices of code to be triggered.Now I will try using the VB.Net code from the SDK just 1 time more. But I think I remember from last time that code did not work at all.Anyone uses fsuipc with .Net ??

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Glad you solved the other problem :)Maybe you'd have better luck asking some help from Peter Dowson.I cannot help since i do not know VB at all :(

Share this post


Link to post
Share on other sites

The other problem is not solved :(I only know now for sure where the problem is. And sadly again it is out of my area. It is Espens panel .. so again I have to ask 3rd party to take action and maybe get me going soon.Asking Pete is what I did. The problem there is that Pete doesn't know .Net So I'd rather ask people using fsuipc and .Net in a combo.At the moment all I know is that Bob Scott made the .Net part of the fsuipc SDK. His code won't even compile so .. maybe I can contact him.Other than that I know that Scott L. Fausel is using .Net for his software but I haven't heard from him for a while. I suppose he's got a succesfull code to link the dll to .Net since he is selling his software.No responce from either of these 3 people so far.Anyone else knows of a .Net program that uses fsuipc ?

Share this post


Link to post
Share on other sites

I am currently involved in a FSUIPC/.Net project using C# and I have a few suggestions that might help.Your FSUIPC timer should Sleep() for 100 to 200ms. Don't let it run without some sort of built-in delay, otherwise you'll tie up the CPU at 100%Run the FSUIPC timer routine in it's own separate thread.DEFINITELY only call FSUIPC_Write and FSUIPC_READ (Or whatever they are called) in VB ONCE in your code, and inside the FSUIPC loop. Don't let other methods() make calls to FSUIPC. If you have to SET something inside a method for FSUIPC, set a flag or BIT value instead, then perform the FSUIPC call inside your FSUIPC loop, based on the flag value.Use the correct size INT values for FSUIPC. If you use INT(32) for a FSUIPC (Short) value, you will get screwy results.That should keep you busy for awhile ;-)

Share this post


Link to post
Share on other sites

-------Your FSUIPC timer should Sleep() for 100 to 200ms. Don't let it run without some sort of built-in delay, otherwise you'll tie up the CPU at 100%-------I have a timer that ticks every 200ms for reading the values.Then I have an other timer that ticks every 100ms (changed that now to 200) for scanning the Photon. The readings will change checkbox status and on check-changed events I will do a write command to fsuipc.-------Run the FSUIPC timer routine in it's own separate thread.-------? Don't understand what you mean.-------DEFINITELY only call FSUIPC_Write and FSUIPC_READ (Or whatever they are called) in VB ONCE in your code, and inside the FSUIPC loop. Don't let other methods() make calls to FSUIPC. If you have to SET something inside a method for FSUIPC, set a flag or BIT value instead, then perform the FSUIPC call inside your FSUIPC loop, based on the flag value.-------set a flag or bit value ?-------Use the correct size INT values for FSUIPC. If you use INT(32) for a FSUIPC (Short) value, you will get screwy results.That should keep you busy for awhile-------I hope you can give me some more info here. I do appreciate any help enormously! But it's not all clear to me yet.

Share this post


Link to post
Share on other sites

Ok I've thought about it. Do I understand it right that the problem occurs because I am reading every 200ms and sometimes I do a write. When it so happens that this read and write go at the same time, .. is it then when the problem gets created ?How then can I make sure these reads and writes never come at the same time ?

Share this post


Link to post
Share on other sites

>------->Run the FSUIPC timer routine in it's own separate thread.>------->>? Don't understand what you mean.>>-------Research 'Programming Multi-Threaded Applications in VB'. It sounds difficult, but instantiating multiple threads in VB is easy. If you have the FSUIPC loop running in a separate thread, you can have that loop always running inside it's own thread, while the rest of your code runs without encountering that 200MS delay. It will make your application run much faster. >DEFINITELY only call FSUIPC_Write and FSUIPC_READ (Or whatever>they are called) in VB ONCE in your code, and inside the>FSUIPC loop. Don't let other methods() make calls to FSUIPC.>If you have to SET something inside a method for FSUIPC, set a>flag or BIT value instead, then perform the FSUIPC call inside>your FSUIPC loop, based on the flag value.>------->>set a flag or bit value ?>>-------For example, if you have a method that sets the NAV1 frequency, set a variable instead. then inside the FSUIPC loop, set NAV1 using the variable value. Some programmers like to perform FSUIPC_Write() inside the NAV1() method (for example). This can get confusing.. not for the programmer, but for FSUIPCLikewise, say you have a method that can set the gear position. Here you'd use a flag (or just a SHORT()). Inside the Gear() Method, just set the variable to reflect the gear state, then inside your FSUIPC loop, you'd set the gear position based on the variable valueI guess it's easier to say "Perform all FSUIPC reads & writes inside the FSUIPC loop... not in other methods.">Use the correct size INT values for FSUIPC. If you use INT(32)>for a FSUIPC (Short) value, you will get screwy results.>------->>I hope you can give me some more info here. I do appreciate>any help enormously! But it's not all clear to me yet.If the FSUIPC offset is a 2-byte offset, use a SHORT(), not an INT() for your variable size. Likewise, if the offset is a 4-byte value, you would then use a variable the size of INT()

Share this post


Link to post
Share on other sites

Hmmz ...Ok, what I am doing is only writing to the "Virtual Joystick Buttons" offsets. So I'm not writing any NAV or Gear variables.Would it now be a sollution to not just write to that button offset a 1, then back a 0 (thats how the press is registered). Instead write in a loop always a 0 to it (over and over again) and only put a 1 in between when the button is pressed ?This thinking here made me realise that I was doing the write (value 1) and the write (value 2) directly after eachoter. I've now put a "Sleep(200)" in between.I'll check the help files for that Multi-Threaded thing.

Share this post


Link to post
Share on other sites

Here's my FSUIPC Thread in C#, but should give you an idea as to how to go about it...#region FSUIPC IO Methods and MCP External Variables Logic private void SetMCPState(){//---------------------------------------------------// READ MSFS Values (Moved 3/29)//--------------------------------------------------- result = fsuipc.FSUIPC_Read(offsetGetALT, 8, ref FSTokens[0], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetIAS, 4, ref FSTokens[1], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetBank, 4, ref FSTokens[2], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetFLAPS, 4, ref FSTokens[3], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetWOW, 4, ref FSTokens[4], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetLOC, 4, ref FSTokens[5], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGNDALT, 4, ref FSTokens[6], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetHDG, 4, ref FSTokens[7], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetMAGVAR,2, ref FSTokens[8], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetMACH, 2, ref FSTokens[9], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetTAS, 2, ref FSTokens[10], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetOAT, 2, ref FSTokens[11], ref dwResult); //Engine Status result = fsuipc.FSUIPC_Read(offsetGetEng1, 2, ref FSTokens[12], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetEng2, 2, ref FSTokens[13], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetEng3, 2, ref FSTokens[14], ref dwResult); result = fsuipc.FSUIPC_Read(offsetGetEng4, 2, ref FSTokens[15], ref dwResult); result = fsuipc.FSUIPC_Read(offsetBUCKET, 4, ref FSTokens[16], ref dwResult); #endregion #region WRITE FSUIPC VALUES (For Processing) //--------------------------------------------------- // WRITE MCP States (BUTTONS) //--------------------------------------------------- result = fsuipc.FSUIPC_Write(offsetAPMaster,AP_Master_State,ref token, ref dwResult); result = fsuipc.FSUIPC_Write(offsetATARM, ATARM_State, ref token, ref dwResult); result = fsuipc.FSUIPC_Write(offsetFD, FDMaster_State, ref token, ref dwResult); result = fsuipc.FSUIPC_Write(offsetHDG, HDG_State + HDGSEL_State, ref token, ref dwResult); result = fsuipc.FSUIPC_Write(offsetVS, VS_State, ref token, ref dwResult); result = fsuipc.FSUIPC_Write(offsetLOC, LOC_State, ref token, ref dwResult); result = fsuipc.FSUIPC_Write(offsetAPP, APP_State, ref token, ref dwResult); // Internal Systems-Specific data result = fsuipc.FSUIPC_Write(offsetBUCKET, BUCKET, ref token, ref dwResult); #endregion//----------------------------------------------//// Engine Combusting Logic ////----------------------------------------------////Check for Engine Out (Not Combusting)//Still got a bug here: AT ARM Turns off intermittently //when VS or ALT is pressed: TIming issue I suspectif((Engine1Combusting == 0 || Engine2Combusting == 0 || Engine3Combusting == 0 || Engine4Combusting == 0) && AircraftOnGround == 0 && ATARM_State == 1 ){Turn_ATARM_Off();}#endregion //Now Process the Entire batch!!fsuipc.FSUIPC_Process(ref dwResult);#region GET RESULTS FROM FSUIPC PROCESSresult = fsuipc.FSUIPC_Get(ref FSTokens[0], ref FacePlate.AircraftAltitude);result = fsuipc.FSUIPC_Get(ref FSTokens[1], ref FacePlate.AircraftAirspeed);result = fsuipc.FSUIPC_Get(ref FSTokens[2], ref FacePlate.AircraftBankAngle);result = fsuipc.FSUIPC_Get(ref FSTokens[3], ref FacePlate.AircraftFlapPosition);result = fsuipc.FSUIPC_Get(ref FSTokens[4], ref FacePlate.AircraftOnGround);result = fsuipc.FSUIPC_Get(ref FSTokens[5], ref FacePlate.AircraftLOCCapture);result = fsuipc.FSUIPC_Get(ref FSTokens[6], ref FacePlate.GroundElevation);result = fsuipc.FSUIPC_Get(ref FSTokens[7], ref FacePlate.AircraftHeading);result = fsuipc.FSUIPC_Get(ref FSTokens[8], ref FacePlate.MAGVAR);result = fsuipc.FSUIPC_Get(ref FSTokens[9], ref FacePlate.AircraftMACH);result = fsuipc.FSUIPC_Get(ref FSTokens[10], ref FacePlate.AircraftTAS);result = fsuipc.FSUIPC_Get(ref FSTokens[11], ref FacePlate.OAT);//Enginesresult = fsuipc.FSUIPC_Get(ref FSTokens[12], ref FacePlate.Engine1Combusting);result = fsuipc.FSUIPC_Get(ref FSTokens[13], ref FacePlate.Engine2Combusting);result = fsuipc.FSUIPC_Get(ref FSTokens[14], ref FacePlate.Engine3Combusting);result = fsuipc.FSUIPC_Get(ref FSTokens[15], ref FacePlate.Engine4Combusting); //Our (Internal) Offsetsresult = fsuipc.FSUIPC_Get(ref FSTokens[16], ref FacePlate.BUCKET_InFromFSUIPC); #endregion#region Convert FSUIPC Values to readable values //-----------------------------------------------////Convert Everything to readable values ////-----------------------------------------------//calc_ALT = (int)(AircraftAltitude * 3.28201);//GOTS US A BAROMETRIC PRESSURE BUG HERE (3/26/2004)calc_IAS = (int)(AircraftAirspeed / 128);calc_TAS = (int)((AircraftTAS / 128) - 1024);calc_ELE = (int)((GroundElevation/256) * 3.28201);calc_tHDG = (int)(AircraftHeading / 11930465);calc_OAT = Convert.ToDouble(OAT) / 256.0;calc_SOS = (float)(38.967854 * Math.Sqrt(calc_OAT + 273.15));calc_MACH = (double)(calc_TAS / calc_SOS);#endregion }while(FSUIPC_Available == true);}#endregion

Share this post


Link to post
Share on other sites

Ok 2 things I notice in this code ..1) you use the process//Now Process the Entire batch!!fsuipc.FSUIPC_Process(ref dwResult);Let me check but I don't think I use it anywhere. Could this be a problem ?2) you use the getWhat does this do ?Ow and on the "speed up the proces" and "having your soft use 100% CPU" .. that's no problem. I use my laptop to run the soft for the interface on linked to the FS pc via widefs.

Share this post


Link to post
Share on other sites

>Ok 2 things I notice in this code ..>>1) you use the process>>//Now Process the Entire batch!!>fsuipc.FSUIPC_Process(ref dwResult);>>>Let me check but I don't think I use it anywhere. Could this>be a problem ?Definitely!! :-)>>2) you use the get>>What does this do ?>>>Ow and on the "speed up the proces" and "having your soft use>100% CPU" .. that's no problem. I use my laptop to run the>soft for the interface on linked to the FS pc via widefs.As long as your CPU isn't maxed at 100%, you're good. That 200ms delay isn't too tight. Try 20ms or even 5, and you'll see what I mean.. :-)

Share this post


Link to post
Share on other sites

Get!result = fsuipc.FSUIPC_Get(ref FSTokens<0>, ref FacePlate.AircraftAltitude);This statement literally GETs the value read --into-- the FSUIPC array (At Token row 'Zero') and places it in the local variable "Faceplate.AircraftAltitude" for later...

Share this post


Link to post
Share on other sites

Ok so when do I put this process ?Only after reads ? Or also after writes ? And if I write 2 times to the same offset short after eachoter, do I process 2 times ?Also you say the Get action puts the read values into your variables. I do this:IAS = CStr(ReadFromFS(&H2BC, 4) / 128)andBinXpdr = Dec2Bin(CStr(ReadFromFS(&H354, 2)))... ?While waiting for your next thoughts, I'll be putting in the process calls here and there to check if it changes anything.

Share this post


Link to post
Share on other sites

You should only have 1 read process, 1 write process per offset before you Process it.It's pointless to Write to an offset twice, then process it. Your FSUIPC values will always be set to the second WRITE value, the first one being overwritten by the 2nd write.So, in short:===========================All your READsAll your WRITEsProcess()All your GETs===========================.

Share this post


Link to post
Share on other sites

Hmmz .. ok so the Process doesn't help :(The thing is .. I can do all my reads in 1 time each timer tick.But if I have to do all the writes ... on a timer based ... I should have to change my entire code. Let me try this.

Share this post


Link to post
Share on other sites

Ok, I've changed my code such that it does no longer use the checkboxes.Each timer tick it will read the variables I need (nav, xpdr, ...)Then it will check the data from Photon.After that it will send the correct values to the offsets (&H3340 to &H334F) if there is a key pressed according to Photons readingsThen it will process.Still same scenario.After a few minutes the readings from nav, xpdr, ... go weird and my soft crashes (because I do dec2bin and substrings on the read value) which is logic.So I think that either it has something to do with me not using the GET, or the code I use to link my soft to fsuipc is bad.I really wish that Scott would send me an e-mail with this part of his code :( or that Pete could help me out. Neither of them have sent me an e-mail yet.

Share this post


Link to post
Share on other sites

Pete told me :---------Please use the logging tools provided in FSUIPC to help you resolve such problems. You can log all IPC reads and writes and see exactly what you are doing.---------What does he mean ?I've used FSinterrogate.exe to check the variables and they keep correct in this software. So it must be that my code is wrong. At least the part you need to add with all the fsuipc stuff in it. I can not edit this myself or check where the fault might be simply because I do not understand any of that code.Very stupid that there is a .Net section in the SDK but it doesn't even compile ......... talk about service to a 23.30 EURO tool ... :/

Share this post


Link to post
Share on other sites

I finally figured it out.It turns out that when I read I get too much data.e.g. when I expect a "4", I get from fsuipc "0000 0100" which converted from binary to decimal is indeed a 4. However the bite I get extra in front makes the 4 go wild whenever the first bite changes and is no longer "0000"So now what I do is read, then cast to string. Check if the number is of character is longer than 16, I take a substring 16 long from the right. When it is to short I add leading 0's. After that I convert from binary do decimal using the BCD methot.It still isn't right, but at least I make it right in the end. And it should work now.EUREKA !Now I hope Espen will figure out the key combos in the gauges to work 100% and then I am off flying my F50 for real and seriously !! o/

Share this post


Link to post
Share on other sites

Hi All,I have been watching this thread with interest as using FSUIPC to read and write to FS sounded like a good idea. I have read through the SDK but must admit I'm more confused than ever!After playing around in VB6 I can read the values, it's writing them that won't work for me, heres my code according to the documentation...Dim dwResult As Long, txt As LongDim myHDG As Longtxt = Me.Text1.TextmyHDG = (txt * 360 / 65536) FSUIPC_Write(&H7CC, 16, myHDG, dwResult) FSUIPC_Process (dwResult)Is this correct?ZK-SHBIf it isn't Boeing, I'm not going.http://www.737simbuilders.com/

Share this post


Link to post
Share on other sites

TryDim Result As LongDim myHDG As LongmyHDG = (Me.Text1.Text * 360 / 65536)FSUIPC_Write(&H7CC, myHDG, Token, Result)FSUIPC_Process(Result)

Share this post


Link to post
Share on other sites

HiThanks for that, what should I declare Token as? I have tried as Long but this just causes the program to close without doing anything. Sorry for so many quetions but this is a very different world to programming a frontend for a SQL SB! Do you know of any good tutorials on programming FSUIPC/FS with VB? I have tried my sources but this is unheard of there.ZK-SHBIf it isn't Boeing, I'm not going.http://www.737simbuilders.com/

Share this post


Link to post
Share on other sites

Have no idea of any tuts for fsuipc vs VB. Sadly enough Pete is not of much help either. I keep giving him info and things I know or notice or see or whatever so that maybe he could figure something out to help me ..Instead he just tells me to use FSinterogate and disencourage me to continue programming at all ... :/I know I am a newbie but that doesn't mean I should give up. And it's not because I am not able to change or edit anything from the fsuipc code block or even understand a single line of code of it (what it does or how it works) that I should forget about the entire thing. I think it's up to him to make the code work without bugs (not up to me for sure) and provide us with CLEAR to the point SDK's. Him not managing to do so results in lots of questions on his forum which he thinks are obvious or stupid.I refuse to read an entire manual where 95% of the text I won't ever need, so what I do is I look for that 5% I do need and than he should NOT blame me for not reading (finding it in) the manual.Either way, here I am rambling on about that guy once more...Back to your question.I suggest you Dim as Integer. Dito for the Result variable. My mistake.Let me know if it works.Thing is that you use VB6 and I started of learning coding with VB.NetI have only used VB6 for a very short time (first version of LPT switch software) and I didn't like it at all.What I hate about it is things like:txtText1 = "blah"While in .Net you would have to writetxtText1.Text = "blah"It is more to type indeed, but when re-reading your code or when reading someone elses code you understand much faster what is going on.If I see that first VB6 line I think I put the string "blah" in a variable. Which is not the case .. I put the string into a property of an object.

Share this post


Link to post
Share on other sites

Hi,I can understand Peters attitude, he uses C not VB and the sdk samples (what there is)were ported by someone else for him. Agree 100% with the sdk manual I found it confusing as most samples were C based and the differences between it and VB... As to my using VB6 over VB.Net just a case of the machine I'm using to develop this on and the fact that I know VB6 enviroment better than VB.Net. If all goes well I will most likely port it to .Net anyways.Tried as integer VB no like, I get a ByRef error so have put both back to long.ZK-SHBIf it isn't Boeing, I'm not going.http://www.737simbuilders.com/

Share this post


Link to post
Share on other sites

I could give you my .Net code .. not sure if you can do anything with it ..I got my "CockpitLink" software for the link between my interface and FS. Then when I noticed that didn't worked I started a new project "FinalTest". Simple GUI, basic code, just enough to get the read/write work.If you want that, I could send you. Just send me a mail: pvanagtADbelgacomDOTnet

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this