Toppa80 Posted August 18, 2008 Report Posted August 18, 2008 Hi, does anybody know, how I can change the time in the flight simulator via FSUIPC like FsRealTime does it? I´m writing a software, which logs the flight in FS. The user should fly in real time for that. Greetings, Tobias
Pete Dowson Posted August 18, 2008 Report Posted August 18, 2008 does anybody know, how I can change the time in the flight simulator via FSUIPC like FsRealTime does it? It writes to the offsets in FSUIPC which control the time -- see offsets 0238 to 023C. Pete
Toppa80 Posted August 19, 2008 Author Report Posted August 19, 2008 Pete, thanks for your answer. I tried it now that way, but it doesn`t work Dim new_H As String = "22" fs_H.Value = System.Text.Encoding.Default.GetBytes(new_H) I work with Visual Basic 2008. Thanks for your help, Tobias
Toppa80 Posted August 19, 2008 Author Report Posted August 19, 2008 I solved the problem now. The String must be converted into CHAR.... Dim new_H As Char = "22" fs_H.Value = System.Text.Encoding.Default.GetBytes(new_H) This works now :) Thanks
Pete Dowson Posted August 19, 2008 Report Posted August 19, 2008 I solved the problem now. The String must be converted into CHAR.... No idea why you'd be using strings or characters for a numerical value. Surely VB2008 supports numbers, like integers and things? Just because some of the destinations are only one byte (8-bits) long doesn't mean your source data cannot be longer -- it is the LENGTH in the FSUIPC write which determines how many bytes get copied over. Regards Pete
Toppa80 Posted August 19, 2008 Author Report Posted August 19, 2008 Pete, you are right. I thought I have it. I was wrong. It still doesn´t work. This is the for example the Zulu-Hour I want to write into the Flusi: Dim fs_H As Offset(Of Byte()) = New FSUIPC.Offset(Of Byte())(&H23B, 1) Thats the way I get the time: Dim new_H As Integer = Date.UtcNow.Hour.ToString I´ve read, that I can get the data into the FSUIPC like that: fs_H.Value = ????? FSUIPCConnection.Process() The .Value must be a byte, right? But how to code it? I can´t find any help in the web :( Thank you, Tobias
Pete Dowson Posted August 20, 2008 Report Posted August 20, 2008 The .Value must be a byte, right? But how to code it? Sorry, I've no idea what all that code is. Doesn't look like anything I've seen before. where are the FSUIPC reads and writes? Maybe VB2008 is completely different to previous versions? Either way, the thing to realise that all "byte" means is a collection of 8 bits, the smallest addressable lump of memory in Intel systems. Bytes are used for ASCII characters, yes, and strung together to make strings (but then there are Unicode characters which are sometimes 16-bits long (words), and there are wide characters too!). But forget all that here. The time values are NUMBERS. You can, in any language, use NUMBERs. So store them as numbers. The only time you have to squeeze the numbers into a byte (or a word, 16-bits, where specified) is when the FSUIPC write function is called -- and that is done using the LENGTH parameter -- you don't need to change the number or convert it. A length of 1 writes one byte, no matter how long the data, and so on. I can´t find any help in the web :( I'm sure there must be plenty of help about on programming in VB. For FSUIPC there's the sample, kindly provided by other users, in the FSUIPC SDK. But maybe that's for a different VB and isn't applicable? It seems it is changing too fast. I'm afraid I'm lost with all these different VBs. I didn't even know the first one very well, just brief encounters like this. Regards Pete
Toppa80 Posted August 20, 2008 Author Report Posted August 20, 2008 Pete, thank you very much, that you bear so much with me. I will try to find more infos to solve the problem. I will write it down here when so happened. Have a nice day. Tobias
Graham Pollitt Posted August 20, 2008 Report Posted August 20, 2008 Using Paul Hentys VB.net DLL I have used the following code to write a small app called FSTimeStay for someone on a forum. It remembers the time within FS that the button is clicked and once a minute it writes that time back to FS. I am sure you can find some help within this code for what you are doing Imports FSUIPC Public Class Form1 Public hr, min, sec, hroffset As Short Public FSHour As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H238) Public FSMin As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H239) Public FSSec As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H23A) Public FSOffset As Offset(Of Short) = New FSUIPC.Offset(Of Short)("fstime", &H246) Private Sub OpenFSUIPC() Try ' Attempt to open a connection to FSUIPC (running ON any version of Flight Sim) FSUIPCConnection.Open() Catch ex As Exception ' Badness occurred - show the error message MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Public Sub WriteTime() 'write the time back to fs FSHour.Value = Me.hr '+ Me.hroffset FSMin.Value = Me.min FSSec.Value = Me.sec FSUIPCConnection.Process("fstime") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Static Run As Boolean = False Static firstrun As Boolean = False If Run = False Then If firstrun = False Then Me.OpenFSUIPC() firstrun = True End If 'read current time FSUIPCConnection.Process("fstime") Me.hr = Me.FSHour.Value Me.min = Me.FSMin.Value Me.sec = Me.FSSec.Value Me.hroffset = Me.FSOffset.Value / 60 lblTime.Text = "Locked time : " & Me.hr & ":" & Me.min & ":" & Me.sec & " GMT Offset:" & Me.hroffset 'start timer Me.Timer1.Enabled = True Me.Button1.Text = "Stop" Run = True Else Run = False Me.Timer1.Enabled = False Me.Button1.Text = "Activate" lblTime.Text = "Not running" End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick 'rewrite the time into FS dependant upon timer interval Me.WriteTime() End Sub End Class
Toppa80 Posted August 21, 2008 Author Report Posted August 21, 2008 Hey, vielen Dank für deinen Quellcode. Die Zeit und auch der Tag wird jetzt perfekt übernommen :) Nur mit dem Jahr passt noch etwas nicht... Da meldet er immer "OverFlowException wurde nicht behandelt". -> Die arithmetische Operation hat einen Überlauf verursacht. Woran kann das nun noch liegen? Public Class Form1 Public FSHour As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H23B) Public FSMin As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H23C) Public FSSec As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H23A) Public FSDoY As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H23E) Public FSYear As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H240) Private Sub btnStartFsTimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartFsTimer.Click FSHour.Value = Date.UtcNow.Hour FSMin.Value = Date.UtcNow.Minute FSSec.Value = Date.UtcNow.Second FSDoY.Value = Date.UtcNow.DayOfYear FSYear.Value = Date.UtcNow.Year FSUIPCConnection.Process("fstime") End Sub End Class Der Wert Date.UtcNow.Year liefert 2008, wird aber nicht in die Variable FSYear.Value übernommen :( Liebe Grüße, Tobi
Graham Pollitt Posted August 21, 2008 Report Posted August 21, 2008 You are defining Public FSYear As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H240) when it should be Public FSYear As Offset(Of UShort) = New FSUIPC.Offset(Of UShort)("fstime", &H240) You get the overflow error as you are loading a 16bit number into an 8bit variable Hope this helps!
Toppa80 Posted August 21, 2008 Author Report Posted August 21, 2008 Oh shit, I´m sorry!!!!! ;) Thank you very much for your code! The Time and the Day of the year works perfectly now :) Only the year doesn´t work :( "OverFlowException was not treated". -> The arithmetic operation caused an overflow. What can that be now? Public Class Form1 Public FSHour As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H23B) Public FSMin As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H23C) Public FSSec As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H23A) Public FSDoY As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H23E) Public FSYear As Offset(Of Byte) = New FSUIPC.Offset(Of Byte)("fstime", &H240) Private Sub btnStartFsTimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartFsTimer.Click FSHour.Value = Date.UtcNow.Hour FSMin.Value = Date.UtcNow.Minute FSSec.Value = Date.UtcNow.Second FSDoY.Value = Date.UtcNow.DayOfYear FSYear.Value = Date.UtcNow.Year FSUIPCConnection.Process("fstime") End Sub End Class The value Date.UtcNow.Year affords 2008, but doesn´t get taken over by FSYear.Value :( I hope, it´s better now ;) Regards, Tobi
Graham Pollitt Posted August 21, 2008 Report Posted August 21, 2008 Sorry, I edited my post as soon as I had sent it. Didnt think anyone would have read it that quickly so my answer is posted above! :D
Toppa80 Posted August 21, 2008 Author Report Posted August 21, 2008 Hey gjpollitt, sorry, I don´t know your real name. Thank you very much for your halp. I`m pretty new in VB. But now it works! The complete time is sent to the simulator. Have a nice weekend, Tobias
Graham Pollitt Posted August 22, 2008 Report Posted August 22, 2008 Sorry my name is Graham. Glad you've got it working, best regards
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