Frédéric-O DUCHEMIN Posted June 5, 2015 Report Posted June 5, 2015 Hello, Using active runway by AI traffic is fine, but howto find runway by wind direction ? We can read runway.csv made by Makerunways and after ? Someone know howto this ? Thanks Regards Fred
Paul Henty Posted June 6, 2015 Report Posted June 6, 2015 You could read one of the files from MakeRunways (e.g. RC4) to give you a list of runways at each airport. Then when the player is close enough to the airport, read the weather information at that airport and get the current wind direction. The DLL has a weather reading facility. Then you can just look up each runway at the airport and find the best runway depending on the heading. However, this may not match up with the same runway that the AI traffic is using. I don't know if that is important to you. This is not a simple thing to do and would require several hours and many lines of code. Getting the runway from the AI is so much easier. Paul
Frédéric-O DUCHEMIN Posted June 7, 2015 Author Report Posted June 7, 2015 Thanks Paul, Why I would like use Wind direction ? I don't use VASIM or IVAO network to fly I don't use AI traffic loosing many FPS (I fly alone or real netwok like a multiplayer session) So I have already the function to my app to read runway.csv to each runway at the airport. Can you explain more please ? (a piece of code maybe) Regards Fred
Paul Henty Posted June 8, 2015 Report Posted June 8, 2015 I've modified one of the functions in your code that reads the runways.csv file. This new function will get the wind direction from the weather service and then find the runway closest to that heading. You should be able to paste it under the others. Public Function getActiveRunway(ByVal ICAOcode As String) As String Dim runwayReturn As String = "" ' Get the weather for the airport - might take some time so we set the timout to 30 seconds Dim ws As WeatherServices = FSUIPCConnection.WeatherServices ws.LocationReadTimeout = 30000 Dim weather As FsWeather = ws.GetWeatherAtLocation(ICAOcode) ' now get wind direction Dim windDirection As Double = 0 If weather.WindLayers.Count > 0 Then windDirection = weather.WindLayers(0).Direction End If ' Now get the runways at the airport ' For each one we test how far they are from the wind direction ' We keep the closest one. Dim pathto As String = My.Application.Info.DirectoryPath Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(pathto & "\runways.csv") MyReader.TextFieldType = FileIO.FieldType.Delimited MyReader.SetDelimiters(",") Dim runwayst As String Dim runwaynum As String Dim runwaydes1 As String Dim runwaydes2 As String = "" Dim currentRow As String() Dim smallestDifference As Double = 360 While Not MyReader.EndOfData Try currentRow = MyReader.ReadFields() If currentRow(0) = ICAOcode Then runwayst = currentRow(1) runwaynum = runwayst.Substring(1, 2) runwaydes1 = runwayst.Substring(3, 1) If runwaydes1 = "0" Then runwaydes2 = "" If runwaydes1 = "1" Then runwaydes2 = "L" If runwaydes1 = "2" Then runwaydes2 = "R" If runwaydes1 = "3" Then runwaydes2 = "C" If runwaydes1 = "4" Then runwaydes2 = "W" Dim rwyMagHeading As Double = CDbl(currentRow(5)) Dim rwyMagVariation As Double = 0 ' I think winds are magnetic. If not we must use true heading instead (second line) Dim rwyHeading As Double = rwyMagHeading ' Dim rwyHeading As Double = rwyMagHeading + rwyMagVariation ' Calculate the difference between the wind heading and the runway heading ' You might need to expand this to ignore short runways Dim difference As Double = 180D - Math.Abs(Math.Abs(windDirection - rwyHeading) - 180D) If difference < smallestDifference Then smallestDifference = difference runwayReturn = runwaynum & runwaydes2 End If End If Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException 'MsgBox("Line " & ex.Message & "is not valid and will be skipped.") End Try End While MyReader.Close() MyReader.Dispose() End Using Return runwayReturn End Function Paul
Frédéric-O DUCHEMIN Posted June 8, 2015 Author Report Posted June 8, 2015 Thanks Paul, I have two functions one for read where the aircraft takiing off and landing readind runway.csv to find runway where the plane is and return the result to the log text Public Function getrunaway(ByVal icaocode As String) As String Dim lon As FsLongitude = New FsLongitude(playerLongitude.Value) Dim lat As FsLatitude = New FsLatitude(playerLatitude.Value) ' Get the point for the current plane position Dim currentPosition As FsLatLonPoint = New FsLatLonPoint(lat, lon) Dim pathto As String = My.Application.Info.DirectoryPath Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(pathto & "\runways.csv") MyReader.TextFieldType = FileIO.FieldType.Delimited MyReader.SetDelimiters(",") Dim runawayst As String Dim runawaynum As String Dim runawaydes1 As String Dim runawaydes2 As String = "" Dim runawayreturn As String Dim currentRow As String() While Not MyReader.EndOfData Try currentRow = MyReader.ReadFields() If currentRow(0) = icaocode Then runawayst = currentRow(1) runawaynum = runawayst.Substring(1, 2) runawaydes1 = runawayst.Substring(3, 1) If runawaydes1 = "0" Then runawaydes2 = "" If runawaydes1 = "1" Then runawaydes2 = "L" If runawaydes1 = "2" Then runawaydes2 = "R" If runawaydes1 = "3" Then runawaydes2 = "C" If runawaydes1 = "4" Then runawaydes2 = "W" Dim aaa As String = currentRow(2) Dim bbb As String = currentRow(3) Dim aaaa As Double Dim bbbb As Double aaaa = System.Convert.ToDouble(aaa) bbbb = System.Convert.ToDouble(bbb) Dim rwyThresholdLat As FsLatitude = New FsLatitude(aaaa) Dim rwyThresholdLon As FsLongitude = New FsLongitude(bbbb) Dim rwyMagHeading As Double = CDbl(currentRow(5)) Dim rwyMagVariation As Double = 0 Dim rwyLength As Double = CDbl(currentRow(6)) / 2 Dim rwyWidth As Double = 254D Dim thresholdCentre As FsLatLonPoint = New FsLatLonPoint(rwyThresholdLat, rwyThresholdLon) Dim trueHeading As Double = rwyMagHeading + rwyMagVariation runwayQuad = FsLatLonQuadrilateral.ForRunway(thresholdCentre, trueHeading, rwyWidth, rwyLength) If runwayQuad.ContainsPoint(currentPosition) = True Then runawayreturn = runawaynum & runawaydes2 Return runawayreturn MyReader.Close() MyReader.Dispose() Exit Function End If End If Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException 'MsgBox("Line " & ex.Message & "is not valid and will be skipped.") End Try End While MyReader.Close() MyReader.Dispose() End Using Return "" End Function and this other to find the good runway for departure and arrival return the result in listbox. This is function where I would like to change by wind direction Public Sub Activerunways() ' Get a reference to the AITrafficServices class (saves typing) Try Dim AI As AITrafficServices = FSUIPCConnection.AITrafficServices ' Refresh the traffic information AI.ApplyFilter(False, True, 0, 360, Nothing, 10000D, 30D) AI.RefreshAITrafficInformation() ' Get the arrival runways in use Dim runways As List(Of FSRunway) = AI.GetArrivalRunwaysInUse(lblArrival.Text) ' Display in the listbox Me.lstArrival.Items.Clear() For Each rw As FSRunway In runways Me.lstArrival.Items.Add(rw.ToString()) Next rw ' same for departure runways runways = AI.GetDepartureRunwaysInUse(lblDeparture.Text) Me.lstDeparture.Items.Clear() For Each rw As FSRunway In runways Me.lstDeparture.Items.Add(rw.ToString()) Next rw Catch ex As Exception End Try End Sub Private Sub BtnGetFlight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGetFlight.Click RegisterKey(Options.Alt, Keys.F) UiFunctions.Connect() downloadmetar(lblDeparture.Text, lblWXDep.Text) downloadmetar(lblArrival.Text, lblWXArr.Text) Activerunways() 'Try ' ui = FSUIPCConnection.UserInputServices ' AddMenuItems() 'Catch ex As Exception 'End Try End Sub Fred
Paul Henty Posted June 8, 2015 Report Posted June 8, 2015 I've written the entire function for you. You just need to paste it in to your code, call it, and use the output however you want. Presumably adding it to the list box. I can help you use the DLL and give you example code, but I cannot do all your work for you or teach VB programming here. You will only get one runway at each airport. If you want different take-off and landing runways where there are Left and Right runways, you'll need to adjust the code for whatever logic you want. I added a comment that you might also need to add code to exclude runways under a certain length. Paul
Frédéric-O DUCHEMIN Posted June 8, 2015 Author Report Posted June 8, 2015 I've written the entire function for you. You just need to paste it in to your code, call it, and use the output however you want. Presumably adding it to the list box. I already thanks for all Paul I can help you use the DLL and give you example code, but I cannot do all your work for you or teach VB programming here. It's not my purpose just maybe misunderstood by myself. I have understood to replace this code by mine. So your function doesn't match if I have understood right with the original function given only where the aircraft taking-off or landing don't depend to the windir, because this function is call earlier. So If I have missed something just tell me. (it's not easy to understand I'm french I don't use google translate...sorry for that) ;) Regards Fred
Paul Henty Posted June 8, 2015 Report Posted June 8, 2015 Okay, sorry I did misunderstand. So, my function using the wind direction does not give the same results as the function using AI? Is that what you mean? Paul
Frédéric-O DUCHEMIN Posted June 8, 2015 Author Report Posted June 8, 2015 Okay, sorry I did misunderstand. No sorry it's me So, my function using the wind direction does not give the same results as the function using AI? Is that what you mean? Nope I have read in your post to replace the function to read runway...Also I keep my function to read which runway aircraft here and ADD your function to replace AI Try depart = getActiveRunway(lblDeparture.Text) Me.lstDeparture.Items.Clear() Me.lstDeparture.Items.Add(depart.ToString()) arrival = getActiveRunway(lblArrival.Text) Me.lstArrival.Items.Clear() Me.lstArrival.Items.Add(arrival.ToString()) Catch ex As Exception End Try Well I need to put everywhere try because the FrmMain at load doesn't connect to FSUIPC :mad: . Thanks Paul
Frédéric-O DUCHEMIN Posted June 9, 2015 Author Report Posted June 9, 2015 Problems: 1) When I call the function just departure are show 2) when the sim is paused issue and crash of app3) It would be easy to retrieve windir after downloading metar by NOAA weather instead FSUIPCConnection.WeatherServices because I have some troubles with the FSUIPC connection goes after click on startlog. 4) this code is correct ? Try depart = getActiveRunway(lblDeparture.Text) Me.lstDeparture.Items.Clear() Me.lstDeparture.Items.Add(depart.ToString()) arrival = getActiveRunway(lblArrival.Text) Me.lstArrival.Items.Clear() Me.lstArrival.Items.Add(arrival.ToString()) Catch ex As Exception End Try 5) Howto check FSUIPC.dll version in "SIMroot\modules" and paste the result to the label and make an action if sim_fsuipc < actual_version 6) add menu () doesn't work it's not the function doesn't work it's a problem of timing like others problem due to how the fsuipc connection is make PS: I'm sorry for this newbie questions, so I'm try to close quickly this thread. Regards Fred
Paul Henty Posted June 9, 2015 Report Posted June 9, 2015 1) When I call the function just departure are show This is probably because the arrival airport is too far away. The weather is not loaded until the player (aircraft) is close to the airport. 2) when the sim is paused issue and crash of app I've tried my test form with the sim paused and there was no problem. It must be some other part of your application. 3) It would be easy to retrieve windir after downloading metar by NOAA weather instead FSUIPCConnection.WeatherServices because I have some troubles with the FSUIPC connection goes after click on startlog. It would also help with your first problem. If you have access to the metar this might be a better way of doing it. Here is a function to get the wind direction from a metar string.... Private Function getWindDirectionFromMETAR(metar As String) As Double Dim heading As Double = 0 Dim endPos As Integer = metar.IndexOf("KT") If endPos >= 0 Then Dim startPos As Double = metar.LastIndexOf(" ", endPos) If startPos >= 0 Then heading = metar.Substring(startPos + 1, 3) End If End If Return heading End Function Here a modified version of the getRunways function that takes in the wind direction and the ICAO... Public Function getActiveRunway(ByVal ICAOcode As String, ByVal WindDirection As Double) As String Dim runwayReturn As String = "" ' Now get the runways at the airport ' For each one we test how far they are from the wind direction ' We keep the closest one. Dim pathto As String = My.Application.Info.DirectoryPath Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser(pathto & "\runways.csv") MyReader.TextFieldType = FileIO.FieldType.Delimited MyReader.SetDelimiters(",") Dim runwayst As String Dim runwaynum As String Dim runwaydes1 As String Dim runwaydes2 As String = "" Dim currentRow As String() Dim smallestDifference As Double = 360 While Not MyReader.EndOfData Try currentRow = MyReader.ReadFields() If currentRow(0) = ICAOcode Then runwayst = currentRow(1) runwaynum = runwayst.Substring(1, 2) runwaydes1 = runwayst.Substring(3, 1) If runwaydes1 = "0" Then runwaydes2 = "" If runwaydes1 = "1" Then runwaydes2 = "L" If runwaydes1 = "2" Then runwaydes2 = "R" If runwaydes1 = "3" Then runwaydes2 = "C" If runwaydes1 = "4" Then runwaydes2 = "W" Dim rwyMagHeading As Double = CDbl(currentRow(5)) Dim rwyMagVariation As Double = 0 ' I think winds are magnetic. If not we must use true heading instead (second line) Dim rwyHeading As Double = rwyMagHeading ' Dim rwyHeading As Double = rwyMagHeading + rwyMagVariation ' Calculate the difference between the wind heading and the runway heading ' You might need to expand this to ignore short runways Dim difference As Double = 180D - Math.Abs(Math.Abs(WindDirection - rwyHeading) - 180D) If difference < smallestDifference Then smallestDifference = difference runwayReturn = runwaynum & runwaydes2 End If End If Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException 'MsgBox("Line " & ex.Message & "is not valid and will be skipped.") End Try End While MyReader.Close() MyReader.Dispose() End Using Return runwayReturn End Function 4) this code is correct ? Yes but arrival may not work as explained above. 5) Howto check FSUIPC.dll version in "SIMroot\modules" and paste the result to the label and make an action if sim_fsuipc < actual_version I've added a new property to the DLL to get the FSUIPC Version number (new DLL attached). You need to be connected to FSUIPC first: FSUIPCConnection.FSUIPCVersion I don't know how you would get the version directly from the fsuipc.dll file on the disk. 6) add menu () doesn't work it's not the function doesn't work it's a problem of timing like others problem due to how the fsuipc connection is make This is something you'll have to sort out yourself. It is confusing source code and would take me too long to reorganise everything. Regards, Paul FSUIPCClient3.0_BETA.zip
Frédéric-O DUCHEMIN Posted June 10, 2015 Author Report Posted June 10, 2015 Thanks a lot Paul, for your attention and your adds ;) Private Function getWindDirectionFromMETAR(metar As String) As Double Dim heading As Double = 0 Dim endPos As Integer = metar.IndexOf("KT") If endPos >= 0 Then Dim startPos As Double = metar.LastIndexOf(" ", endPos) If startPos >= 0 Then heading = metar.Substring(startPos + 1, 3) End If End If Return heading End Function Here a modified version of the getRunways function that takes in the wind direction and the ICAO... Thanks for those adds ;) call like this: (maybe Each ?) headingdeparture = FsuipcData.getWindDirectionFromMETAR(lblWXDep.Text) depart = getActiveRunway(lblDeparture.Text, headingdeparture) Me.lstDeparture.Items.Clear() Me.lstDeparture.Items.Add(depart.ToString()) headingarrival = FsuipcData.getWindDirectionFromMETAR(lblWXArr.Text) arrival = getActiveRunway(lblArrival.Text, headingarrival) Me.lstArrival.Items.Clear() Me.lstArrival.Items.Add(arrival.ToString()) I've added a new property to the DLL to get the FSUIPC Version number (new DLL attached). You need to be connected to FSUIPC first: FSUIPCConnection.FSUIPCVersion.ToString I don't know how you would get the version directly from the fsuipc.dll file on the disk. By file property and Php Script Public Function CheckVersion() Dim pathtosim As String = "" Dim fsxpath As String = "" Dim fs9path As String = "" If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft Games\Flight Simulator\10.0", "SetupPath", Nothing) IsNot Nothing Then fsxpath = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft Games\Flight Simulator\10.0", "SetupPath", Nothing).ToString Else If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\microsoft games\flight simulator\10.0", "SetupPath", Nothing) IsNot Nothing Then fsxpath = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\microsoft games\flight simulator\10.0", "SetupPath", Nothing).ToString Else If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Microsoft Games\Flight Simulator\10.0", "AppPath", Nothing) IsNot Nothing Then fsxpath = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Microsoft Games\Flight Simulator\10.0", "AppPath", Nothing).ToString End If End If End If If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft Games\Flight Simulator\9.1", "EXE Path", Nothing) IsNot Nothing Then fs9path = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft Games\Flight Simulator\9.1", "EXE Path", Nothing).ToString Else If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\microsoft games\flight simulator\9.0", "EXE Path", Nothing) IsNot Nothing Then fs9path = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\microsoft games\flight simulator\9.0", "EXE Path", Nothing).ToString Else If My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Microsoft Games\Flight Simulator\9.0", "EXE Path", Nothing) IsNot Nothing Then fs9path = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\Software\Microsoft\Microsoft Games\Flight Simulator\9.0", "EXE Path", Nothing).ToString End If End If End If If fsxpath IsNot "" And fs9path IsNot "" Then If MsgBox("FSX and FS9 detected. " & vbCrLf & "Is your primary simmulator FSX?", MsgBoxStyle.YesNo + vbQuestion, "Warning") = vbYes Then pathtosim = fsxpath Else pathtosim = fs9path End If If fsxpath IsNot "" And pathtosim = "" Then pathtosim = fsxpath If fs9path IsNot "" And pathtosim = "" Then pathtosim = fs9path If fsxpath = "" And fs9path = "" Then MsgBox("Can not find path to Flight simulator. " & vbCrLf & "Select path to FS instalation folder.") Dim fbd As New FolderBrowserDialog fbd.ShowDialog() pathtosim = fbd.SelectedPath & "\" fbd.Dispose() End If pathtosim = pathtosim.Trim Do While pathtosim.Contains("\.") pathtosim = pathtosim.Replace("\.", "\") Loop Dim fversion As String = FileVersionInfo.GetVersionInfo(pathtosim & "Modules\FSUIPC4.DLL").FileVersion Dim fversion2 As String = fversion.Substring(0, 5) Dim fversion3 As String = fversion2.Replace(".", "") Return fversion3 End Function Now I have a big problem losing FSUIPC connection > 2mn and I can't reconnect (close to finish)Regards,Fred
pellelil Posted June 10, 2015 Report Posted June 10, 2015 Fred I hope you don't mind, but if I can comment your form-dessign I would strongly recommend loosing the red background color in the input/entry-fields, as it makes it very hard to read the text (especially blue text on a red background is a "no no", and the green text on red is not much better).I see the red color is the same as in the logo ("SKYDream"), but it "hurts" the readabillity (if I had to use that program I think I in many cases would cut-and-past test into Notepad) Pelle
Frédéric-O DUCHEMIN Posted June 10, 2015 Author Report Posted June 10, 2015 Thank you for your remarks, but what do you recommend then? If you have time you can answer me via private message, not to lengthen this topic is already very long and almost not related to the main subject that is Paul's support. I also have technical questions about developing reading AIRAC then display them on a map like Google Maps Regards Fred
Frédéric-O DUCHEMIN Posted June 10, 2015 Author Report Posted June 10, 2015 Hey Paul, I have found the problem (lose FSUIPC connection) Dim msgcontrol As Offset(Of Short) = New FSUIPC.Offset(Of Short)("msg", &H32FA) Dim msg As Offset(Of String) = New FSUIPC.Offset(Of String)("msg", &H3380, 128) msg.Value = "SKYDreamTracker is Connected to SIM !!! Have a nice flight;)" msgcontrol.Value = 5 FSUIPCConnection.Process("msg") During my multiple try the message appear during a longtime not the 5s I would like...So Since yesterday no message appear but I lost FSUIPC connection. Regards, Fred
Paul Henty Posted June 10, 2015 Report Posted June 10, 2015 During my multiple try the message appear during a longtime not the 5s I would like...So Since yesterday no message appear but I lost FSUIPC connection. Problem 1 - Message not disappearing after 5 seconds This code is in a sub called 'mess()' which is called from drivestarttmr(). drivestarttmr() runs every 0.5 seconds, called from TmrGetDataFromFs_Tick(). So the problem is the message is being displayed every 0.5 seconds. Every time it is called the message timer gets reset. It will never reach 5 seconds. Solution: Move the mess() call from drivestarttmr() to a more suitable place so it's only called once after the connection is made. Problem 2 - Losing Connection This is because you are declaring offsets in the main sub: Dim msgcontrol As Offset(Of Short) = New FSUIPC.Offset(Of Short)("msg", &H32FA) '<---- Very bad Dim msg As Offset(Of String) = New FSUIPC.Offset(Of String)("msg", &H3380, 128) '<---- Very bad msg.Value = "SKYDreamTracker is Connected to SIM !!! Have a nice flight;)" msgcontrol.Value = 5 FSUIPCConnection.Process("msg") Each time this code runs (2 times a second) you create two new offsets in the 'msg' group. Eventually there are too many for FSUIPC to handle. Solution: You must move these two lines to the top of the class (FSUIPCData.vb) with all the other offset declarations. Paul
Frédéric-O DUCHEMIN Posted June 10, 2015 Author Report Posted June 10, 2015 Hey Paul,I am impressed very detailed analysis. I'll change that all this right away. Does there a way to change the color of the message and the length of the green bar?I have read the docs I found things of course but I do not have a huge level of development in Visual BasicRegards,Fred
Paul Henty Posted June 10, 2015 Report Posted June 10, 2015 Does there a way to change the color of the message and the length of the green bar? No. Users of FSUIPC can change the text to white using the tick box for 'non-scrolling FS msgs to be in white' on the 'miscellaneous' tab. But I don't believe the colour cannot be set via code. Paul
Frédéric-O DUCHEMIN Posted June 12, 2015 Author Report Posted June 12, 2015 Ok thanks for info Regards, Fred
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