Jump to content
The simFlight Network Forums

Paul Henty

Members
  • Posts

    1,652
  • Joined

  • Days Won

    74

Posts posted by Paul Henty

  1. Could you say to me of what you think of it?

    The code looks good to me. The only mistake I can see is that turbRpm (0x0896) is only 2 bytes and should therefore be declared as 'short' not 'int'.

    private Offset<short> turbRpm = new Offset<short>(0x0896);
    

    I'm not sure if you had a problem you want help with. If you do, please be more specific about what the problem is.

    Regards,

    Paul

  2. I'm trying to use NewWeather.h converted to C # but I'm not succeeding.

    It's not easy in C# because my DLL doesn't support reading and writing structures. I've also never tried using the NWI myself, but this might work...

    You need to convert your structure to a byte array before assigning it to the offset.

    Here is a method that will do that:

    You'll need to add the following using statement:

    using System.Runtime.InteropServices
    

    private byte [] StructureToByteArray(object obj)
    {
    	int len = Marshal.SizeOf(obj);
    	byte [] arr = new byte[len];
    	IntPtr ptr = Marshal.AllocHGlobal(len);
    	Marshal.StructureToPtr(obj, ptr, true);
    	Marshal.Copy(ptr, arr, 0, len);
    	Marshal.FreeHGlobal(ptr);
    	return arr;
    }
    

    Now you can use this to give the offset the byte array, rather than the structure itself:

    			NewWeather weather = new NewWeather();
    			weather.uCommand = 3;
    			NWICommand.Value = StructureToByteArray(weather);
    
    			// pressure.Value = 1024;
    			FSUIPCConnection.Process();
    

    I don't know if this will work but it's certainly a step in the right direction.

    If you want to read from the NWI, you'll need to convert the byte array back into a structure using this method:

    private void ByteArrayToStructure(byte [] bytearray, ref object obj)
    {
    	int len = Marshal.SizeOf(obj);
    	IntPtr i = Marshal.AllocHGlobal(len);
    	Marshal.Copy(bytearray,0, i,len);
    	obj = Marshal.PtrToStructure(i, obj.GetType());
    	Marshal.FreeHGlobal(i);
    }
    
    

    Paul

  3. Hello..

    I want make a program with Vbasic,like this ;

    Do you mean Visual Basic by Microsoft? If so, it's fairly simple. Let me know which version (VB6? VB.NET 2012?) and I'll tell you what you need and where to find it.

    If you mean a different language called Vbasic, there is no FSUIPC SDK for it. You'd have to write one yourself by translating the C SDK,

    Paul

  4. The number &H2BC on the Dim is what we want to know correct?

    if is &H2BC is speed if is &H3118 is com frequency 2...

    Correct?

    If its true there is any list with all that codes and funcions?

    Yes, that's all correct.

    A list of all the offsets (code numbers) can be found in the FSUIPC SDK. For FSUIPC4 the document is called 'FSUIPC4 Offsets Status.pdf'. This document tells you three main things about each offset:

    1. The offset code (address) e.g. 02BC

    2. The Size of the offfset in bytes and the type of data stored in the offset - This tells you what data type to Dim your offset as. Example: 4 byte integer = (As Integer), 2 Byte = (As Short).

    3. How the value is stored so you can convert it to real-world values. Example: (Indicated Air Speed, as knots * 128). This means to get back to knots you need to divide by 128. - (airSpeed.Value / 128D)

    There is a useful table on page 7 of my UserGuide.pdf (see the Docs folder in the Zip) which tells you what .NET types to use for each size/type of FSUIPC offset.

    Paul

  5. HI Joaogl,

    I've reproduced the error you are getting on the form designer. You can fix it by building or running the project, then close the form designer and reopen it.

    I create a Label to say my Speed but it says like 50.5 how can i remove that .5 ? i just want the 50...

    This isn't really to do with FSUIPC or my DLL. It's just VB / .NET programming. It's not really possible to give VB lessons in this forum. You can find this kind of thing elsewhere on the internet or in books. But to answer your question just convert to a string using a fixed point format with 0 decimal places:


    Dim mySpeed as Double = 50.5
    myLabel.Text = mySpeed.ToString("F0")

    [/CODE]

    This will probably round the number for you. If you don't want rounding then use the Floor function.

    [CODE]
    Dim mySpeed as Double = 50.5
    myLabel.Text = Math.Floor(mySpeed).ToString()

    [/CODE]

    Paul

  6. Ive done the Download of the FSUIPCDotNetClient2.0.zip open the VB Exemple add the reference but it give me 2 warnings....

    Warning 1 Could not find type 'FSUIPCClientExample_VB.DoubleBufferPanel'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built using settings for your current platform or Any CPU. 0 0

    Warning 2 The variable 'pnlAIRadar' is either undeclared or was never assigned. C:\Users\Joao Lourenco\Desktop\uuu\FSUIPCClientExample_VB\Form1.Designer.vb 520 0

    why this hapen?

    Hi,

    Have you tried to build the project or have you just gone into the form designer. Building it first might help.

    If it won't build, let me know if you can see the DoubleBufferPanel class. If should be at the bottom of the Form1.vb code file. It looks like this:


    Public Class DoubleBufferPanel
    Inherits Panel

    Public Sub New()
    ' Set the value of the double-buffering style bits to true.
    Me.SetStyle(ControlStyles.DoubleBuffer Or ControlStyles.UserPaint Or ControlStyles.AllPaintingInWmPaint, True)
    Me.UpdateStyles()
    End Sub

    End Class

    [/CODE]

    Paul

  7. all the airborn traffic ATCIdentifier returns the AirlineAndFlightNumber

    all the ground traffic ATCIdentifier returns only the Airline

    Hi Achilles,

    That's probably because the ground planes are 'sleeping'. They only have flight numbers assigned when they are in an active state like 'Taxiing out' or 'ready for takeoff'. I've tried it here with FSUIPC4 and the active ground planes do have flight numbers. The sleeping ones (most of them) do not.

    Incidentally, it's probably better to set the INI options before refreshing the AI data:


    FSUIPCConnection.AITrafficServices.OverrideGroundTrafficINISettings(ATCIdentifier.AirlineAndFlightNumber,True, 0, 0)
    FSUIPCConnection.AITrafficServices.OverrideAirborneTrafficINISettings(ATCIdentifier.AirlineAndFlightNumber, RangeInNM:=0)
    FSUIPCConnection.AITrafficServices.RefreshAITrafficInformation()
    [/CODE]

    If you still think there's a problem (e.g. you can't see flight numbers on active ground AI) let me know and I'll look into it some more.

    Paul

  8. I am trying to read an offset dymamically

    But always returns zero?

    Hi,

    There's nothing wrong with the code that I can see. I've tried it here using "02BC" (Airspeed) in the textbox and it worked fine.

    It would depend on what you're typing into the textbox and what kind of data is stored at that offset. You can obviously only use offsets of 4 bytes that are integers with the code you posted.

    This is not related to your problem, but you need to be careful when creating offsets when the program is running. When you 'Dim' a new offset it's registered with the FSUIPCConnection class which holds a reference to that Offset instance it. If that offset then goes out of scope in your program it will still be registered with the FSUIPCConnection class. Therefore it is still taking up memory and will still be read every time you do Process().

    As your program is at the moment, if you use this dynamic feature 50 times you will have all 50 offsets still in memory and all 50 being read each Process().

    To clean up offsets you don't want any more you must either:

    1. Disconnect them by calling MyOffset.Disconnect()

    or

    2. Delete the group they are in (If you put them in a group). e.g. FSUIPCConnection.DeleteGroup("MyTemporaryOffsets")

    Here is your code again (works here for a few offsets I tried - e.g. 02BC (Airspeed)) but with the disconnect in:


    Dim Newoffset = "&H" & TextBox1.Text
    Dim readoffset As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(Newoffset)
    FSUIPCConnection.Process()
    MsgBox(readoffset.Value)
    readoffset.Disconnect()

    [/CODE]

    If you still have problems let me know what offsets don't work.

    Paul

  9. Hi Paul,

    How can I get the lat and lon of aitraffic as numbers without the letters and symbols?

    The only option seems to be the location for AITrafficServices which gives the complete lat and lon with symbols. Is there any option to get the lat and lon without the symbols you add? And even better as location.lat and location.lon

    Regards,

    Achilles

    Hi Achilles,

    All the locations used in my DLL are an instance of the FsLatLonPoint class. This has properties for the Longitude and the Latitude which are instances of FsLongitude and FsLatitude. These classes have various properties for obtaining the lon/lat in various ways.

    It's all explained on the Intellisense and in the user guide. If you're not seeing the intellisense then make sure you have the FSUIPCClient.XML file in the folder as the FSUIPCClient.DLL.

    To answer your specific question about the lon/lat of AI traffic you can use the following to get the lon and lat as a numeric value of degrees:


    Dim aiPlaneLat As Double = myAIPlane.Location.Latitude.DecimalDegrees
    Dim aiPlaneLon As Double = myAIPlane.Location.Longitude.DecimalDegrees
    [/CODE]

    Paul

  10. Hello :) I have a question.. How can i write a textstrip into FS.

    You need to use offsets 3380 and 32FA. Details of these can be found in the FSUIPC documentation.

    Here is some example code:

    Declaration of the required offsets:


    Public messageText As Offset(Of String) = New Offset(Of String)("textstrip", &H3380, 128, True)
    Public messageControl As Offset(Of Short) = New Offset(Of Short)("textstrip", &H32FA, True)
    [/CODE]

    Note that 3380 requires the offset length (128) as it's a string type. Also they are both declared as WriteOnly because there is no point reading what's in these offsets.

    I have also put them in thier own offset group called "textstrip". This is so we can send messages without processing all the other offsets.

    The code to write the message:

    [CODE]
    messageText.Value = "XXX has connected with your FSX"
    messageControl.Value = 5
    FSUIPCConnection.Process("textstrip")
    [/CODE]

    Note that here we only process the "textstrip" group.

    This will make the message appear on the screen for 5 seconds. See the FSUIPC documentation for the different options avilable for the control offset (32FA).

    Paul

  11. Public Gear As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&0BF0) ' gear

    The hex specifier in VB is &H. So you need this:

    Public Gear As Offset(Of Integer) = New FSUIPC.Offset(Of Integer)(&HBF0) ' gear
    

    Please take some time to review the UserGuide that comes with my DLL and the VB sample application. Everything is explained and shown in great detail.

    Paul

  12. Public Sub mess()
    		Try
    			FSUIPCConnection.Process("")
    			Dim airSpeedKnots As Double = (airSpeed.Value / 128D)
    			' Label1.Text = airpeedKnots.ToString("f0")
    			trspeed = airSpeed.ToString("f0")
    		Catch ex As Exception
    			MsgBox("ERROR")
    		End Try
    	End Sub
    [/CODE]
    
    doesen´t work
    i call the Function in form1 with [b]test.mess[/b]but i get only the try-catch Error (msgbox"ERROR")
    Anyone can help me?
    
    Hi Alex,
    It will help more if you know what the exception (error) is that is being thrown.  MsgBox("Error") isn't very helpful.  Something like this would be better:
    [code]
    MsgBox("Error: " & ex.Message)
    

    Anyway I think I see the problem:

    			FSUIPCConnection.Process("")
    

    If you don't want to process a particular group just use:

    FSUIPCConnection.Process()
    

    The error you are getting probably says that the group "" does not exist.

    If that's not it then show me the message from the exception that's being thrown.

    Paul

  13. In the other hand, in c# (MS Visual C#) I'm supposed to write the following command to achieve the same effect:

    fsuipc.FSUIPC_Write(0x88C, throttle_1, ref token, ref dwResult);

    fsuipc.FSUIPC_Process(ref dwResult);

    and guess what happens. The Helicopter lever position works fine but the Helicopter just gains power for a brief instant (1 second) and then it looses power. I notice that N1 rotation (in this case) decreases as I the throttle lever position increases. At least to me it is extremely nonsense.

    Observation #1: It perfectly works for aircraft, not to helicopters (in C#).

    Observation #2: It perfectly works for all aircrafts in FS (in C++)

    Observation #3: I tested the command line to many other offsets and they worked fine also. It seems to be a bug in 0x88C offset for c# applications (??)

    The most likely cause of your problem is that throttle_1 is declared and 'int' (4 bytes) and not 'short' 2 bytes. Therefore, at the same time you're writing to 0x088C you are also trampling over 0x88E which is the 'prop lever'. Could this possibly be the collective in helicopters? Changing the collective on a helicopter would certainly account for a change in N1.

    Paul

  14. Hi Paul.

    your answer did the trick,however here's the problem I now face. I am reading the digi pot, or encoder from the arduino maga 2560. I can send it to VB.NET 2010 and display it in a textbox. For your answer to work it needs to have the decimal point.(121.55) the data I can send from the encoder read is (12155) no (.)

    Hi Ron,

    My snippit of code assumes there is a . in the frequency string because that's how it normally is. However, if your string doesn't have a . in it then you can just change it to fit what you have.

    FSUIPC requires 121.55 to be in the format 2155. In my example the second line of code transforms 121.55 into 2155 buy concatenating the second, third, fith and sixth together:

    Dim com2FS As String = newCom2Frequency.Substring(1, 2) & newCom2Frequency.Substring(4, 2)
    

    So if you are starting with 12155 all you need to do is take the second digit onwards:

    Dim com2FS As String = newCom2Frequency.Substring(1)
    

    So the whole example would be:

    				Dim newCom2Frequency As String = "11945" ' 119.45 as read from arduino
    				' get the freqeuncy into FS format (no leading 1 = 1945)
    				Dim com2FS As String = newCom2Frequency.Substring(1)
    				' set the value to the com2 offset after converting to a short as a hex string
    				com2Offset.Value = Short.Parse(com2FS, Globalization.NumberStyles.AllowHexSpecifier)
    

    How can I convert a number such as 12155 to 121.55 in VB NET 2010.?? Thanks so much, Ron.

    If you use the code above you don't need to. But incase you need it for display purposes just use the Substring() method:

    Dim stringFromArduino as String = "12155"
    Dim stringWithDecimal as String = stringFromArduino.Substring(0,3) & "." & stringFromArduino.Substring(3)
    

    Paul

  15. Hi Paul, or anyone who may know how to ::: send a BDC code to set the radio com1 freq. just from the FSUIPC code Example. Paul has shown how to READ the BDC but NOT how to send to. Any Help.

    Hi Ron,

    You need to take the BCD string and convert it to a Short as if it was a hex string. Here is a snippit of code that shows how: I think the last line is what you're looking for...

    		Dim newCom2Frequency As String = "119.45" ' Set to 119.45
    		' get the freqeuncy into FS format (no . and no leading 1 = 1945)
    		Dim com2FS As String = newCom2Frequency.Substring(1, 2) & newCom2Frequency.Substring(4, 2)
    		' set the value to the com2 offset after converting to a short as a hex string
    		com2Offset.Value = Short.Parse(com2FS, Globalization.NumberStyles.AllowHexSpecifier)
    

    Paul

  16. My question is:

    How Read + Write a single Flag value with Visual Basic 2008 ?

    Example: FSuipc - Offset 3366 - Var.Type U8 - Bit 0 .. 7

    If you are using my DLL then the easiest way is to declare the offset as a 'BitArray' type.

    The sample application included with the DLL has an example of using a BitArray offset for the lights.

    Basically, you need to declare the offset as follows:


    Dim enginesOnFire As Offset(Of BitArray) = New FSUIPC.Offset(Of BitArray)(&H3366, 1)
    [/CODE]

    Note the size is 1 because the offset is 1 byte.

    Then after processing you can check if each bit is set by using an array index. This is 0 based so to test is bit 0 is set you use:

    [CODE]
    If enginesOnFire.Value(0) = True then
    ' Engine 1 on Fire!
    end if
    [/CODE]

    Engine 2 would be enginesOnFire.Value(1)

    Engine 3 would be enginesOnFire.Value(2)

    Engine 4 would be enginesOnFire.Value(3)

    You can also set and reset these bits by setting the value to True or False repectively e.g.

    [CODE]
    enginesOnFire.Value(2) = True
    [/CODE]

    although the documentation says this probably doesn't start a fire in the simulation, just sets the warning light.

    Paul

  17. Hi,

    Offset<string> ofsTextMessage = new Offset<string>(0x3380);
    [/Code]
    
    
    What the error message is trying to say is that when you declare an offset as a string or byte[] you need to tell it how long the offset is.  Normally this can be derived for things like short and int but it has no way of knowing the size of an offset from the type 'string' or 'byte[]'  So you need to supply the parameter 'ArrayOrStringLength'.  The simplest overload for this would be:
    [code]
    Offset<string> ofsTextMessage = new Offset<string>(0x3380,128);
    

    You use the full size. The dll knows about 0 terminations etc.


    ofsTextMessage.Value = msg.Substring(0, msg.Length > 127 ? 127 : msg.Length);
    [/CODE]

    The dll also handles truncation for you if the string supplied is over the specified size. (well the size -1 because of the 0 terminator). So no need for you to check the size. Just pass whatever's in msg.

    Paul

    • Upvote 1
  18. 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 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.