Jump to content
The simFlight Network Forums

Using C# SDK and Offset 3380


 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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;


        }

Link to comment
Share on other sites

  • 2 weeks later...

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...

Link to comment
Share on other sites

  • 5 years later...

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.