Jump to content
The simFlight Network Forums

Recommended Posts

Posted

I don't know why, but it doesn't work.

This is my source code for VB:

    Dim test As String
    Dim control As Integer

    test = "hello!"
    control = 0

    If FSUIPC_Write(&H3380&, 128, VarPtr(test), dwResult) Then
        If FSUIPC_Process(dwResult) Then
        End If
    End If

    If FSUIPC_Write(&H32FA&, 2, VarPtr(control), dwResult) Then
        If FSUIPC_Process(dwResult) Then
        End If
    End If

Does anybody has an idea?

Posted
I don't know why, but it doesn't work.

This is my source code for VB:

    Dim test As String
    Dim control As Integer

    test = "hello!"
    control = 0

    If FSUIPC_Write(&H3380&, 128, VarPtr(test), dwResult) Then
        If FSUIPC_Process(dwResult) Then
        End If
    End If

    If FSUIPC_Write(&H32FA&, 2, VarPtr(control), dwResult) Then
        If FSUIPC_Process(dwResult) Then
        End If
    End If

Does anybody has an idea?

Hi

I use it vice versa and it works perfect.

First writing 32FA, following by 3380.

Posted

I use it vice versa and it works perfect.

First writing 32FA, following by 3380.

But it most certainly shouldn't work that way. The display is activated when you write to 32FA. Nothing happens when you write to 3380. Maybe you are repeating it?

I don't know why, but it doesn't work.

This is my source code for VB:

First, the call "FSUIPC_Write(&H3380&, 128, VarPtr(test), dwResult)" is wrong because the string is not 128 bytes long. You must give the actual length, including the terminating zero byte.

Second, though I don't know VB, the usual sort of reason for this problem was that VB didn't use ASCIIZ strings, but either Wide or Unicode strings, so that string wouldn't be correct. Additionally, an ASCIIZ string should be zero terminated, whereas aren't VB strings preceded by a length byte? If that is some odd control character, that would wreck the string as well.

Please use the Logging facilities in FSUIPC to see exactly what is being written. That is why I provided logging, to help folks debug their code, yet no one seems to bother to take advantage of this! :-(

Regards

Pete

Posted

Now it works!

First, I forgot to initialize FSUIPC... I could beat myself...

Second, I found a way to avoid the string-problem:

    Dim msgString As String
    Dim msgPos As Integer

    msgString = "welcome"

    FSUIPC_Initialization

    If FSUIPC_Open(SIM_ANY, dwResult) = True Then
        For msgPos = 1 To Len(msgString)
            If FSUIPC_Write(13183 + msgPos, 2, VarPtr(Asc(Mid(msgString, msgPos, 1))), dwResult) Then
                If FSUIPC_Process(dwResult) Then
                End If
            End If
        Next msgPos

        If FSUIPC_Write(&H32FA&, 2, VarPtr(5), dwResult) Then
            If FSUIPC_Process(dwResult) Then
            End If
        End If
    End If

Posted

Second, I found a way to avoid the string-problem:

        For msgPos = 1 To Len(msgString)
            If FSUIPC_Write(13183 + msgPos, 2, VarPtr(Asc(Mid(msgString, msgPos, 1))), dwResult) 

Yes, that will work (though you should add a zero character to the end -- if you don't any previous longer message will leave part of itself appended to yours when displayed).

But: it is not very efficient. Each time you add another character you are creating another "write block" with a 16-byte header. That makes the data being transferred nearly 17 times larger than it should be. Worse, when it gets to FSUIPC, each of those writes is processed separately, taking valuable FS processor cycles.

Better to formulate the string correctly in your own area first. If VB doesn't come with a way of converting its strings for normal Windows API ASCIIZ format already (which would surprise me), then declare a work area as an array of 128 bytes and do the loop for the string length preparing that array. Add the zero at the end, then do the single FSUIPC_Write from the array with a length+1.

Regards

Pete

Posted

Yes, I know that this is not the best solution, so I will try to improve it in the next days.

The problem is, that I found nothing about ASCIIZ in VB.

Posted

Now it's finished:

Declaration:

Private AsciiZ() As Byte

Function:

Public Sub writeMsg(msgString As String, msgControl As Integer)
    msgString = msgString & Chr(0)
    AsciiZ = StrConv(msgString, vbFromUnicode)

    FSUIPC_Initialization

    If FSUIPC_Open(SIM_ANY, dwResult) = True Then
        If FSUIPC_Write(&H3380&, Len(msgString), VarPtr(AsciiZ(0)), dwResult) Then
            If FSUIPC_Process(dwResult) Then
            End If
        End If

        If FSUIPC_Write(&H32FA&, 2, VarPtr(msgControl), dwResult) Then
            If FSUIPC_Process(dwResult) Then
            End If
        End If
    End If
End Sub

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.