André Gonçalves Posted September 11, 2012 Report Share Posted September 11, 2012 I'm trying to use NewWeather.h converted to C # but I'm not succeeding. Would you like more details on how utiizar in dotnet. best regards public struct NewWeather { public short uCommand; // C000 C400 C800 CC00 public short uFlags; // C002 C402 C802 CC02 // Not used until FSX - see below public int ulSignature; // C004 C404 C804 CC04 char chICAO; // C008 C408 C808 CC08 public short uDynamics; // C00C C40C C80C CC0C // 0=none, 4=extreme public short uSeconds; // C00E C40E C80E CC0E // FSX only -- see below double dLatitude; // C010 C410 C810 CC10 // LLA zero for GLOB or unknown ICAO double dLongitude; // C018 C418 C818 CC18 int nElevation; // C020 C420 C820 CC20 // metres * 65536 public int ulTimeStamp; // C024 C424 C824 CC24 // mSecs since start of session NewPress Press; // C028 C428 C828 CC28 NewVis Vis; // C02C C42C C82C CC2C // Base Vis -- for upper Vis layers see int nTempCtr; // C034 C434 C834 CC34 // Number of temperature layers NewTemp Temp; // C038 C438 C838 CC38 int nWindsCtr; // C0F8 C4F8 C8F8 CCF8 // Number of wind layers NewWind Wind; // C0FC C4FC C8FC CCFC int nCloudsCtr; // C27C C67C CA7C CE7C // Number of Cloud layers (max 16 in FSX, was 24 NewCloud Cloud; // C280 C680 CA80 CE80 char chUTCstamp; // C380 C780 CB80 CF80 // UTC time stamp on METAR (internal use) public short fWriteback; // C386 C786 CB86 CF86 // Flags for writing back to FSX (internal use only) public long ulSettingTimeStamp; // C388 c788 CB88 CF88 // Timestamp METAR sent (internal use) int nUpperVisCtr; // C38C C78C CB8C CF8C // Number of upper Vis layer (new in FSX) NewVis UpperVis; // C390 C790 CB90 CF90 public short uSpare; // C3F0 C7F0 CBF0 CFF0 } private Offset<byte[]> NWICommand = new Offset<byte[]>(0xC800, true); NewWeather weather = new NewWeather(); weather.uCommand = 3; NWICommand.Value = weather; // pressure.Value = 1024; FSUIPCConnection.Process(); Error!!! help me! Link to comment Share on other sites More sharing options...
Paul Henty Posted September 11, 2012 Report Share Posted September 11, 2012 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 Link to comment Share on other sites More sharing options...
André Gonçalves Posted September 11, 2012 Author Report Share Posted September 11, 2012 Thanks Paul, I'll do some tests, the principle does not only want to read the time to write a new FS. best regards Link to comment Share on other sites More sharing options...
lordofwings Posted January 30, 2013 Report Share Posted January 30, 2013 I have a question about FSUIPC DotNet Client., well a few questions.... If the FSUIPCConnection object loses the connection with FSX, can I reuse the object and reconnect or must I dispose it and use a new one? If FSUIPCClient loses contact with FSX, after I reconnect (see question above) do I have to reconnect ALL the offsets again, or does it remember which ones it is tracking? Can I have multiple FSUIPCClient instances on the same application? or is it meant to be a singleton pattern? if there are multiple, do they share the registered offsets? or each have their own? I normally write a wrapper around it but it would be nice if the FSUIPCConnection instance also exposed events such as these: SimulatorDisconnected() - the current connection was closed in response to Close(). SimulatorConnected() - An Open() was completed or perhaps re-open(). An argument could indicate what is the FS version to which it is connected (as it may have changed...) SimulatorFaulted() - The FSUIPCConnection instance has faulted and can possibly not recover. Link to comment Share on other sites More sharing options...
Paul Henty Posted January 31, 2013 Report Share Posted January 31, 2013 If the FSUIPCConnection object loses the connection with FSX, can I reuse the object and reconnect or must I dispose it and use a new one? You can (and should) reuse it. Just remember that if the connection is lost to call Close() before you try to Open() it again. If FSUIPCClient loses contact with FSX, after I reconnect (see question above) do I have to reconnect ALL the offsets again, or does it remember which ones it is tracking? It remembers everything. Can I have multiple FSUIPCClient instances on the same application? or is it meant to be a singleton pattern? if there are multiple, do they share the registered offsets? or each have their own? Its a singleton pattern (technically a Static class in .net terminology) so there can only be one instance. There are facilities to connect to multiple instances of flight sims using WideClient but that's quite an unusual requirement. Usually you are just connected to one copy of flight sim at a time so it doesn't really make sense to have multiple connections. You can of course use the grouping to read and write different groups of offsets at different times. I normally write a wrapper around it but it would be nice if the FSUIPCConnection instance also exposed events such as these: SimulatorDisconnected() - the current connection was closed in response to Close(). SimulatorConnected() - An Open() was completed or perhaps re-open(). An argument could indicate what is the FS version to which it is connected (as it may have changed...) SimulatorFaulted() - The FSUIPCConnection instance has faulted and can possibly not recover. Yes, that would be good. I'll add it to my list of things to do. Thanks for the suggestion. Paul Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now