Toppa80 Posted August 19, 2008 Report Posted August 19, 2008 Hi Folks, I have a problem with the connection to the FSUIPC. First I had a button. With a click on it, I started the connection to the FSUIPC, when the flusi was already running. Now I want to start my program first, in which I have a Timer, which tries to connect to FSUIPC. The flusi is not yet running. When I start the flusi now, it doesn´t find the FSUIPC. Do I start the program after flusi is running, it connects. What is the problem for that? Here is the Timer: Private Sub StbyTimerForFsuipc_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StbyTimerForFsuipc.Tick Try ' Attempt to open a connection to FSUIPC (running on any version of Flight Sim) FSUIPCConnection.Open() Me.ToolStripStatusLabel1.ForeColor = Color.Green Me.ToolStripStatusLabel1.Text = "Connected to Flight Simulator" Me.bxtConnectedToFlusi.Text = 1 Me.StbyTimerForFsuipc.Enabled = False Catch ex As Exception ' Badness occurred - show the error message Me.ToolStripStatusLabel1.ForeColor = Color.Red Me.ToolStripStatusLabel1.Text = "No Connection to Flight Simulator" End Try End Sub Thank you for help, Tobias
VulcanB2 Posted August 19, 2008 Report Posted August 19, 2008 Hi, My connect code reads something like this: Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click If f.FSUIPC_Open(FSUIPCInterop.Fsuipc.SIM_FS2K4, FSUIPC_ERR) Then txtStatus.Text = "Open!" Else txtStatus.Text = "STATUS: " & GetFSUIPCErr(FSUIPC_ERR) End If End Sub GetFSUIPCErr reads something like: Private Function GetFSUIPCErr(ByVal FSUIPC_ERR As Integer) As String Select Case FSUIPC_ERR Case FSUIPC_ERR_ATOM GetFSUIPCErr = "Failed to create Atom for mapping filename" Case FSUIPC_ERR_BUFOVERFLOW GetFSUIPCErr = "Buffer Overflow" Case FSUIPC_ERR_DATA GetFSUIPCErr = "IPC request contains bad data" Case FSUIPC_ERR_MAP GetFSUIPCErr = "Failed to create a file mapping object" Case FSUIPC_ERR_NODATA GetFSUIPCErr = "Call cannot execute: no requests accumulated" Case FSUIPC_ERR_NOFS GetFSUIPCErr = "Cannot link to FSUIPC or WideClient" Case FSUIPC_ERR_NOTOPEN GetFSUIPCErr = "Call cannot execute, link not Open" Case FSUIPC_ERR_OK GetFSUIPCErr = "OK!" Case FSUIPC_ERR_OPEN GetFSUIPCErr = "Attempt to Open when already Open" Case FSUIPC_ERR_REGMSG GetFSUIPCErr = "Failed to Register common message with Windows" Case FSUIPC_ERR_RUNNING GetFSUIPCErr = "Maybe running on WideClient, but FS not running on Server, or wrong FSUIPC" Case FSUIPC_ERR_SENDMSG GetFSUIPCErr = "IPC sendmessage failed all retries" Case FSUIPC_ERR_SIZE GetFSUIPCErr = "Size Error" Case FSUIPC_ERR_TIMEOUT GetFSUIPCErr = "IPC timed out all retries" Case FSUIPC_ERR_VERSION GetFSUIPCErr = "Incorrect version of FSUIPC, or not FSUIPC" Case FSUIPC_ERR_VIEW GetFSUIPCErr = "Failed to open a view to the file map" Case FSUIPC_ERR_WRONGFS GetFSUIPCErr = "Sim is not version requested" Case Else GetFSUIPCErr = "No Error" End Select End Function All the above code is because I found the Try...Catch didn't work. If you want to detect that FS is running then connect, you're going to need to set a flag somewhere that says the connection is open already, so it doesn't perpetually try opening an already opened connction. e.g. Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click If FSUIPC_CONN_OPEN Then Exit Sub If f.FSUIPC_Open(FSUIPCInterop.Fsuipc.SIM_FS2K4, FSUIPC_ERR) Then txtStatus.Text = "Open!" FSUIPC_CONN_OPEN = True Else txtStatus.Text = "STATUS: " & GetFSUIPCErr(FSUIPC_ERR) End If End Sub You could even get it so the code disables the connect timer when a connection is made, but you'd need a way to detect the connection failed, and either re-connect or generate an error saying why it can't reconnect. Best regards, Robin.
Toppa80 Posted August 19, 2008 Author Report Posted August 19, 2008 Thank you Robin for your help. I didn´t really used your code, but you brought me to an other idea. The problem was, that once the FSUIPCConnection.Open() was used, I have to close before next use... See the code: Private Sub StbyTimerForFsuipc_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StbyTimerForFsuipc.Tick If FSUIPC_CONN_OPEN Then Exit Sub Try FSUIPCConnection.Open() FSUIPC_CONN_OPEN = True Me.StbyTimerForFsuipc.Enabled = False Me.ToolStripStatusLabel1.ForeColor = Color.Green Me.ToolStripStatusLabel1.Text = "Connected to Flight Simulator" Me.bxtConnectedToFlusi.Text = 1 Catch ex As Exception Me.ToolStripStatusLabel1.ForeColor = Color.Orange Me.ToolStripStatusLabel1.Text = "Waiting for Flight Simulator" End Try If FSUIPC_CONN_OPEN Then Exit Sub FSUIPCConnection.Close() End Sub Greetings, Tobias
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