henre Posted May 5, 2004 Report Posted May 5, 2004 Hi , Can anyone give a litelle example for VB for reading an offset For Example a example code for reading offset 5806 and displaying it to a textbox named textbox1.. I am not new to VB but new to FSUIPC programming so i dont know how to read an offset and dsiplay it in VB. And i couldnt see it in SDK example for VB Can you give a litte example code for it pls
Pete Dowson Posted May 5, 2004 Report Posted May 5, 2004 I am not new to VB but new to FSUIPC programming so i dont know how to read an offset and dsiplay it in VB. And i couldnt see it in SDK example for VB The SDK contains examples of VB usage is the ZIP called "UIPC_SDK_VisualBasic.zip". There are also extras for the VB.NET programmers in another ZIP, also in the SDK. I am not familiar with VB at all, but looking at the files in the VB ZIP it certainly looks as if you should have enough there. The main example source file appears to be "General.bas". I'm not sure what all the other files are for, but I'm sure that as an experienced VB programmer already you should recognise them. Regards, Pete
henre Posted May 5, 2004 Author Report Posted May 5, 2004 Ok but in uipc vb example i couldnt see any example for reading an offset. Ok Pete thanks for your reply anyway .. If a vb programmer can write here a very little example of reading the offset and displaying it to a label i would be very glad..
Chris Brett Posted May 5, 2004 Report Posted May 5, 2004 The VB example code in the SDK contains a good example of how to read data from FS. The Timer1_Timer() procedure shows how to obtain the FS time (hours mins and secs) and display them. You don't even need to do anything, just run the code. However, if you'd like an even simpler example, try this. I added a Command button onto the form of the UIPCHello demo program (mine was called Command6 but yours many be different, so modify as necessary): Private Sub Command6_Click() Dim i_APactive As Integer Dim dwResult As Long Call FSUIPC_Read(&H7BC, 4, VarPtr(i_APactive), dwResult) Call FSUIPC_Process(dwResult) Command6.Caption = "AP is " & i_APactive End Sub This reads the state of the FS autopilot master switch when you press the button, and shows "AP is 1" if it's on, or "AP is 0" if it's off. And here is the explanation: Dim i_APactive As Integer This declares the variable that will hold the value of the offset we'd like to read. Here, we declare "i_APactive" as an integer type. We do this because if we look in the FSUIPC SDK doc, we find the entry for autopilot master switch and it says it's at offset 07BC (which is &H7BC in VB parlance), and that in order to get the proper meaning of AP master, we must read 4 bytes beginning at this offset. That is what the doc says. So, we use VB help to find a list of all data types supported and look for one that is likely to hold a sensible value for what we are trying to read. An Integer type is 4 bytes itself, so that fits the bill, and the only likely values to come from FS at this location are 0 or 1 (nothing too complicated). So an Integer type will be more than adequate for us. Dim dwResult As Long This is just another declaration of the result variable for the IPC function calls. We don't bother checking it here in this example; we assume it always reads correctly, for simplicity. But nevertheless, a declaration must be made for it, so here it is. Call FSUIPC_Read(&H7BC, 4, VarPtr(i_APactive), dwResult) This initiates the process to put our request into the buffer which FSUIPC will action when we (later) ask it to do so. Here, we say we'd like to read from offset 07BC, for a total of 4 bytes-worth of data (ie. we are reading 07BC, 07BD, 07BE and 07BF from FS), and that we'd like FSUIPC to store that result into our previously declared variable called i_APactive. The dwResult part simply holds the result of the call, and we shall ignore this for this example. This FSUIPC_Read action does nothing other than to queue this particular read request. We have not communicated with FSUIPC yet, but merely added our request to the buffer. We could add more Read requests here if we wanted to. But now, we must ask FSUIPC to action the requests in the buffer, and we do this by... Call FSUIPC_Process(dwResult) This is the meat of the FSUIPC communication. All it does is ask FSUIPC to action the queued Read (and Write) events that are sat in the buffer as a result of our previous calls to FSUIPC_Read() and FSUIPC_Write. The dwResult again holds the success/fail status of the call, and we will assume for this example it all went well (ie. we will disregard the dwResult), so don't worry about it. Command6.Caption = "AP is " & i_APactive This final line merely outputs the value of i_APactive to the command button caption. It will show 1 for the AP master switch being on, and 0 for it being off. The previous FSUIPC_Process call actioned our earlier request to put the 4 bytes of FS memory from location 07BC into our 4-byte long variable i_APactive. If it worked, then i_APactive will now be made up of those same 4 bytes, and if you've chosen the correct data type, then reading out those bytes by referencing the variable itself will reveal the result. If you've chosen the wrong variable type to use, you may get garbage. We could have done this another way. We could have declared i_APactive as a byte, and read just 1 byte from 07BC (ie. 07BC itself) as the return value is only ever 1 or 0. But for compliance with the FSUIPC SDK docs, we've done it properly and used the full 4 bytes. I hope this helps you. You should also take a look at the time reading example already in the code - this is just an extension of what has been described here. And the principles for writing values to FS are the same (except strings, which are a bit of a pain in VB). -- Chris Brett c.brett@flightdecktechnology.com
henre Posted May 5, 2004 Author Report Posted May 5, 2004 Now i started fs then run the fsuipc demo with the new codes and in startup i get en error "One of more programs you are using is not accredited for access to an unregistered copy of fsuipc. Please see fsuipc.log for detaisl" (for information i had registered fsuipc for squawkbox ) what is the soluotion ?
Chris Brett Posted May 5, 2004 Report Posted May 5, 2004 The solution is to read this: http://forums.simflight.com/viewtopic.php?t=8906 and take particular note of point 5 listed under "What you get if you pay". Essentially, unless you have registered (ie. paid) to license your copy of FSUIPC, then only "allowed" programs ("accredited" in Pete parlance) will be able to use FSUIPC to get/set data, like you are trying to do. Without registering & paying for your copy of FSUIPC, you can't do what you want to do. Unless you apply to Pete for a freeware access / developer's key, assuming you are going to develop freeware that is. Those are the options. Squawkbox works after you entered the Squawkbox code in FSUIPC because that is a freeware application and supported by Pete with a program access code that allows Squawkbox, and only Squawkbox, to access FSUIPC devlopers functions with that code. Hope this helps. Chris
henre Posted May 5, 2004 Author Report Posted May 5, 2004 So that everybody that uses my program has to register with fsuipc with paying ?
Jamie Fox Posted May 5, 2004 Report Posted May 5, 2004 You have two options: 1. Anyone else using your program will need a registered copy of FSUIPC. 2. You can apply for an access key for your application, so that your end users won't need to pay. This is free if your application is distributed free of charge. If your application is distributed at cost then you will have to reach a mutually acceptable agreement with Peter.
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