Jump to content
The simFlight Network Forums

How read quickly after FSUIPC_WRITE()


Recommended Posts

Hello , everybody.

I've been sufferig from a problem using FSUIPC_READ() during the past one month.

I use FSUIPC 3.48 , VB5 and FS2004.

What I like to do is ,

1. Write a value (f.e. altitude) to FS's MCP via FSUIPC_WRITE().

2. Shortly thereafter , read altitude of FS's MCP via FSUIPC_READ().

I can't get a correct value first, but while trying in severaltimes I can get correct value.

But I'd like to get it as quickly as possible.

My VB code is below.

Please somebody teach me what my mistake.

Best regards

' ----------------------------

Dim FsAlt(4) As Byte

Dim alt As Long

Dim AltFnl as Long

alt = 5000 * 0.3048 * 65536 ' --- alt=5000 ft

Call FSUIPC_Write(&H7D4, 4, VarPtr(alt), dwResult) '---Write alt to FS

Call FSUIPC_Read(&H7D4, 4, VarPtr(FsAlt(1)), dwResult) '--- Read alt from FS

Call FSUIPC_Process(dwResult)

AltFnl = (FsAlt(1) + FsAlt(2) * 256& + FsAlt(3) * 65536 + FsAlt(4) * 16777216) / 19975.3728

'-----------------------------

Link to comment
Share on other sites

But I'd like to get it as quickly as possible.

Why? Why not use the value you just sent? Don't you believe it?

Call FSUIPC_Write(&H7D4, 4, VarPtr(alt), dwResult) '---Write alt to FS

Call FSUIPC_Read(&H7D4, 4, VarPtr(FsAlt(1)), dwResult) '--- Read alt from FS

Call FSUIPC_Process(dwResult)

Both the write and the read are being done in the same Process. That will only work (on the same PC as FS) where all FSUIPC has to do is copy the value into some memory, because obviously the memory will be just written in the same call. It will not work on a client PC because the process is being done by WideClient. It will send your Write over to FS, but it will give you the value for the read that it has in memory. Until WideServer sends it the update any reads on the Client will return the previous value. It will be two network cycles before you get an updates -- possibly 50 mSecs, more likely anything from 100 to 300 mSecs. More on a very busy system.

If, for this particular value, FSUIPC cannot simply write to a memory location, but has to send the value to somewhere in FS for processing, then you cannot expect the value to be read back correctly in the same process call to FSUIPC. It cannot be done.

You should write your program with cycles either approximating the FS frame rate, or regularly, say one FSUIPC_Process call every one or two or more "timer ticks" (each 55 mSecs). Requests sent on one cycle may be seen to be effective on a later one -- hopefully the very next one for something simple like this. For some weather and AI traffic reading requests there might be a longer delay. And of course, over a Network, through wideFS, you mst allow for much longer as a rule.

Regards,

Pete

Link to comment
Share on other sites

Thank you for reply, Pete.

Let me explain you a reason why I want to FSUIPC_Write and Read continuously.I made a small 777-MCP hardware with a rotary encoder sws, 7-segleds and microcomputer. It sends and receives a data to and from VB program via RS232C port.

I want a two-way conversation between a hardware MCP and FS MCP (i.e. if I operate a hardware MCP ,it changes value of FS MCP. And otherwise)

In the VB program , SubProcedure is running 500ms cycle. It works...

Step1. Check whether a value of hardware MCP changes or not. If it has changed , sends it to FS. (at this time a value of FS MCP on screen changes)

Step2. Check a value of FS MCP. If it has changed , sends it to hardware MCP via RS232C.

A problem is there are differences between FS MCP value on screen and read value from FS MCP in Step2.

So I tried some of test using simple VB program, and noticed FSUIPC_READ() can't read a correct value after in just a sec FSUIPC_WRITE().

But I might be unintelligene about FSUIPC. What should I see to learn how to use of FSUIPC_Read, Write, Process_??

Best Regards.

Link to comment
Share on other sites

Let me explain you a reason why I want to FSUIPC_Write and Read continuously.

...

Step1. Check whether a value of hardware MCP changes or not. If it has changed , sends it to FS. (at this time a value of FS MCP on screen changes)

Step2. Check a value of FS MCP. If it has changed , sends it to hardware MCP via RS232C.

A problem is there are differences between FS MCP value on screen and read value from FS MCP in Step2.

Yes. I originally faced this problem programming displays via EPIC (the original Flight-Link TR-1 and KR-1 avionics stacks, in fact) way back in FS98 -- before FSUIPC in fact.

The only sensible way to do it is as follows:

1. When your dials are adjusted, update your displays locally with the new values as well as sending the new values to FS.

2. If the values are changing fast, don't try to send them all. It is probably best for the routine you use to send to FS to "sample" the current updated value every 250 or 500 mSecs and send the new values at that time.

3. Whilst the values are being updated locally, IGNORE changes being read from FS.

4. After a time (say 1 second or so -- experiment) from the last local change, THEN start reading FS values again for display.

If you don't do it something like this you will find it very difficult to do adjustments accurately as the FS read-out will always run behind. You watch an MCP being adjusted in a real aircraft and you will see how fast you can "spin those numbers". Try to implement it locally like that. Just let everything catch up in FS when the value stabilises.

Regards

Pete

Link to comment
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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.