Jump to content
The simFlight Network Forums

Recommended Posts

Posted

I was wondering if anyone has been successful (Using C#) in writing text to offset 0x3380 for display on the windscreen...

There are currently 5 overloads for FSUIPC_Write(), but none seem to favor the writing of a string() value.

Any help is much appreciated.

Ray

Posted
I was wondering if anyone has been successful (Using C#) in writing text to offset 0x3380 for display on the windscreen...

There are currently 5 overloads for FSUIPC_Write(), but none seem to favor the writing of a string() value.

The VB version had a special "FSUIPC_WriteS" foor that. I don't know VB or C# so I can't really help directly, but Pelle Liljendal is working on a revised C# section at present. You might like to write to him. See the FSInterrogate announcement above for his address.

Regards,

Pete

Posted

This works, but needs some tidying (such as checking for strings greater than 127 chars, error handling, etc). You'll get the idea...

The answer to your question is that you need to convert your string to an array of bytes.

BTW - the fsuipc object is the one included in the C# example of the SDK.

Cheers,

Matt.

(assumes fsuipc.FSUIPC_Open has been called...)

      public bool WriteMessageToFS(string Message, int Duration)
        {
            int dwResult = -1;
            bool bResult = false;

            if (ConnectToFS())
            {

                Message += "\0";

                byte[] bytMessage = new byte[128];

                for (int intCurrentChar = 0; intCurrentChar < Message.Length; intCurrentChar++)
                {
                    bytMessage[intCurrentChar] = (byte)Message[intCurrentChar];
                }



                lock (fsuipc)
                {

                    // Set Message
                    bResult = fsuipc.FSUIPC_Write(0x3380, 128, ref bytMessage, ref token, ref dwResult);


                    // set Text display control word 
                    bResult = fsuipc.FSUIPC_Write(0x32FA, Duration, ref token, ref dwResult);

                    // Write the data to FS
                    bResult = fsuipc.FSUIPC_Process(ref dwResult);

                }


            }


            return bResult;


        }

  • 2 weeks later...
Posted

A cleaner way to convert from a string an an array of bytes:

 
System.Text.ASCIIEncoding ASCII = new ASCIIEncoding();          
byte[] bytMessage = new Byte[128];
int bytesEncodedCount = ASCII.GetBytes(Message, 0, Message.Length - 1, bytMessage, 0);

Again, you'll need to check for strings greater than 128 chars...

  • 5 years later...
Posted

hi

I need help. I'm try this:

public Offset<byte[]> messageWrite = new Offset<byte[]>(0x3380,128);

public Offset<int> messageDuration = new Offset<int>(0x32FA);

string Message = "my message test";

byte[] datablock = new byte[Message.Length + 1];

Encoding asciiEncoder = UTF7Encoding.ASCII;

asciiEncoder.GetBytes(Message).CopyTo(datablock, 0);

FSUIPCConnection.Open();

this.messageWrite.Value = datablock;

this.messageDuration.Value = 2;

FSUIPCConnection.Process();

FSUIPCConnection.Close();

And this does not work. Presents an error write protected memory. what's wrong?

Posted

hi

...

public Offset<byte[]> messageWrite = new Offset<byte[]>(0x3380,128);

public Offset<int> messageDuration = new Offset<int>(0x32FA);

...

And thisdoes not work.Presentsanerrorwrite protected memory.what'swrong?

The DLL supports reading and writing of strings directly so just declare 3380 as a string type:


public Offset&lt;string&gt; messageWrite = new Offset&lt;string&gt;(0x3380, 128);
[/CODE]

The control offset at 0x32FA is defined in the documentation as 2 bytes.  You should therefore decalre this as a short, not an int (which is 4 bytes).
[code]
public Offset&lt;short&gt; messageDuration = new Offset&lt;short&gt;(0x32FA);

The full code will something like this:

public Offset&lt;string&gt; messageWrite = new Offset&lt;string&gt;(0x3380, 128);
public Offset&lt;short&gt; messageDuration = new Offset&lt;short&gt;(0x32FA);

string Message = "my message test";
this.messageWrite.Value = Message;
this.messageDuration.Value = 2;
FSUIPCConnection.Process();

Paul

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.